Skip to content
Snippets Groups Projects
Commit 1a5fd89f authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Reinstall extlinux after shrinking if needed

If extlinux is installed on the root partition (the OS does not have a
separate /boot partition) it needs to be reinstalled, otherwise the OS
won't boot.
parent 9777ab86
No related branches found
No related tags found
No related merge requests found
......@@ -299,8 +299,8 @@ class Image(object):
"""Shrink the image.
This is accomplished by shrinking the last file system of the
image and then updating the partition table. The new disk size
(in bytes) is returned.
image and then updating the partition table. The shrinked device is
returned.
ATTENTION: make sure umount is called before shrink
"""
......@@ -351,7 +351,7 @@ class Image(object):
if self.is_unsupported():
if not silent:
self.out.warn("Shrinking is disabled for unsupported images")
return self.size
return None
sector_size = self.g.blockdev_getss(self.guestfs_device)
......@@ -381,7 +381,7 @@ class Image(object):
if not silent:
self.out.warn(
"Don't know how to shrink %s partitions." % fstype)
return self.size
return None
part_dev = "%s%d" % (self.guestfs_device, last_part['part_num'])
......@@ -461,7 +461,7 @@ class Image(object):
self.out.success("Image size is %dMB" %
((self.size + MB - 1) // MB))
return self.size
return part_dev
def mount(self, mpoint, readonly=False):
"""Mount the image file system under a local directory"""
......
......@@ -20,7 +20,7 @@ Systems for image creation.
"""
from image_creator.util import FatalError
from image_creator.bootloader import mbr_bootinfo
from image_creator.bootloader import mbr_bootinfo, vbr_bootinfo
import textwrap
import re
......@@ -483,9 +483,28 @@ class OSBase(object):
@sysprep('Shrinking image (may take a while)', nomount=True)
def _shrink(self):
"""Shrink the last file system and update the partition table"""
self.image.shrink()
device = self.image.shrink()
self.shrinked = True
# Check the Volume Boot Record of the shrinked partition to determine
# if a bootloader is present on it.
vbr = self.image.g.pread_device(device, 512, 0)
bootloader = vbr_bootinfo(vbr)
if bootloader == 'syslinux':
# EXTLINUX needs to be reinstalled after shrinking
with self.mount(silent=True):
self.out.info("Reinstalling extlinux ...", False)
if self.image.g.is_dir('/boot/extlinux'):
extdir = '/boot/extlinux'
elif self.image.g.is_dir('/boot/syslinux'):
extdir = '/boot/syslinux'
else:
extdir = '/boot'
self.image.g.command(['extlinux', '--install', extdir])
self.out.success("done")
@property
def ismounted(self):
return self._mounted is not None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment