mirror of
https://github.com/xcat2/confluent.git
synced 2026-11-20 09:22:27 +00:00
Keep image2disk partitions inside the disk
When the largest filesystem of a captured image is a plain partition, it was sized as the disk minus the other filesystems. That ignored the 2048 sector gap before the first partition and the rounding of every partition up to a 2048 sector boundary, so the last partition always ran past the end of the disk. The clamp then set its end to the sector count, one past the last sector and inside the backup GPT, and parted refused it with 'The location ... is outside of the device'. Images with the largest filesystem in LVM were not affected. Reserve that overhead plus 1MiB at the end of the disk for the backup GPT, and clamp to that last sector instead. Also round the swap partition by its own size rather than by the previous partition's.
This commit is contained in:
@@ -256,7 +256,13 @@ def install_to_disk(imgpath):
|
||||
minsectors = mintotsize // sectorsize
|
||||
if sectors < (minsectors + 65536):
|
||||
raise Exception('Disk too small to fit image')
|
||||
biggestsectors = sectors - (minexcsize // sectorsize)
|
||||
# leave room for the 1MiB gap before the first partition, up to 1MiB of
|
||||
# rounding per partition and the backup GPT at the end of the disk
|
||||
lastsector = sectors - 2048
|
||||
nparts = len(plainvols)
|
||||
if swapsize and not lvmvols:
|
||||
nparts += 1
|
||||
biggestsectors = lastsector - 2048 * (nparts + 1) - (minexcsize // sectorsize)
|
||||
biggestsize = sectorsize * biggestsectors
|
||||
parted.run('mklabel gpt')
|
||||
curroffset = 2048
|
||||
@@ -268,18 +274,18 @@ def install_to_disk(imgpath):
|
||||
size = biggestsize // sectorsize
|
||||
size += 2047 - (size % 2048)
|
||||
end = curroffset + size
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart primary {}s {}s'.format(curroffset, end))
|
||||
vol['targetdisk'] = get_partname(instdisk , volidx)
|
||||
curroffset += size + 1
|
||||
if not lvmvols:
|
||||
if swapsize:
|
||||
swapsize = swapsize // sectorsize
|
||||
swapsize += 2047 - (size % 2048)
|
||||
swapsize += 2047 - (swapsize % 2048)
|
||||
end = curroffset + swapsize
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart swap {}s {}s'.format(curroffset, end))
|
||||
subprocess.check_call(['mkswap', get_partname(instdisk, volidx + 1)])
|
||||
else:
|
||||
|
||||
@@ -345,7 +345,13 @@ def install_to_disk(imgpath):
|
||||
minsectors = mintotsize // sectorsize
|
||||
if sectors < (minsectors + 65536):
|
||||
raise Exception('Disk too small to fit image')
|
||||
biggestsectors = sectors - (minexcsize // sectorsize)
|
||||
# leave room for the 1MiB gap before the first partition, up to 1MiB of
|
||||
# rounding per partition and the backup GPT at the end of the disk
|
||||
lastsector = sectors - 2048
|
||||
nparts = len(plainvols)
|
||||
if swapsize and not lvmvols:
|
||||
nparts += 1
|
||||
biggestsectors = lastsector - 2048 * (nparts + 1) - (minexcsize // sectorsize)
|
||||
biggestsize = sectorsize * biggestsectors
|
||||
parted.run('mklabel gpt')
|
||||
curroffset = 2048
|
||||
@@ -357,18 +363,18 @@ def install_to_disk(imgpath):
|
||||
size = biggestsize // sectorsize
|
||||
size += 2047 - (size % 2048)
|
||||
end = curroffset + size
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart primary {}s {}s'.format(curroffset, end))
|
||||
vol['targetdisk'] = get_partname(instdisk, volidx)
|
||||
curroffset += size + 1
|
||||
if not lvmvols:
|
||||
if swapsize:
|
||||
swapsize = swapsize // sectorsize
|
||||
swapsize += 2047 - (size % 2048)
|
||||
swapsize += 2047 - (swapsize % 2048)
|
||||
end = curroffset + swapsize
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart swap {}s {}s'.format(curroffset, end))
|
||||
subprocess.check_call(['mkswap', get_partname(instdisk, volidx + 1)])
|
||||
else:
|
||||
|
||||
@@ -447,7 +447,13 @@ def install_to_disk(imgpath):
|
||||
minsectors = mintotsize // sectorsize
|
||||
if sectors < (minsectors + 65536):
|
||||
raise Exception('Disk too small to fit image')
|
||||
biggestsectors = sectors - (minexcsize // sectorsize)
|
||||
# leave room for the 1MiB gap before the first partition, up to 1MiB of
|
||||
# rounding per partition and the backup GPT at the end of the disk
|
||||
lastsector = sectors - 2048
|
||||
nparts = len(plainvols)
|
||||
if swapsize and not lvmvols:
|
||||
nparts += 1
|
||||
biggestsectors = lastsector - 2048 * (nparts + 1) - (minexcsize // sectorsize)
|
||||
biggestsize = sectorsize * biggestsectors
|
||||
parted.run('mklabel gpt')
|
||||
curroffset = 2048
|
||||
@@ -459,8 +465,8 @@ def install_to_disk(imgpath):
|
||||
size = biggestsize // sectorsize
|
||||
size += 2047 - (size % 2048)
|
||||
end = curroffset + size
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart primary {}s {}s'.format(curroffset, end))
|
||||
vol['targetdisk'] = get_partname(instdisk, volidx)
|
||||
if vol['mount'] == '/':
|
||||
@@ -469,10 +475,10 @@ def install_to_disk(imgpath):
|
||||
if not lvmvols:
|
||||
if swapsize:
|
||||
swapsize = swapsize // sectorsize
|
||||
swapsize += 2047 - (size % 2048)
|
||||
swapsize += 2047 - (swapsize % 2048)
|
||||
end = curroffset + swapsize
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart swap {}s {}s'.format(curroffset, end))
|
||||
newswapdev = get_partname(instdisk, volidx + 1)
|
||||
subprocess.check_call(['mkswap', newswapdev])
|
||||
|
||||
@@ -287,7 +287,13 @@ def install_to_disk(imgpath):
|
||||
minsectors = mintotsize // sectorsize
|
||||
if sectors < (minsectors + 65536):
|
||||
raise Exception('Disk too small to fit image')
|
||||
biggestsectors = sectors - (minexcsize // sectorsize)
|
||||
# leave room for the 1MiB gap before the first partition, up to 1MiB of
|
||||
# rounding per partition and the backup GPT at the end of the disk
|
||||
lastsector = sectors - 2048
|
||||
nparts = len(plainvols)
|
||||
if swapsize and not lvmvols:
|
||||
nparts += 1
|
||||
biggestsectors = lastsector - 2048 * (nparts + 1) - (minexcsize // sectorsize)
|
||||
biggestsize = sectorsize * biggestsectors
|
||||
parted.run('mklabel gpt')
|
||||
curroffset = 2048
|
||||
@@ -299,18 +305,18 @@ def install_to_disk(imgpath):
|
||||
size = biggestsize // sectorsize
|
||||
size += 2047 - (size % 2048)
|
||||
end = curroffset + size
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart primary {}s {}s'.format(curroffset, end))
|
||||
vol['targetdisk'] = get_partname(instdisk, volidx)
|
||||
curroffset += size + 1
|
||||
if not lvmvols:
|
||||
if swapsize:
|
||||
swapsize = swapsize // sectorsize
|
||||
swapsize += 2047 - (size % 2048)
|
||||
swapsize += 2047 - (swapsize % 2048)
|
||||
end = curroffset + swapsize
|
||||
if end > sectors:
|
||||
end = sectors
|
||||
if end > lastsector:
|
||||
end = lastsector
|
||||
parted.run('mkpart swap {}s {}s'.format(curroffset, end))
|
||||
subprocess.check_call(['mkswap', get_partname(instdisk, volidx + 1)])
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user