diff --git a/bootstrapvz/common/task_groups.py b/bootstrapvz/common/task_groups.py index 330c598..d6370d0 100644 --- a/bootstrapvz/common/task_groups.py +++ b/bootstrapvz/common/task_groups.py @@ -1,7 +1,8 @@ from tasks import workspace from tasks import packages from tasks import host -from tasks import boot +from tasks import grub +from tasks import extlinux from tasks import bootstrap from tasks import volume from tasks import loopback @@ -129,17 +130,17 @@ locale_group = [locale.LocaleBootstrapPackage, def get_bootloader_group(manifest): group = [] if manifest.system['bootloader'] == 'grub': - group.extend([boot.AddGrubPackage, - boot.ConfigureGrub]) + group.extend([grub.AddGrubPackage, + grub.ConfigureGrub]) from bootstrapvz.common.tools import get_codename if get_codename(manifest.system['release']) in ['squeeze', 'wheezy']: - group.append(boot.InstallGrub_1_99) + group.append(grub.InstallGrub_1_99) else: - group.append(boot.InstallGrub_2) + group.append(grub.InstallGrub_2) if manifest.system['bootloader'] == 'extlinux': - group.extend([boot.AddExtlinuxPackage, - boot.ConfigureExtlinux, - boot.InstallExtlinux]) + group.extend([extlinux.AddExtlinuxPackage, + extlinux.ConfigureExtlinux, + extlinux.InstallExtlinux]) return group diff --git a/bootstrapvz/common/tasks/boot.py b/bootstrapvz/common/tasks/boot.py index 9610fd5..3d7d509 100644 --- a/bootstrapvz/common/tasks/boot.py +++ b/bootstrapvz/common/tasks/boot.py @@ -1,9 +1,5 @@ from bootstrapvz.base import Task from .. import phases -from ..tools import log_check_call -import apt -import filesystem -from bootstrapvz.base.fs import partitionmaps import os.path @@ -45,143 +41,3 @@ class DisableGetTTYs(Task): for i in range(2, 7): i = str(i) sed_i(inittab_path, '^' + i + ttyx + i, '#' + i + ttyx + i) - - -class AddGrubPackage(Task): - description = 'Adding grub package' - phase = phases.preparation - predecessors = [apt.AddDefaultSources] - - @classmethod - def run(cls, info): - info.packages.add('grub-pc') - - -class ConfigureGrub(Task): - description = 'Configuring grub' - phase = phases.system_modification - predecessors = [filesystem.FStab] - - @classmethod - def run(cls, info): - from bootstrapvz.common.tools import sed_i - grub_def = os.path.join(info.root, 'etc/default/grub') - sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') - sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', - 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"') - - -class InstallGrub_1_99(Task): - description = 'Installing grub 1.99' - phase = phases.system_modification - predecessors = [filesystem.FStab] - - @classmethod - def run(cls, info): - - from ..fs import remount - p_map = info.volume.partition_map - - def link_fn(): - info.volume.link_dm_node() - if isinstance(p_map, partitionmaps.none.NoPartitions): - p_map.root.device_path = info.volume.device_path - - def unlink_fn(): - info.volume.unlink_dm_node() - if isinstance(p_map, partitionmaps.none.NoPartitions): - p_map.root.device_path = info.volume.device_path - - # 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(info.root, 'boot/grub/device.map') - partition_prefix = 'msdos' - if isinstance(p_map, partitionmaps.gpt.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, partitionmaps.none.NoPartitions): - for idx, partition in enumerate(info.volume.partition_map.partitions): - device_map.write('(hd0,{prefix}{idx}) {device_path}\n' - .format(device_path=partition.device_path, - prefix=partition_prefix, - idx=idx + 1)) - - # Install grub - 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): - remount(info.volume, unlink_fn) - raise e - - if isinstance(info.volume, LoopbackVolume): - 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 - predecessors = [apt.AddDefaultSources] - - @classmethod - def run(cls, info): - info.packages.add('extlinux') - if isinstance(info.volume.partition_map, partitionmaps.gpt.GPTPartitionMap): - info.packages.add('syslinux-common') - - -class ConfigureExtlinux(Task): - description = 'Configuring extlinux' - phase = phases.system_modification - predecessors = [filesystem.FStab] - - @classmethod - def run(cls, info): - if info.release_codename == 'squeeze': - # On squeeze /etc/default/extlinux is generated when running extlinux-update - log_check_call(['chroot', info.root, - 'extlinux-update']) - from bootstrapvz.common.tools import sed_i - extlinux_def = os.path.join(info.root, 'etc/default/extlinux') - sed_i(extlinux_def, r'^EXTLINUX_PARAMETERS="([^"]+)"$', - r'EXTLINUX_PARAMETERS="\1 console=ttyS0"') - - -class InstallExtlinux(Task): - description = 'Installing extlinux' - phase = phases.system_modification - predecessors = [filesystem.FStab, ConfigureExtlinux] - - @classmethod - def run(cls, info): - if isinstance(info.volume.partition_map, partitionmaps.gpt.GPTPartitionMap): - bootloader = '/usr/lib/syslinux/gptmbr.bin' - else: - bootloader = '/usr/lib/extlinux/mbr.bin' - log_check_call(['chroot', info.root, - 'dd', 'bs=440', 'count=1', - 'if=' + bootloader, - 'of=' + info.volume.device_path]) - log_check_call(['chroot', info.root, - 'extlinux', - '--install', '/boot/extlinux']) - log_check_call(['chroot', info.root, - 'extlinux-update']) diff --git a/bootstrapvz/common/tasks/extlinux.py b/bootstrapvz/common/tasks/extlinux.py new file mode 100644 index 0000000..a050700 --- /dev/null +++ b/bootstrapvz/common/tasks/extlinux.py @@ -0,0 +1,58 @@ +from bootstrapvz.base import Task +from .. import phases +from ..tools import log_check_call +import apt +import filesystem +from bootstrapvz.base.fs import partitionmaps +import os.path + + +class AddExtlinuxPackage(Task): + description = 'Adding extlinux package' + phase = phases.preparation + predecessors = [apt.AddDefaultSources] + + @classmethod + def run(cls, info): + info.packages.add('extlinux') + if isinstance(info.volume.partition_map, partitionmaps.gpt.GPTPartitionMap): + info.packages.add('syslinux-common') + + +class ConfigureExtlinux(Task): + description = 'Configuring extlinux' + phase = phases.system_modification + predecessors = [filesystem.FStab] + + @classmethod + def run(cls, info): + if info.release_codename == 'squeeze': + # On squeeze /etc/default/extlinux is generated when running extlinux-update + log_check_call(['chroot', info.root, + 'extlinux-update']) + from bootstrapvz.common.tools import sed_i + extlinux_def = os.path.join(info.root, 'etc/default/extlinux') + sed_i(extlinux_def, r'^EXTLINUX_PARAMETERS="([^"]+)"$', + r'EXTLINUX_PARAMETERS="\1 console=ttyS0"') + + +class InstallExtlinux(Task): + description = 'Installing extlinux' + phase = phases.system_modification + predecessors = [filesystem.FStab, ConfigureExtlinux] + + @classmethod + def run(cls, info): + if isinstance(info.volume.partition_map, partitionmaps.gpt.GPTPartitionMap): + bootloader = '/usr/lib/syslinux/gptmbr.bin' + else: + bootloader = '/usr/lib/extlinux/mbr.bin' + log_check_call(['chroot', info.root, + 'dd', 'bs=440', 'count=1', + 'if=' + bootloader, + 'of=' + info.volume.device_path]) + log_check_call(['chroot', info.root, + 'extlinux', + '--install', '/boot/extlinux']) + log_check_call(['chroot', info.root, + 'extlinux-update']) diff --git a/bootstrapvz/common/tasks/grub.py b/bootstrapvz/common/tasks/grub.py new file mode 100644 index 0000000..ed781a1 --- /dev/null +++ b/bootstrapvz/common/tasks/grub.py @@ -0,0 +1,96 @@ +from bootstrapvz.base import Task +from .. import phases +from ..tools import log_check_call +import apt +import filesystem +from bootstrapvz.base.fs import partitionmaps +import os.path + + +class AddGrubPackage(Task): + description = 'Adding grub package' + phase = phases.preparation + predecessors = [apt.AddDefaultSources] + + @classmethod + def run(cls, info): + info.packages.add('grub-pc') + + +class ConfigureGrub(Task): + description = 'Configuring grub' + phase = phases.system_modification + predecessors = [filesystem.FStab] + + @classmethod + def run(cls, info): + from bootstrapvz.common.tools import sed_i + grub_def = os.path.join(info.root, 'etc/default/grub') + sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') + sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', + 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"') + + +class InstallGrub_1_99(Task): + description = 'Installing grub 1.99' + phase = phases.system_modification + predecessors = [filesystem.FStab] + + @classmethod + def run(cls, info): + + from ..fs import remount + p_map = info.volume.partition_map + + def link_fn(): + info.volume.link_dm_node() + if isinstance(p_map, partitionmaps.none.NoPartitions): + p_map.root.device_path = info.volume.device_path + + def unlink_fn(): + info.volume.unlink_dm_node() + if isinstance(p_map, partitionmaps.none.NoPartitions): + p_map.root.device_path = info.volume.device_path + + # 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(info.root, 'boot/grub/device.map') + partition_prefix = 'msdos' + if isinstance(p_map, partitionmaps.gpt.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, partitionmaps.none.NoPartitions): + for idx, partition in enumerate(info.volume.partition_map.partitions): + device_map.write('(hd0,{prefix}{idx}) {device_path}\n' + .format(device_path=partition.device_path, + prefix=partition_prefix, + idx=idx + 1)) + + # Install grub + 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): + remount(info.volume, unlink_fn) + raise e + + if isinstance(info.volume, LoopbackVolume): + 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']) diff --git a/bootstrapvz/plugins/docker_daemon/tasks.py b/bootstrapvz/plugins/docker_daemon/tasks.py index 93fcb16..59bef18 100644 --- a/bootstrapvz/plugins/docker_daemon/tasks.py +++ b/bootstrapvz/plugins/docker_daemon/tasks.py @@ -1,6 +1,6 @@ from bootstrapvz.base import Task from bootstrapvz.common import phases -from bootstrapvz.common.tasks import boot +from bootstrapvz.common.tasks import grub from bootstrapvz.common.tasks import initd from bootstrapvz.common.tools import log_check_call from bootstrapvz.common.tools import sed_i @@ -63,8 +63,8 @@ class AddDockerInit(Task): class EnableMemoryCgroup(Task): description = 'Change grub configuration to enable the memory cgroup' phase = phases.system_modification - successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] - predecessors = [boot.ConfigureGrub, gceboot.ConfigureGrub] + successors = [grub.InstallGrub_1_99, grub.InstallGrub_2] + predecessors = [grub.ConfigureGrub, gceboot.ConfigureGrub] @classmethod def run(cls, info): diff --git a/bootstrapvz/providers/azure/tasks/boot.py b/bootstrapvz/providers/azure/tasks/boot.py index 7f95276..8c61fff 100644 --- a/bootstrapvz/providers/azure/tasks/boot.py +++ b/bootstrapvz/providers/azure/tasks/boot.py @@ -1,12 +1,12 @@ from bootstrapvz.base import Task from bootstrapvz.common import phases -from bootstrapvz.common.tasks import boot +from bootstrapvz.common.tasks import grub class ConfigureGrub(Task): description = 'Change grub configuration to allow for ttyS0 output' phase = phases.system_modification - successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] + successors = [grub.InstallGrub_1_99, grub.InstallGrub_2] @classmethod def run(cls, info): diff --git a/bootstrapvz/providers/ec2/__init__.py b/bootstrapvz/providers/ec2/__init__.py index d58ff04..3399831 100644 --- a/bootstrapvz/providers/ec2/__init__.py +++ b/bootstrapvz/providers/ec2/__init__.py @@ -11,6 +11,7 @@ import tasks.initd from bootstrapvz.common.tasks import volume from bootstrapvz.common.tasks import filesystem from bootstrapvz.common.tasks import boot +from bootstrapvz.common.tasks import grub from bootstrapvz.common.tasks import initd from bootstrapvz.common.tasks import loopback from bootstrapvz.common.tasks import kernel @@ -90,7 +91,7 @@ def resolve_tasks(taskset, manifest): taskset.add(initd.AdjustExpandRootScript) if manifest.system['bootloader'] == 'pvgrub': - taskset.add(boot.AddGrubPackage) + taskset.add(grub.AddGrubPackage) taskset.add(tasks.boot.ConfigurePVGrub) if manifest.volume['backing'].lower() == 'ebs': diff --git a/bootstrapvz/providers/gce/tasks/boot.py b/bootstrapvz/providers/gce/tasks/boot.py index 6d03025..224c7fc 100644 --- a/bootstrapvz/providers/gce/tasks/boot.py +++ b/bootstrapvz/providers/gce/tasks/boot.py @@ -1,13 +1,13 @@ from bootstrapvz.base import Task from bootstrapvz.common import phases -from bootstrapvz.common.tasks import boot +from bootstrapvz.common.tasks import grub import os.path class ConfigureGrub(Task): description = 'Change grub configuration to allow for ttyS0 output' phase = phases.system_modification - successors = [boot.InstallGrub_1_99, boot.InstallGrub_2] + successors = [grub.InstallGrub_1_99, grub.InstallGrub_2] @classmethod def run(cls, info):