Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 320655 - <sys-apps/util-linux-2.17 - fdisk includes an extra sector when specifying a specific partition size
Summary: <sys-apps/util-linux-2.17 - fdisk includes an extra sector when specifying a ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-19 23:19 UTC by Richard
Modified: 2010-06-04 16:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard 2010-05-19 23:19:18 UTC
Whenever you specify a beginning sector, and then ask fdisk to make a partition starting at the sector of size x bytes/kbytes/mbytes/gbytes/tbytes, it will make a partition of x bytes plus 1 sector, which messes things up when you try to align partitions to 4KB boundaries on a SSD. It also affects the new advanced format drives from Western Digital and other manufacturers that have 4KB sectors.

Reproducible: Always

Steps to Reproduce:
1. Run fdisk
2. Press u to change to sectors
3. Make a new partition starting at sector 128 with size 32M (to follow the gentoo handbook).
4. Try to make a new partition starting at sector 65644, which should be right after the partition you just made.
5. Watch it fail and force you to use sector 65645.
6. Use that sector, make a swap partition and repeat this procedure to make a root partition according to the gentoo handbook.
Actual Results:  
Now your boot partition is properly aligned, your swap partition is off by 1 sector and your root partition is off by 2 sectors.

Expected Results:  
It should have omitted the last sector from the partition because that makes the partition bigger than you told it to make it by 1 sector. This is a consequence of the array size formula, where size = final - initial + 1.

This kills I/O performance on both SSDs and Advanced Format Drives. For details as to why this is bad, there are some good resources that can be found via Google:

http://www.google.com/search?hl=en&q=ssd+partition+alignment

Microsoft has a powerpoint presentation that graphically shows the issues involved with having improperly aligned partitions and describes proper alignment as being something that they did in Windows 7 to improve system performance:

http://download.microsoft.com/download/5/E/6/5E66B27B-988B-4F50-AF3A-C2FF1E62180F/COR-T558_WH08.pptx
Comment 1 Wormo (RETIRED) gentoo-dev 2010-05-27 07:00:40 UTC
I believe fdisk expert mode is what you want:
http://lwn.net/Articles/377956/

Agreed that this is not exactly a user-friendly solution, but I've heard upstream partitioning tools are improving with respect to support for SSD alignment... so upcoming versions will hopefully be more convenient.
Comment 2 Richard 2010-05-27 13:49:11 UTC
(In reply to comment #1)
> I believe fdisk expert mode is what you want:
> http://lwn.net/Articles/377956/
> 
> Agreed that this is not exactly a user-friendly solution, but I've heard
> upstream partitioning tools are improving with respect to support for SSD
> alignment... so upcoming versions will hopefully be more convenient.
> 

I manually calculate the sector numbers for the partitions and enter them in place of partition sizes as a workaround.
Comment 3 Jeroen Roovers (RETIRED) gentoo-dev 2010-05-31 21:16:34 UTC
Looks like it's fixed in 2.17. Quoting from util-linux-ng-2.17.2/docs/v2.17-ReleaseNotes:

fdisk:
   - the fdisk command aligns newly created partitions to minimum_io_size
     boundary ("minimum_io_size" is physical sector size or stripe chunk
     size on RAIDs).

but I will leave it to others to either deny or confirm this. You could try yourself, of course.
Comment 4 Richard 2010-05-31 22:28:26 UTC
(In reply to comment #3)
> Looks like it's fixed in 2.17. Quoting from
> util-linux-ng-2.17.2/docs/v2.17-ReleaseNotes:
> 
> fdisk:
>    - the fdisk command aligns newly created partitions to minimum_io_size
>      boundary ("minimum_io_size" is physical sector size or stripe chunk
>      size on RAIDs).
> 
> but I will leave it to others to either deny or confirm this. You could try
> yourself, of course.
> 

I looked around in fdisk and noticed something about a "dos compatibility" mode. Toggling it off makes fdisk a Windows 7-style partitioning utility. Unfortunately, that means that the first partition must start no earlier than sector 2048. There is no technical reason to start the first partition at sector 2048 instead of sector 1024, and ideally it should be sector 1024, but under the Windows 7-style partitioning mode, this is impossible.

Using the default dos compatibility mode allows you do it, but it still has the nonsensical behavior I reported in the first place, which at this point, appears to be a legacy implementation from MS-DOS, even though doing it that way would have been the wrong way to do things back then. I suppose that something being nonsensical would never stop Microsoft from implementing math errors in its programs.

Anyway, the original issue where partitions were being extended a sector is no longer present when the dos compatibility mode is toggled off. The fact that this behavior was changed by matching the behavior of Windows 7 is an issue in itself because strictly speaking, Windows 7 does not partition the disks properly by starting the first partition at sector 2048 instead of sector 1024.  That is not as egregious an issue as having the partitions misaligned, but it is not strictly correct because it wastes space. The amount of wasted space (512KB) is not significant enough to warrant keeping this bug open, so I will mark it fixed, although I might file a bug with upstream about this in the near future.
Comment 5 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-04 08:40:47 UTC
(In reply to comment #4)
>  That is not as egregious an issue as having the partitions misaligned, but it
> is not strictly correct because it wastes space. The amount of wasted space
> (512KB) is not significant enough to warrant keeping this bug open, so I will
> mark it fixed, although I might file a bug with upstream about this in the near
> future.
Richard if you do file that, please ask upstream to make the alignment configurable.

Windows7 is using 1MiB alignment as that's the largest erase block size known on SSDs. However most SSDs are on 128/256/512KiB.

Comment 6 Richard 2010-06-04 16:25:22 UTC
As far as I know, no SSDs are using 1MB erase blocks at this time. Do you know of any particular models that contradict this?