Parted tasks and grub installation working now

This commit is contained in:
Anders Ingemann 2013-08-11 23:03:44 +02:00
parent cecdeba45f
commit 7a93002b2d
2 changed files with 27 additions and 13 deletions

View file

@ -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']])

View file

@ -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']])