bootstrap-vz/providers/virtualbox/tasks/boot.py
Anders Ingemann ff7c04c120 Support for partitions
MAJOR refactor. The volume is now abstracted into a model along with a partitionmap and partitions.
Volumes and partitions are now controlled via an FSM to ensure that commands are called in the proper sequence.
GRUB can now be installed properly onto loop devices by using dmsetup to fake a proper harddisk.
2013-10-27 18:11:12 +01:00

47 lines
1.5 KiB
Python

from base import Task
from common import phases
from common.tasks import apt
from common.fs.loopbackvolume import LoopbackVolume
class ConfigureGrub(Task):
description = 'Configuring grub'
phase = phases.system_modification
after = [apt.AptUpgrade]
def run(self, info):
import os
from common.tools import log_check_call
boot_dir = os.path.join(info.root, 'boot')
grub_dir = os.path.join(boot_dir, 'grub')
if isinstance(info.volume, LoopbackVolume):
info.volume.unmount()
info.volume.unmap()
info.volume.link_dm_node()
info.volume.map()
info.volume.mount_root(info.root)
info.volume.mount_boot()
info.volume.mount_specials()
[device_path] = log_check_call(['readlink', '-f', info.volume.device_path])
device_map_path = os.path.join(grub_dir, 'device.map')
with open(device_map_path, 'w') as device_map:
device_map.write('(hd0) {device_path}\n'.format(device_path=device_path))
# Install grub
log_check_call(['/usr/sbin/grub-install',
'--root-directory=' + info.root,
'--boot-directory=' + boot_dir,
device_path])
log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub'])
# log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-initramfs', '-u'])
if isinstance(info.volume, LoopbackVolume):
info.volume.unmount()
info.volume.unmap()
info.volume.unlink_dm_node()
info.volume.map()
info.volume.mount_root(info.root)
info.volume.mount_boot()
info.volume.mount_specials()