4k alignment of MBR slices / BSD partitions is not working correctly
Miroslav Lachman
000.fbsd at quip.cz
Wed Dec 12 01:00:25 UTC 2012
There is a problem with fdisk and gpart as discussed below this blogpost
http://ivoras.net/blog/tree/2011-01-01.freebsd-on-4k-sector-drives.html
Alignment works with GPT schema, but not with MBR.
Both tools - fdisk and gpart - are doing some auto corrections causing
misalignment of partitions.
It is even worse, that user can create an aligned slices with
interactive fdisk and resulting setup cannot be restored later by some
script.
This is on FreeBSD 9.1-RC3 amd64 GENERIC
# echo 'p 1 165 64 40G' | fdisk -f - /dev/mirror/gm0
******* Working on device /dev/mirror/gm0 *******
fdisk: WARNING: adjusting start offset of partition 1
from 64 to 126, to fall on a head boundary
fdisk: WARNING: adjusting size of partition 1 from 83875301 to 83875239
to end on a cylinder boundary
Resulting slice is not starting on requested 64, but on 126
Again with the gpart and MBR scheme
# gpart create -s mbr mirror/gm0
mirror/gm0 created
# gpart add -b 64 -s 40g -t freebsd mirror/gm0
mirror/gm0s1 added
# gpart show -p mirror/gm0
=> 63 1951475648 mirror/gm0 MBR (930G)
63 63 - free - (31k)
126 83886012 mirror/gm0s1 freebsd (40G)
83886138 1867589573 - free - (890G)
Silently changed from 64 to 126 (63)
Next test with gpart -a 4k
# gpart create -s mbr mirror/gm0
mirror/gm0 created
# gpart add -a 4k -s 40g -t freebsd mirror/gm0
mirror/gm0s1 added
# gpart show -p mirror/gm0
=> 63 1951475648 mirror/gm0 MBR (930G)
63 63 - free - (31k)
126 83886012 mirror/gm0s1 freebsd (40G)
83886138 1867589573 - free - (890G)
Same wrong result as in previous test
But it can be set correctly with interactive fdisk in 9.1-RC3
(impossible in older releases)
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 63, size 1951463682 (952863 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 640/ head 254/ sector 63
Supply a decimal value for "sysid (165=FreeBSD)" [165]
Supply a decimal value for "start" [63] 64
Supply a decimal value for "size" [1951463682] 83886080
fdisk: WARNING: partition does not start on a head boundary
fdisk: WARNING: partition does not end on a cylinder boundary
fdisk: WARNING: this may confuse the BIOS or some operating systems
Correct this automatically? [n] n
Explicitly specify beg/end address ? [n]
Result shown by gpart
# gpart show -p mirror/gm0
=> 63 1951475648 mirror/gm0 MBR (930G)
63 1 - free - (512B)
64 83886080 mirror/gm0s1 freebsd [active] (40G)
83886144 1867577602 mirror/gm0s2 freebsd (890G)
1951463746 11965 - free - (5.9M)
But the worst problem is, that now it cannot be backed up and restored!
# gpart backup mirror/gm0
MBR 4
1 freebsd 64 83886080 [active]
2 freebsd 83886144 1867577602
# gpart backup mirror/gm0 > gm0.gpart.backup
# gpart destroy -F /dev/mirror/gm0
mirror/gm0 destroyed
# gpart restore mirror/gm0 < gm0.gpart.backup
# gpart show -p mirror/gm0
=> 63 1951475648 mirror/gm0 MBR (930G)
63 63 - free - (31k)
126 83886012 mirror/gm0s1 freebsd [active] (40G)
83886138 63 - free - (31k)
83886201 1867577544 mirror/gm0s2 freebsd (890G)
1951463745 11966 - free - (5.9M)
I think that some tools need to be fixed. I vote for fdisk & gpart
allowing to do what is user asking to do (maybe with some "use force"
switch) or disallow interactive fdisk to create partitioning which
cannot be restored later.
I would like to discuss it here before creating PR.
Miroslav Lachman
More information about the freebsd-geom
mailing list