diff --git a/confluent_osdeploy/el7-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el7-diskless/profiles/default/scripts/image2disk.py index ec67bad0..eaccfb62 100644 --- a/confluent_osdeploy/el7-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el7-diskless/profiles/default/scripts/image2disk.py @@ -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: diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py index 3971ca71..65ca4fe6 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py @@ -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: diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py index a0e22247..8cab5e50 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py @@ -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]) diff --git a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/image2disk.py index ef9419f4..3bca6302 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/image2disk.py @@ -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: