2013-07-01 23:15:49 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-12-29 23:21:50 +01:00
|
|
|
from . import assets
|
2013-07-07 18:07:15 +02:00
|
|
|
import os
|
2013-07-01 23:15:49 +02:00
|
|
|
|
|
|
|
|
2013-12-01 23:50:32 +01:00
|
|
|
class ConfigurePVGrub(Task):
|
|
|
|
description = 'Creating grub config files for PVGrub'
|
2013-07-01 23:15:49 +02:00
|
|
|
phase = phases.system_modification
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
import stat
|
|
|
|
rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
|
|
|
stat.S_IRGRP | stat.S_IXGRP |
|
|
|
|
stat.S_IROTH | stat.S_IXOTH)
|
|
|
|
x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
|
|
|
|
2013-07-07 18:07:15 +02:00
|
|
|
grubd = os.path.join(info.root, 'etc/grub.d')
|
|
|
|
for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]:
|
2013-07-01 23:15:49 +02:00
|
|
|
os.chmod(cfg, os.stat(cfg).st_mode & ~ x_all)
|
|
|
|
|
|
|
|
from shutil import copy
|
2013-12-29 23:21:50 +01:00
|
|
|
script_src = os.path.join(assets, 'grub.d/40_custom')
|
2013-07-01 23:15:49 +02:00
|
|
|
script_dst = os.path.join(info.root, 'etc/grub.d/40_custom')
|
|
|
|
copy(script_src, script_dst)
|
|
|
|
os.chmod(script_dst, rwxr_xr_x)
|
|
|
|
|
2013-10-27 17:47:39 +01:00
|
|
|
from base.fs.partitionmaps.none import NoPartitions
|
|
|
|
if not isinstance(info.volume.partition_map, NoPartitions):
|
|
|
|
from common.tools import sed_i
|
|
|
|
root_idx = info.volume.partition_map.root.get_index()
|
|
|
|
grub_device = 'GRUB_DEVICE=/dev/xvda{idx}'.format(idx=root_idx)
|
|
|
|
sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', grub_device)
|
2013-12-14 19:37:23 +01:00
|
|
|
grub_root = '\troot (hd0,{idx})'.format(idx=root_idx - 1)
|
2013-10-27 17:47:39 +01:00
|
|
|
sed_i(script_dst, '^\troot \(hd0\)$', grub_root)
|
|
|
|
|
|
|
|
if info.manifest.volume['backing'] == 's3':
|
|
|
|
from common.tools import sed_i
|
|
|
|
sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', 'GRUB_DEVICE=/dev/xvda1')
|
|
|
|
|
2013-07-01 23:15:49 +02:00
|
|
|
from common.tools import sed_i
|
|
|
|
grub_def = os.path.join(info.root, 'etc/default/grub')
|
2013-07-07 17:06:44 +02:00
|
|
|
sed_i(grub_def, '^GRUB_TIMEOUT=[0-9]+', 'GRUB_TIMEOUT=0\n'
|
|
|
|
'GRUB_HIDDEN_TIMEOUT=true')
|
2013-07-01 23:15:49 +02:00
|
|
|
|
|
|
|
from common.tools import log_check_call
|
2013-07-07 19:38:34 +02:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub'])
|
2013-08-17 15:00:53 +00:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/bin/ln', '--symbolic', '/boot/grub/grub.cfg', '/boot/grub/menu.lst'])
|