You are not logged in.

#1 2013-09-11 00:21:17

klaus
Member
From: Brazil
Registered: 2013-03-09
Posts: 42

[SOLVED] Partition alignment

I might have misunderstood fdisk and attempted to align my partitions to I/O optimal size because fdisk was complaining about impacts to the disk's performance. It still complained after I partitioned everything the way I thought it was supposed to be, so I must've been wrong.

Partitions all start in a multiple of 4096 (that's what I meant by I/O optimal size), and heres the output of fdisk /dev/sda and a subsequent p (listing partitions).

What have I done wrong and/or how can I fix it?

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0004b3e0

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            4096   104857599    52426752    7  HPFS/NTFS/exFAT
/dev/sda2   *   104857600   167766015    31454208   83  Linux
/dev/sda3       167768064   970481663   401356800    7  HPFS/NTFS/exFAT
/dev/sda4       970481664   976773167     3145752   82  Linux swap / Solaris

Command (m for help): 

Thanks!

Last edited by klaus (2013-09-13 09:50:02)

Offline

#2 2013-09-11 02:34:23

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,135

Re: [SOLVED] Partition alignment

I'm not sure what the problem is meant to be. fdisk is telling you something about the disk and recommending partitioning in a certain way as a result. It isn't saying your partitions are not aligned as far as I can tell. Why do you think it is?

I am not sure whether fdisk can do this but the manual page for cfdisk suggests it can check alignment for you.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2013-09-11 03:07:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Partition alignment

If you just stick to whole MBs for your partition sizes, everything will be aligned properly if your first partition starts at the default 2048 (or your 4096).  It might have been giving you warnings simply because you are not starting the first partition at the recommended value of 2048.  But it has been quite some time since I have used fdisk, so I am not sure what kinds of things it may or may not check for.

Offline

#4 2013-09-11 05:50:13

klaus
Member
From: Brazil
Registered: 2013-03-09
Posts: 42

Re: [SOLVED] Partition alignment

Thanks (again) for the replies.

WonderWoofy,
So, if I align the first partition at 4096 (which fdisk says is both the optimal I/O size and physical sector size), can I align every other partition to 1024? fdisk tells me to align to my drive's physical sector size or optimal I/O size, both being 4096, and it checks for the first partition starting at 2048? That doesn't really make sense.

cfr,
Yeah, I know it's just a warning, but since the machine in question is a netbook, I can't talk read a warning about performance loss without worrying about it, even if I don't really know how much of a hit would that be. Anyway, in the wiki there's a recommendation against using cfdisk because of alignment issue, and I thought it was a good time to learn about fdisk (I used to go always with the easier way, not the Arch way -- gparted).

Just wanna make sure I'm not suffering any performance loss, while also learning a little bit more.

Offline

#5 2013-09-11 15:07:22

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Partition alignment

klaus wrote:

fdisk tells me to align to my drive's physical sector size or optimal I/O size, both being 4096, and it checks for the first partition starting at 2048? That doesn't really make sense.

If you disk is an Advanced Format rotational drive, the block size is 4KB(many solid state drives are as well).  You are insisting that the first partition start at sector 4096.  But you are totally disregarding the sector size.  fdisk will tell you, and your disk likely reports 512B (byte) sectors.  So starting your first partition at 4096 is actually starting the first partition 2097152 bytes into the disk (or 2048KB).  So starting at sector 2048 (or 1024KB) makes perfect sense actually.

This is really not as hard has you're making it.  Since we can assume that there are quite a number of users out there who have disks that need proper alignment since disks no longer use the CHS, and instead use LBA.  That being the case, for a bit now, the tools that we have in Linux to partition our drives tend to try to properly align things for you.  It seems as though you are going at this with the assumption that you are going to have to force your way into compliance.

Just start fdisk on your desired disk.  Make a new first partition, and fdisk will default the first sector to 2048, which is aligned, neat!  Then it will ask where you want it to end the partition.  Do now specify this in sectors as if you do, it will take exactly what you tell it as the end point, whether it is aligned or not.  So instead use MBs to tell it where the end.  fdisk even tells you how to note the end point in this way when it is asking you, but for example if you wanted to make it 512MB, you would use +512M.  If you wanted to make it 3GB, you would use +3G.  Simple, and fdisk will properly align your partitions for you.

There is also a reason why 2048 is selected as well, and that is because it is the first LBA that results in proper alignment for every kind of partitioning you can think of (regular, LVM, mdadm, etc.).  See the link below for more info.

http://www.ibm.com/developerworks/linux … tor-disks/

Offline

#6 2013-09-11 18:04:19

srs5694
Member
From: Woonsocket, RI
Registered: 2012-11-06
Posts: 719
Website

Re: [SOLVED] Partition alignment

klaus wrote:

I might have misunderstood fdisk and attempted to align my partitions to I/O optimal size because fdisk was complaining about impacts to the disk's performance.

It's not really complaining; it's just warning you of a potential problem, should you decide to create new partitions that are not properly aligned.

Partitions all start in a multiple of 4096 (that's what I meant by I/O optimal size), and heres the output of fdisk /dev/sda and a subsequent p (listing partitions).
...

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
...
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            4096   104857599    52426752    7  HPFS/NTFS/exFAT
/dev/sda2   *   104857600   167766015    31454208   83  Linux
/dev/sda3       167768064   970481663   401356800    7  HPFS/NTFS/exFAT
/dev/sda4       970481664   976773167     3145752   82  Linux swap / Solaris

It's important that you distinguish between sector size values and partition start point values. They're similar numbers in your case, but they're different things. Sector size values represent the amount of data stored within each sector on the hard disk. Partition start (and end) points are measured in sector values. An analogy might be this: There are 1,000 meters in a kilometer -- that's analogous with the statement that a sector contains 512 (or 4096) bytes. A road begins in City A and extends to City E, passing Cities B, C, and D in the process. City B is at kilometer 212 and city C begins at kilometer 283, so the stretch of highway between Cities B and C is from kilometers 212 to 283. That's analogous to saying that your /dev/sda2 begins at sector 104857600 and extends to sector 167766015.

This analogy breaks down when it comes to physical vs. logical sector sizes. For optimum performance, though, partitions must begin on the boundaries of physical sectors; but with modern disks, the logical sectors used in partition tables are smaller than the physical sectors. Thus, partitions should begin on logical sectors that correspond to the start of physical sectors. In your case, you have 4096-byte physical sectors and 512-byte logical sectors, so your partitions should begin on 8-sector multiples (4096/512 = 8). This is a common case for Advanced Format hard disks.

The convention these days is to begin all partitions on multiples of 2048 sectors (that is, on 1MiB boundaries). 2048 is a multiple of 8, so it works well for Advanced Format disks. It also works well with most RAID configurations and SSDs, which have their own needs that typically require alignment on larger sector values. As a practical matter, you could begin your first partition at sector 8, or 40, or 128, or 512, or any other multiple of 8 and get good performance. IIRC, fdisk won't let you use a start value lower than 2048 by default, but that's a conservative fdisk limitation. (That said, there is another reason to start the first partition at 2048: GRUB needs a certain amount of space, so starting the first partition too early won't leave enough room for GRUB. GRUB's space requirements vary depending on its configuration.)

All told, then, beginning your partitions on multiples of 4096 sectors, as you have done, is fine, although it wastes an extra 1MiB of space at the very start of the disk compared to starting the first partition at the default value of 2048. The message you've quoted from fdisk is just telling you to stick to that sort of partitioning; it's not an error message warning you of an existing problem. (That message should probably be re-written to be a bit clearer.) The fact that you're beginning your partitions on multiple of 4096 sectors has nothing to do with the fact that your disk's physical sector size is 4096 bytes. This would be analogous to the situation of a city that lies at kilometer 1,000 on that highway -- that value is only coincidentally related to the fact that there are 1,000 meters in a kilometer.

Offline

#7 2013-09-13 09:49:31

klaus
Member
From: Brazil
Registered: 2013-03-09
Posts: 42

Re: [SOLVED] Partition alignment

Thanks srs5694 and WonderWoofy both for the thorough and well-written explanations, now I have a bigger grasp on the subject!
I now understand that my interpretation of fdisk's warning was incorrect, it wasn't pointing out that my partitioning was wrong. Even though I was actually wasting space, by aligning my partitions to multiples of 4096 I was indirectly aligning them to multiples of 8.

Anyway, marking thread as solved.

Offline

Board footer

Powered by FluxBB