37

I just installed ubuntu on my new intel SSD. Now I am not sure, whether paritions are properly aligned in respect to my specific SSD.

Here's my fdisk output.

$ fdisk -l

    Platte /dev/sda: 120.0 GByte, 120034123776 Byte
255 Köpfe, 63 Sektoren/Spur, 14593 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a6294

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sda1   *           1        1913    15360000   83  Linux
/dev/sda2            1913       14058    97558528   83  Linux
/dev/sda3           14058       14594     4300800   82  Linux Swap / Solaris

Also, do I still need to align my SSD at all, since I am using TRIM on the ext4 partitions by mounting them with the discard flag.

If it is the case, that my partitions are not properly aligned, what could I do to fix this without having to reinstall everything?

4
  • What do you mean by "properly aligned"?
    – Flimzy
    Commented Jun 25, 2011 at 8:03
  • 4
    As much as I know, SSDs need to be aligned to provide maximum io. Here's an article on the topic. I am still not sure, how I set up alignment for my specific SSD.
    – jottr
    Commented Jun 25, 2011 at 10:15
  • 4
    Nope, none of those partitions are aligned. It's suggested (citation needed, but GParted does it that way and so does Windows 7) that the start blocks of your partitions (Anfang) are at a sector evenly dividable by 2048 (= 2048 sectors à 512 byte = 1 MiB). – htorqu
    – htorque
    Commented Sep 15, 2011 at 9:26
  • @htorque AFAICT from an article about this, it depends on the segment size, which could be 8 MB or even larger. With a modern disk it would probably be easiest to align it to e.g. 32 MB, to fit with most common segment sizes.
    – l0b0
    Commented Jan 11, 2013 at 15:47

3 Answers 3

59

Parted has an align-check build in.

parted /dev/sda
align-check opt n

n is the partition you want to check.

1
  • 2
    The optimal alignment uses information reported by disk. That's not always aligned to the physical block size as sometimes the hardware lies about its block size. Sometimes hard disks have 4k blocks internally, but report 512b blocks. Additional check would be to see if start divides to 4096 (and end+1 also)
    – NickSoft
    Commented May 30, 2017 at 7:14
11

Ensuring SSD alignment with parted tool looks like a pretty good guide for aligning your filesystem on the SSD:

  1. Get the block size of your SSD in bytes (there are heaps of tips, and I don't know which ones will work for which hardware).
  2. Start the partition editor:

    sudo parted
    
  3. Show the partition table:

    p
    
  4. Verify that the numbers in the Start and Size columns are divisible by the block size.
1
  • Does size need to be divisible ?
    – nehz
    Commented Aug 10, 2020 at 6:47
6

To be sure you have to use both built-in parted align-check option:

HDD:

DEVICE=/dev/sda && for i in `sudo parted $DEVICE print | grep -oE "^[[:blank:]]*[0-9]+"`; do   sudo parted $DEVICE align-check opt "$i"; done

SSD:

DEVICE=/dev/nvme0n1 && for i in `sudo parted $DEVICE print | grep -oE "^[[:blank:]]*[0-9]+"`; do   sudo parted $DEVICE align-check opt "$i"; done

and manual check (calculate divisibility by 4096B)

I've written a bash script to perform both checks:

https://github.com/crysman/check-partitions-alignment

(works on any GNU/Linux OS)

Or you can check manually using this table:

https://docs.google.com/spreadsheets/d/1dnDlhglxxgApvtUv0-nxn1iFYTqkjRELqCOWJtp3hbs/edit#gid=0

And yes, SSD HDD's partitions need to be aligned properly for maximum performance.

1
  • @crysmon The -l options prints of gparted ignores the /dev/sda given and also prints partition numbers for /dev/sdb, /dev/sdc, etc and also LVM logical volumes. Can you please replace sudo parted /dev/sda -l by sudo parted /dev/sda print in your command ?
    – SebMa
    Commented Aug 1, 2020 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .