From 7a93002b2d5e0ac6d3ad62468be27862b42a7681 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 11 Aug 2013 23:03:44 +0200 Subject: [PATCH] Parted tasks and grub installation working now --- common/tasks/parted.py | 23 ++++++++++++++--------- providers/virtualbox/tasks/boot.py | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/common/tasks/parted.py b/common/tasks/parted.py index 822e6ef..c8d1190 100644 --- a/common/tasks/parted.py +++ b/common/tasks/parted.py @@ -2,6 +2,7 @@ from base import Task from common import phases from common.tools import log_check_call import filesystem +import loopback class PartitionVolume(Task): @@ -10,14 +11,11 @@ class PartitionVolume(Task): def run(self, info): # parted - log_check_call(['parted', '-a', 'optimal', - '-s', info.bootstrap_device['path'], - 'mklabel', 'msdos']) - log_check_call(['parted', '-a', 'optimal', - '-s', info.bootstrap_device['path'], + log_check_call(['parted', '-a', 'optimal', '-s', info.bootstrap_device['path'], + '--', 'mklabel', 'msdos']) + log_check_call(['parted', '-a', 'optimal', '-s', info.bootstrap_device['path'], '--', 'mkpart', 'primary', 'ext4', '32k', '-1']) - log_check_call(['parted', - '-s', info.bootstrap_device['path'], + log_check_call(['parted', '-s', info.bootstrap_device['path'], '--', 'set', '1', 'boot', 'on']) @@ -29,7 +27,11 @@ class MapPartitions(Task): def run(self, info): log_check_call(['kpartx', '-a', '-v', info.bootstrap_device['path']]) root_partition_path = info.bootstrap_device['path'].replace('/dev', '/dev/mapper')+'p1' - info.bootstrap_device['partitions'] = {'root_path': root_partition_path} + + [root_loopback_path] = log_check_call(['/sbin/losetup', '--find']) + log_check_call(['/sbin/losetup', root_loopback_path, root_partition_path]) + + info.bootstrap_device['partitions'] = {'root_path': root_loopback_path} class FormatPartitions(Task): @@ -46,8 +48,11 @@ class FormatPartitions(Task): class UnmapPartitions(Task): description = 'Removing volume partitions mapping' phase = phases.volume_unmounting + before = [loopback.Detach] after = [filesystem.UnmountVolume] def run(self, info): - log_check_call(['kpartx', '-d', info.loopback_file]) + log_check_call(['/sbin/losetup', '-d', info.bootstrap_device['partitions']['root_path']]) del info.bootstrap_device['partitions']['root_path'] + + log_check_call(['kpartx', '-d', info.bootstrap_device['path']]) diff --git a/providers/virtualbox/tasks/boot.py b/providers/virtualbox/tasks/boot.py index 6ccaa8d..fcd25f9 100644 --- a/providers/virtualbox/tasks/boot.py +++ b/providers/virtualbox/tasks/boot.py @@ -7,10 +7,19 @@ class ConfigureGrub(Task): phase = phases.system_modification def run(self, info): + import os.path + device_map_path = os.path.join(info.root, 'boot/grub/device.map') + with open(device_map_path, 'w') as device_map: + device_map.write(('(hd0) {dev_path}\n' + '(hd0,1) {root_path}' + .format(dev_path=info.bootstrap_device['path'], + root_path=info.bootstrap_device['partitions']['root_path']))) + from common.tools import log_check_call log_check_call(['/usr/sbin/chroot', info.root, 'update-initramfs', '-u']) - log_check_call(['/usr/sbin/grub-install', - '--boot-directory='+info.root+"/boot/", - info.bootstrap_device['path']]) - log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub']) + log_check_call(['/usr/sbin/chroot', info.root, + '/usr/sbin/grub-mkconfig', '-o', '/boot/grub/grub.cfg']) + + log_check_call(['/usr/sbin/chroot', info.root, + '/usr/sbin/grub-install', info.bootstrap_device['path']])