fdisk and 2048 sectors obsession.
Hi!
I was learning about GPT when I noticed this behavior of fdisk which I never though about before.
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors.
Why this behavior?
dE composed on 2014-10-28 00:13 (UTC+0530):
Quoted 11 lines
I was learning about GPT when I noticed this behavior of fdisk which I never though about before.
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors.
Why this behavior?
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives-master-ti/
may provide some insight WRT performance issues ensuing from other start sector selections.
Signature · 6 lines
"The wise are known for their understanding, and pleasant words are persuasive." Proverbs 16:21 (New Living Translation) Team OS/2 ** Reg. Linux User #211409 ** a11y rocks! Felix Miata *** http://fm.no-ip.com/
Quoted 10 lines · Felix Miata
dE composed on 2014-10-28 00:13 (UTC+0530):
Quoted 8 lines
I was learning about GPT when I noticed this behavior of fdisk which I never though about before.
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors. Why this behavior?
Quoted 3 lines
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives-master-ti/
may provide some insight WRT performance issues ensuing from other start sector selections.
But that works even with multiples of 8. So we can start from sector 8 in MBR and 40 in GPT.
Also I'm pretty sure fdisk uses 2048 even with -b 4096, but unfortunately I get --
*** Error in `fdisk': malloc(): memory corruption: 0x0000000002507330 ***
with that switch.
dE composed on 2014-10-28 08:54 (UTC+0530):
Quoted 8 lines
Quoted 3 lines · Felix Miata
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives-master-ti/
may provide some insight WRT performance issues ensuing from other start sector selections.But that works even with multiples of 8. So we can start from sector 8 in MBR and 40 in GPT.
OK, as long as you know you'll never need a bootloader or other boot-time software that requires the "wasted" space between MBR and first partition sector. It seems M$ for Vista picked 2048 to reserve plenty of space for such a *possibility* (not necessarily expectation), so for compat reasons and other[1], other tools, including fdisk, decided to do the same at least by default.
I've created partitions starting at sector 0x400 on 4k disks with no problems observed.
Quoted 6 lines
Also I'm pretty sure fdisk uses 2048 even with -b 4096, but unfortunately I get --
*** Error in `fdisk':
malloc(): memory corruption:0x0000000002507330***with that switch.
Bug somewhere?
[1]
http://www.anchor.com.au/blog/2012/10/the-difference-between-booting-mbr-and-gpt-with-grub/
Signature · 6 lines
"The wise are known for their understanding, and pleasant words are persuasive." Proverbs 16:21 (New Living Translation) Team OS/2 ** Reg. Linux User #211409 ** a11y rocks! Felix Miata *** http://fm.no-ip.com/
Quoted 18 lines · Felix Miata
dE composed on 2014-10-28 08:54 (UTC+0530):
Quoted 6 lines
Quoted 3 lines · Felix Miata
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives-master-ti/
may provide some insight WRT performance issues ensuing from other start sector selections.But that works even with multiples of 8. So we can start from sector 8 in MBR and 40 in GPT.
OK, as long as you know you'll never need a bootloader or other boot-time software that requires the "wasted" space between MBR and first partition sector. It seems M$ for Vista picked 2048 to reserve plenty of space for such a *possibility* (not necessarily expectation), so for compat reasons and other[1], other tools, including fdisk, decided to do the same at least by default.
I've created partitions starting at sector
0x400on 4k disks with no problems observed.
Quoted 8 lines
Quoted 4 lines
Also I'm pretty sure fdisk uses 2048 even with -b 4096, but unfortunately I get --
*** Error in `fdisk':malloc(): memory corruption:0x0000000002507330***
with that switch.Bug somewhere?
[1]
http://www.anchor.com.au/blog/2012/10/the-difference-between-booting-mbr-and-gpt-with-grub/
Yeah, I'll file that bug.
But I also think this fdisk 2048 behavior should be removed now or at least provide a switch for the same and document this in the man page.
dE composed on 2014-10-28 10:00 (UTC+0530):
Quoted 2 lines
But I also think this fdisk 2048 behavior should be removed now or at least provide a switch for the same and document this in the man page.
There is a switch:
-c , --compatibility[=mode]
The man page does fail to explain what dos mode actually means. Google can take up that slack for those interested, while the man page ought to be better.
Signature · 6 lines
"The wise are known for their understanding, and pleasant words are persuasive." Proverbs 16:21 (New Living Translation) Team OS/2 ** Reg. Linux User #211409 ** a11y rocks! Felix Miata *** http://fm.no-ip.com/
Karel Zak
maintainerQuoted 8 lines · Felix Miata
dE composed on 2014-10-28 10:00 (UTC+0530):
Quoted 2 lines
But I also think this fdisk 2048 behavior should be removed now or at least provide a switch for the same and document this in the man page.
There is a switch:
-c , --compatibility[=mode]
Please, don't use this option. You can move the first sector of the first partition in expert menu by command 'b'.
Quoted 1 line
The man page does fail to explain what dos mode actually means.
- start at sector 63
- care about CHS in partition table
- extra checks for alignment to be compatible with CHS addressing
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak composed on 2014-10-28 08:32 (UTC+0100):
Quoted 5 lines
Quoted 1 line
The man page does fail to explain what dos mode actually means.
- start at sector 63
- care about CHS in partition table
- extra checks for alignment to be compatible with CHS addressing
Why isn't that in the man page? People trying to use a program aren't always able to Google an explanation of its man page minimalism.
Signature · 6 lines
"The wise are known for their understanding, and pleasant words are persuasive." Proverbs 16:21 (New Living Translation) Team OS/2 ** Reg. Linux User #211409 ** a11y rocks! Felix Miata *** http://fm.no-ip.com/
Am Dienstag, 28. Oktober 2014, 03:49:00 schrieb Felix Miata:
Quoted 9 lines
Karel Zak composed on 2014-10-28 08:32 (UTC+0100):
Quoted 5 lines
Quoted 2 lines
The man page does fail to explain what dos mode actually means.
- start at sector 63
- care about CHS in partition table
- extra checks for alignment to be compatible with CHS addressingWhy isn't that in the man page? People trying to use a program aren't always able to Google an explanation of its man page minimalism.
You are free to contribute…
Signature · 2 lines
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de GPG: 03B0 0D6C 0040 0710 4AFA B82F 991B EAAC A599 84C7
Hello you with the unknown real name,
Am Dienstag, 28. Oktober 2014, 08:54:56 schrieb dE:
Quoted 11 lines · Felix Miata
Quoted 10 lines
dE composed on 2014-10-28 00:13 (UTC+0530):
Quoted 8 lines
I was learning about GPT when I noticed this behavior of fdisk which I never though about before.
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors. Why this behavior?
Quoted 6 lines
Quoted 3 lines
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives
-master-ti/ may provide some insight WRT performance issues ensuing from other start sector selections.But that works even with multiples of 8. So we can start from sector 8 in MBR and 40 in GPT.
But then you have SoftRAID or Hardware RAID with 64 or 512 KiB chunk size. Or you have SSD/PCIe or other flash with erase block sizes and so son. 1 MiB is dividable by these usual sizes.
Why is this an issue for you?
Also see -c=dos switch or interactive "c" command:
merkaba:~> LANG=C fdisk /dev/sda
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Command (m for help): c
DOS Compatibility flag is set (DEPRECATED!)
Command (m for help): o
"
Created a new DOS disklabel with disk identifier 0x7c1893d1.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (63-586072367, default 63):
"DOS-compatible mode is deprecated." is in red :)
Ciao,
Signature · 2 lines
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de GPG: 03B0 0D6C 0040 0710 4AFA B82F 991B EAAC A599 84C7
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 30 lines · Bruce Dubbs
Quoted 20 lines · dE
Quoted 10 lines · Felix Miata
dE composed on 2014-10-28 00:13 (UTC+0530):
Quoted 8 lines
I was learning about GPT when I noticed this behavior of fdisk which I never though about before.
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors. Why this behavior?Quoted 5 lines
http://www.seagate.com/tech-insights/advanced-format-4k-sector-hard-drives-master-ti/
may provide some insight WRT performance issues ensuing from other start sector selections.
But that works even with multiples of 8. So we can start from sector 8 in MBR and 40 in GPT.
Quoted 6 lines
Also I'm pretty sure fdisk uses 2048 even with -b 4096, but unfortunately I get --
*** Error in `fdisk':
malloc(): memory corruption:0x0000000002507330***with that switch.
You seem to be overly concerned about the disk space below sector 2048. That's a little less than 1M -- less than a floppy disk. In the era of $100/TB, does 1M matter?
Quoted 8 lines
When formatting a drive, there are several issues to consider. If it's a boot drive, then the boot loader needs to go somewhere. Grub puts it in sectors 2-63 for MSDOS style partition tables and in a separate Grub partition for GPT formatted drives.
Larger hard drives (2T+) require a GPT to access the entire drive. They also are formatted internally as 4K sectors. Creating a partition that is not aligned with the disk architecture is inefficient.
IMO, all partitions should be aligned on 1MiB boundaries by default for either type of partition. It's just easier to understand.
-- Bruce
But if fdisk puts it at sector 8 for MBR and sector 40 for GPT, it'll solve the purpose.
2048 is Windows behavior ported to utils-linux. It's pointless.
Quoted 1 line · dE
2048 is Windows behavior ported to utils-linux. It's pointless.
Not if you move to any sort of RAID and want efficiency. Then 64k or 256k alignment is minimal. If you start at 1M, then layering other things on top, -- like default lvm blocks of 4M will still line up at 1M. Then when you layer RAID aware software like xfs on top of those, it can know how to do allocations and layout to allow optimal I/O on most RAID sizes.
Anyone who uses RAID5 or RAID6 based underlying HW will appreciate file systems with full alignment to the underlying device stripes. Partial writes on those types of RAID's (or derivatives) requiring a complete read-modify-write cycle the size of the data stripe, so any underlying disk misalignment will really cause performance pain...
But having all the disks start at 1M, you can usually move complete disk images around on devices and not get hurt by alignment issues.
It seems quite obvious to me -- New technologies are likely to make the natural block size larger over time. Where by "natural block size", I mean the block alignment necessary to get highest performance out of the device/system. You don't want to have to keep modifying your disk structuring software every time a new technology comes out that has a larger natural block size -- and then discover you've got to reorganize all your disk images. By going to 1 MiB alignment now, we may be able to keep the alignment and allocation policies stable for ten or twenty years.
If you have a good reason to use a smaller alignment, the software lets you override the default. But the default minimizes the trouble you risk in the future.
Dale
Karel Zak
maintainerQuoted 8 lines · dE
Regardless of the partition table, fdisk always starts the first partition at 2048. In reality, the maximum size required by the gap between MBR and the 1st partition is a single sector, which's used by GRUB 1.5. GPT doesn't need this space at all.
Then extended partitions too have a gap of 2048 sectors.
Why this behavior?
This is standard behavior for all modern partitioning tools.
# parted -s --align optimal /dev/sdb 'mkpart primary 1 10MiB'
# fdisk -l /dev/sdb Device Start End Size Type /dev/sdb1 2048 20479 9M Microsoft basic data
the goal is to start the first partition on offset which is the most portable and the most useful on all possible disk configurations. If you align partitions to 1MiB than it's good enough for all possible I/O limits (including 4K disks, RAIDs with huge optimal I/O etc). You can dd(1) partition table from 512-byte disk to 4K disk without care about alignment etc.
The overhead (1MiB gap(s)) is minimal to compare to usual disk sizes. (Note that for very small disk we use grain based on real I/O limits.)
The another advantage is that 1MiB offset also unifies all partition tables -- from users point of view all the partition table look very analogous.
If you don't like it, then use fdisk expert menu and move the begin of the partition by command 'b'.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Karel" == Karel Zak <[email protected]> writes:
Karel> This is standard behavior for all modern partitioning tools.
Karel> the goal is to start the first partition on offset which is the Karel> most portable and the most useful on all possible disk Karel> configurations.
Not only that. It was an explicit request from IDEMA. The disk drive and RAID vendors asked all operating system vendors to ensure 1MB alignment by default.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 11 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Karel" == Karel Zak <[email protected]> writes:
Karel> This is standard behavior for all modern partitioning tools.
Karel> the goal is to start the first partition on offset which is the Karel> most portable and the most useful on all possible disk Karel> configurations.
Not only that. It was an explicit request from IDEMA. The disk drive and RAID vendors asked all operating system vendors to ensure 1MB alignment by default.
Ok, it's an IDEMA recommendation. That's why.
Quoted 6 lines · dE
Quoted 4 lines
Not only that. It was an explicit request from IDEMA. The disk drive and RAID vendors asked all operating system vendors to ensure 1MB alignment by default.
Ok, it's an IDEMA recommendation. That's why.
One additional reason why it's a good idea is for better compatibility with drive-managed or host-aware SMR (Shingled Magnetic Recording) disks, it's a really good idea if partitions are aligned on 256 MiB boundaries.
And in the future, the hard drive vendors hope to promulgate 32k or 64k native sector size. If we adopted the suggestion to align new partitions at 4k after the MBR, it would be disastrous for SMR disks (some of which will be shipping soon, or may be shipping already but you might know it, especially for some high-capacity USB attached storage), and for these larger sector disks.
Or if you are using very low-end flash (i.e., on SD cards) which have a very primitive FTL, if the partitions aren't aligned on the erase block, you will also have terrible performance --- and this is true today.
Given the painful history of how long it took to get OS vendors to move off of a sector 63 offset (a decade, thanks to Windows XP), it's not surprising IDEMA has requested that all OS vendors use a 1MB alignment for partitions going forward.
So I don't think we want to change the default. If you're so hard up for space that clawing back that extra 1020k with of disks on a 2T or 6T disk is significant, you can manually adjust the starting offset of the partition. But I really don't think it's worth it, at least for myself....
Cheers,
- Ted
Quoted 34 lines · Theodore Ts'o
Quoted 5 lines · dE
Quoted 4 lines
Not only that. It was an explicit request from IDEMA. The disk drive and RAID vendors asked all operating system vendors to ensure 1MB alignment by default.
Ok, it's an IDEMA recommendation. That's why.
One additional reason why it's a good idea is for better compatibility with drive-managed or host-aware SMR (Shingled Magnetic Recording) disks, it's a really good idea if partitions are aligned on 256 MiB boundaries.
And in the future, the hard drive vendors hope to promulgate 32k or 64k native sector size. If we adopted the suggestion to align new partitions at 4k after the MBR, it would be disastrous for SMR disks (some of which will be shipping soon, or may be shipping already but you might know it, especially for some high-capacity USB attached storage), and for these larger sector disks.
Or if you are using very low-end flash (i.e., on SD cards) which have a very primitive FTL, if the partitions aren't aligned on the erase block, you will also have terrible performance --- and this is true today.
Given the painful history of how long it took to get OS vendors to move off of a sector 63 offset (a decade, thanks to Windows XP), it's not surprising IDEMA has requested that all OS vendors use a 1MB alignment for partitions going forward.
So I don't think we want to change the default. If you're so hard up for space that clawing back that extra 1020k with of disks on a 2T or 6T disk is significant, you can manually adjust the starting offset of the partition. But I really don't think it's worth it, at least for myself....
Quoted 3 lines
Cheers,
- Ted
Thanks for all the answers everyone!
Now I get the point.
This conversation will get a lot of hits.