On Sat, Jan 02, 2010 at 01:01:16PM +0100, Giulio wrote: > In particular, I can dump "sfdisk -d" the partition table and then sfdisk > will refuse to use its own dump as input on the basis that the disk is not > large enough. Yes, you're right. Unfortunately, the sfdisk command internally uses number of cylinders rather than number of sectors... Fixed, see the patch below. Thanks. Karel >From dfb536c33812d24553350fc9ec08035bf7df52b6 Mon Sep 17 00:00:00 2001 From: Karel Zak <kzak@xxxxxxxxxx> Date: Mon, 4 Jan 2010 11:34:13 +0100 Subject: [PATCH] sfdisk: confused about disk size The size of disk in the sfdisk command is based on number of cylinders (this is probably legacy from CHS epoch). That's wrong because partitions are addressed in sectors (LBA), so cylinders don't provide necessary resolution (granularity). On Sat, Jan 02, 2010 at 01:01:16PM +0100, Giulio wrote: > $ cat /sys/block/sda/size > 184549376 > > $ sfdisk -d /dev/sda > part.dump > $ cat part.dump > # partition table of /dev/sda > unit: sectors > > /dev/sda1 : start= 2048, size= 2097152, Id=83 > /dev/sda2 : start= 2099200, size= 12582912, Id=83 > /dev/sda3 : start= 14682112, size= 84934656, Id=83 > /dev/sda4 : start= 99616768, size= 84932608, Id=83 > > > $ sfdisk -L /dev/sda < part.dump > Checking that no-one is using this disk right now ... > OK > > Disk /dev/sda: 11487 cylinders, 255 heads, 63 sectors/track > Old situation: > Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 > > Device Boot Start End #cyls #blocks Id System > /dev/sda1 0+ 130- 131- 1048576 83 Linux > /dev/sda2 130+ 913- 784- 6291456 83 Linux > /dev/sda3 913+ 6200- 5287- 42467328 83 Linux > /dev/sda4 6200+ 11487- 5287- 42466304 83 Linux > Warning: given size (84932608) exceeds max allowable size (84921887) disk size: based on number of cylinders: 11487 * 8225280 = 94483791360 bytes based on number of sectors: 184549376 * 512 = 94489280512 bytes end of 4th partition (LBA in bytes): (99616768 + 84932608) * 512 = 94489280512 Reported-by: Giulio <giulioo@xxxxxxxxx> Signed-off-by: Karel Zak <kzak@xxxxxxxxxx> --- fdisk/sfdisk.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index 3283146..0652cfa 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -906,10 +906,11 @@ unitsize(int format) { static unsigned long get_disksize(int format) { - unsigned long cs = B.cylinders; - if (cs && leave_last) - cs--; - return (cs * B.cylindersize) / unitsize(format); + if (B.total_size && leave_last) + /* don't use last cylinder (--leave-last option) */ + return (B.total_size - B.cylindersize) / unitsize(format); + + return B.total_size / unitsize(format); } static void -- 1.6.5.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html