mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Take partitionmap into consideration in device.map
Simplify boot task a little
This commit is contained in:
parent
977b1f290f
commit
c78866f103
1 changed files with 16 additions and 10 deletions
|
@ -17,13 +17,14 @@ class ConfigureGrub(Task):
|
|||
grub_dir = os.path.join(boot_dir, 'grub')
|
||||
|
||||
from base.fs.partitionmaps.none import NoPartitions
|
||||
from base.fs.partitionmaps.gpt import GPTPartitionMap
|
||||
p_map = info.volume.partition_map
|
||||
|
||||
def remount(volume, fn):
|
||||
def remount(fn):
|
||||
# GRUB cannot deal with installing to loopback devices
|
||||
# so we fake a real harddisk with dmsetup.
|
||||
# Guide here: http://ebroder.net/2009/08/04/installing-grub-onto-a-disk-image/
|
||||
volume.unmount_specials()
|
||||
p_map = volume.partition_map
|
||||
info.volume.unmount_specials()
|
||||
if hasattr(p_map, 'boot'):
|
||||
boot_dir = p_map.boot.mount_dir
|
||||
p_map.boot.unmount()
|
||||
|
@ -34,22 +35,27 @@ class ConfigureGrub(Task):
|
|||
p_map.map()
|
||||
else:
|
||||
fn()
|
||||
p_map.root.device_path = volume.device_path
|
||||
p_map.root.device_path = info.volume.device_path
|
||||
p_map.root.mount(info.root)
|
||||
if hasattr(p_map, 'boot'):
|
||||
p_map.boot.mount(boot_dir)
|
||||
volume.mount_specials()
|
||||
info.volume.mount_specials()
|
||||
|
||||
if isinstance(info.volume, LoopbackVolume):
|
||||
remount(info.volume, info.volume.link_dm_node)
|
||||
remount(info.volume.link_dm_node)
|
||||
try:
|
||||
[device_path] = log_check_call(['readlink', '-f', info.volume.device_path])
|
||||
device_map_path = os.path.join(grub_dir, 'device.map')
|
||||
partition_prefix = 'msdos'
|
||||
if isinstance(p_map, GPTPartitionMap):
|
||||
partition_prefix = 'gpt'
|
||||
with open(device_map_path, 'w') as device_map:
|
||||
device_map.write('(hd0) {device_path}\n'.format(device_path=device_path))
|
||||
if not isinstance(p_map, NoPartitions):
|
||||
for idx, partition in enumerate(info.volume.partition_map.partitions):
|
||||
[partition_path] = log_check_call(['readlink', '-f', partition.device_path])
|
||||
device_map.write('(hd0,gpt{idx}) {device_path}\n'.format(device_path=partition_path, idx=idx+1))
|
||||
device_map.write('(hd0,{prefix}{idx}) {device_path}\n'
|
||||
.format(device_path=partition_path, prefix=partition_prefix, idx=idx+1))
|
||||
|
||||
# Install grub
|
||||
log_check_call(['/usr/sbin/chroot', info.root,
|
||||
|
@ -60,7 +66,7 @@ class ConfigureGrub(Task):
|
|||
log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub'])
|
||||
except Exception as e:
|
||||
if isinstance(info.volume, LoopbackVolume):
|
||||
remount(info.volume, info.volume.unlink_dm_node)
|
||||
remount(info.volume.unlink_dm_node)
|
||||
raise e
|
||||
|
||||
if isinstance(info.volume, LoopbackVolume):
|
||||
|
|
Loading…
Add table
Reference in a new issue