From e4a9cc837ae54ddb3007de71f658cf9a1a1c756c Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Wed, 9 Jul 2014 21:20:26 +0200 Subject: [PATCH] Differentiate installation of grub 1.99 and grub 2 --- bootstrapvz/common/task_groups.py | 19 +++++++++++---- bootstrapvz/common/tasks/boot.py | 28 +++++++++++++--------- bootstrapvz/plugins/docker_daemon/tasks.py | 2 +- bootstrapvz/providers/azure/tasks/boot.py | 2 +- bootstrapvz/providers/gce/tasks/boot.py | 2 +- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/bootstrapvz/common/task_groups.py b/bootstrapvz/common/task_groups.py index c10c177..96e125c 100644 --- a/bootstrapvz/common/task_groups.py +++ b/bootstrapvz/common/task_groups.py @@ -30,7 +30,7 @@ def get_standard_groups(manifest): group.extend(get_apt_group(manifest)) group.extend(security_group) group.extend(locale_group) - group.extend(bootloader_group.get(manifest.system['bootloader'], [])) + group.extend(get_bootloader_group(manifest)) group.extend(cleanup_group) return group @@ -126,9 +126,20 @@ locale_group = [locale.LocaleBootstrapPackage, ] -bootloader_group = {'grub': [boot.AddGrubPackage, boot.ConfigureGrub, boot.InstallGrub], - 'extlinux': [boot.AddExtlinuxPackage, boot.InstallExtLinux], - } +def get_bootloader_group(manifest): + group = [] + if manifest.system['bootloader'] == 'grub': + group.extend([boot.AddGrubPackage, + boot.ConfigureGrub]) + from bootstrapvz.common.tools import get_codename + if get_codename(manifest.system['release']) in ['squeeze', 'wheezy']: + group.append(boot.InstallGrub_1_99) + else: + group.append(boot.InstallGrub_2) + if manifest.system['bootloader'] == 'extlinux': + group.extend([boot.AddExtlinuxPackage, + boot.InstallExtLinux]) + return group def get_fs_specific_group(manifest): diff --git a/bootstrapvz/common/tasks/boot.py b/bootstrapvz/common/tasks/boot.py index 05dab75..c0a4d4d 100644 --- a/bootstrapvz/common/tasks/boot.py +++ b/bootstrapvz/common/tasks/boot.py @@ -1,5 +1,6 @@ from bootstrapvz.base import Task from .. import phases +from ..tools import log_check_call import apt import filesystem from bootstrapvz.base.fs import partitionmaps @@ -58,18 +59,13 @@ class ConfigureGrub(Task): 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"') -class InstallGrub(Task): - description = 'Installing grub' +class InstallGrub_1_99(Task): + description = 'Installing grub 1.99' phase = phases.system_modification predecessors = [filesystem.FStab] @classmethod def run(cls, info): - from ..fs.loopbackvolume import LoopbackVolume - from ..tools import log_check_call - - boot_dir = os.path.join(info.root, 'boot') - grub_dir = os.path.join(boot_dir, 'grub') from ..fs import remount p_map = info.volume.partition_map @@ -87,11 +83,12 @@ class InstallGrub(Task): # 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/ + from ..fs.loopbackvolume import LoopbackVolume if isinstance(info.volume, LoopbackVolume): remount(info.volume, link_fn) try: [device_path] = log_check_call(['readlink', '-f', info.volume.device_path]) - device_map_path = os.path.join(grub_dir, 'device.map') + device_map_path = os.path.join(info.root, 'boot/grub/device.map') partition_prefix = 'msdos' if isinstance(p_map, partitionmaps.gpt.GPTPartitionMap): partition_prefix = 'gpt' @@ -105,8 +102,7 @@ class InstallGrub(Task): idx=idx + 1)) # Install grub - log_check_call(['chroot', info.root, - 'grub-install', device_path]) + log_check_call(['chroot', info.root, 'grub-install', device_path]) log_check_call(['chroot', info.root, 'update-grub']) except Exception as e: if isinstance(info.volume, LoopbackVolume): @@ -117,6 +113,17 @@ class InstallGrub(Task): remount(info.volume, unlink_fn) +class InstallGrub_2(Task): + description = 'Installing grub 2' + phase = phases.system_modification + predecessors = [filesystem.FStab] + + @classmethod + def run(cls, info): + log_check_call(['chroot', info.root, 'grub-install', info.volume.device_path]) + log_check_call(['chroot', info.root, 'update-grub']) + + class AddExtlinuxPackage(Task): description = 'Adding extlinux package' phase = phases.preparation @@ -136,7 +143,6 @@ class InstallExtLinux(Task): @classmethod def run(cls, info): - from ..tools import log_check_call if isinstance(info.volume.partition_map, partitionmaps.gpt.GPTPartitionMap): bootloader = '/usr/lib/syslinux/gptmbr.bin' else: diff --git a/bootstrapvz/plugins/docker_daemon/tasks.py b/bootstrapvz/plugins/docker_daemon/tasks.py index d44a661..e82aad2 100644 --- a/bootstrapvz/plugins/docker_daemon/tasks.py +++ b/bootstrapvz/plugins/docker_daemon/tasks.py @@ -52,7 +52,7 @@ class AddDockerInit(Task): class EnableMemoryCgroup(Task): description = 'Change grub configuration to enable the memory cgroup' phase = phases.system_modification - successors = [boot.InstallGrub] + successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] predecessors = [boot.ConfigureGrub, gceboot.ConfigureGrub] @classmethod diff --git a/bootstrapvz/providers/azure/tasks/boot.py b/bootstrapvz/providers/azure/tasks/boot.py index 5fc4756..7f95276 100644 --- a/bootstrapvz/providers/azure/tasks/boot.py +++ b/bootstrapvz/providers/azure/tasks/boot.py @@ -6,7 +6,7 @@ from bootstrapvz.common.tasks import boot class ConfigureGrub(Task): description = 'Change grub configuration to allow for ttyS0 output' phase = phases.system_modification - successors = [boot.InstallGrub] + successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] @classmethod def run(cls, info): diff --git a/bootstrapvz/providers/gce/tasks/boot.py b/bootstrapvz/providers/gce/tasks/boot.py index 1100210..6d03025 100644 --- a/bootstrapvz/providers/gce/tasks/boot.py +++ b/bootstrapvz/providers/gce/tasks/boot.py @@ -7,7 +7,7 @@ import os.path class ConfigureGrub(Task): description = 'Change grub configuration to allow for ttyS0 output' phase = phases.system_modification - successors = [boot.InstallGrub] + successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] @classmethod def run(cls, info):