2013-07-10 10:49:45 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigureGrub(Task):
|
|
|
|
description = 'Configuring grub'
|
|
|
|
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
|
|
|
|
|
|
|
|
grubd = os.path.join(info.root, 'etc/grub.d')
|
|
|
|
for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]:
|
|
|
|
os.chmod(cfg, os.stat(cfg).st_mode & ~ x_all)
|
|
|
|
|
|
|
|
from shutil import copy
|
|
|
|
script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/40_custom'))
|
|
|
|
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-08-10 16:18:48 +02:00
|
|
|
if info.manifest.virtualization == 'virtio':
|
|
|
|
modules_path = os.path.join(info.root, 'etc/initramfs-tools/modules')
|
|
|
|
with open(modules_path, 'a') as modules:
|
|
|
|
modules.write("\nvirtio_pci\nvirtio_blk\n")
|
2013-07-10 10:49:45 +02:00
|
|
|
|
2013-08-10 16:18:48 +02:00
|
|
|
from common.tools import log_check_call
|
2013-07-10 10:49:45 +02:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, 'ln', '-s', '/boot/grub/grub.cfg', '/boot/grub/menu.lst'])
|
|
|
|
|
2013-07-30 11:21:09 +02:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, 'update-initramfs', '-u'])
|
2013-08-10 23:02:44 +02:00
|
|
|
log_check_call(['grub-install',
|
|
|
|
'--boot-directory='+info.root+"/boot/",
|
|
|
|
info.bootstrap_device['partitions']['root_path']])
|
2013-08-01 11:19:20 +02:00
|
|
|
|
2013-07-30 13:03:08 +02:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub'])
|
2013-07-10 10:49:45 +02:00
|
|
|
|
|
|
|
from common.tools import sed_i
|
2013-08-10 16:18:48 +02:00
|
|
|
if info.manifest.virtualization == 'virtio':
|
|
|
|
grub_cfg = os.path.join(info.root, 'boot/grub/grub.cfg')
|
|
|
|
sed_i(grub_cfg, 'sda', 'vda')
|
|
|
|
device_map = os.path.join(info.root, 'boot/grub/device.map')
|
|
|
|
sed_i(device_map, 'sda', 'vda')
|