[parted-devel] "Error: Can't have a partition outside the disk!"
Jim Meyering
jim at meyering.net
Wed Sep 22 14:58:06 UTC 2010
Richard W.M. Jones wrote:
> If you take a virtual disk and truncate it, then likely some
> partitions in the partition table will be off the end of the disk.
>
> However parted refuses to start up in this case. It says:
>
> Error: Can't have a partition outside the disk!
>
> even if you are trying to do something sensible such as deleting a
> partition which is outside the disk.
>
> I can't really see a "good" way to solve this, since it happens in the
> depths of the constraints/geometry code. The attached patch just
> deletes the error check, on the basis that parted should confine
> itself to partition tables and not worry about the size of the disk.
> Discuss ...
Rich,
I tried your patch (but retained the warning),
running it against a sample "device" I shrank by one byte...
created like this:
$ dev=dev-file
$ dd if=/dev/null of=$dev bs=1 seek=2GB
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000256681 s, 0.0 kB/s
$
[Exit 1]
$ parted -s -- $dev mklabel msdos mkpart primary fat32 64s -1s u s p
Warning: The resulting partition is not properly aligned for best performance.
Model: (file)
Disk /c/parted/parted/dev-file: 3906250s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 64s 3906249s 3906186s primary lba
$ truncate -s -1 $dev
$ ./parted -s $dev u s p
Warning: Can't have a partition outside the disk!
Warning: Can't have a partition outside the disk!
Warning: Can't have a partition outside the disk!
...
Assertion (part->geom.end < disk->dev->length) at disk.c:1856 in function _partition_check_basic_sanity() failed.
As you can see, this assumption that partitions
fit within the bounds of the device is at least one
assertion deeper...
Commenting out that assertion, we get a little further:
$ ./parted -s dev-file u s p
Warning: Can't have a partition outside the disk!
Warning: Can't have a partition outside the disk!
Warning: Can't have a partition outside the disk!
Error: Can't have overlapping partitions.
[Exit 1]
The bottom line is that the partition-reading
and -validation code is too tightly coupled.
I'd rather be able to read in the entire partition
table description, and then sanitize it in a separate, optional phase.
But no rewrite today... I barely have time to tend to the occasional
Parted bug report.
More information about the parted-devel
mailing list