mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
Split grub and extlinux installs into separate modules
This commit is contained in:
parent
ce8dd02cbf
commit
5823c9119b
8 changed files with 172 additions and 160 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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'])
|
||||
|
|
58
bootstrapvz/common/tasks/extlinux.py
Normal file
58
bootstrapvz/common/tasks/extlinux.py
Normal file
|
@ -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'])
|
96
bootstrapvz/common/tasks/grub.py
Normal file
96
bootstrapvz/common/tasks/grub.py
Normal file
|
@ -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'])
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue