mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
Implemented ConfigureGrub
This commit is contained in:
parent
1a21b4d90e
commit
c187cf6c13
3 changed files with 119 additions and 1 deletions
|
@ -8,6 +8,7 @@ from tasks import filesystem
|
|||
from tasks import bootstrap
|
||||
from tasks import locale
|
||||
from tasks import apt
|
||||
from tasks import boot
|
||||
|
||||
|
||||
def initialize():
|
||||
|
@ -39,7 +40,8 @@ def tasks(tasklist, manifest):
|
|||
locale.GenerateLocale(),
|
||||
locale.SetTimezone(),
|
||||
apt.AptSources(),
|
||||
apt.AptUpgrade())
|
||||
apt.AptUpgrade(),
|
||||
boot.ConfigureGrub())
|
||||
|
||||
from common.tasks import TriggerRollback
|
||||
tasklist.add(TriggerRollback())
|
||||
|
|
81
providers/ec2/assets/grub.d/40_custom
Normal file
81
providers/ec2/assets/grub.d/40_custom
Normal file
|
@ -0,0 +1,81 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This file generates the old menu.lst configuration with grub2
|
||||
# It was copied from tomheadys github repo:
|
||||
# https://github.com/tomheady/ec2debian/blob/master/src/root/etc/grub.d/40_custom
|
||||
|
||||
prefix=/usr
|
||||
exec_prefix=${prefix}
|
||||
bindir=${exec_prefix}/bin
|
||||
libdir=${exec_prefix}/lib
|
||||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
export TEXTDOMAIN=grub
|
||||
export TEXTDOMAINDIR=${prefix}/share/locale
|
||||
|
||||
GRUB_DEVICE=/dev/xvda1
|
||||
|
||||
|
||||
cat << EOF
|
||||
default ${GRUB_DEFAULT}
|
||||
timeout ${GRUB_TIMEOUT}
|
||||
EOF
|
||||
|
||||
if ${GRUB_HIDDEN_TIMEOUT:-false}; then
|
||||
printf "hiddenmenu\n"
|
||||
fi
|
||||
|
||||
linux_entry ()
|
||||
{
|
||||
os="$1"
|
||||
version="$2"
|
||||
args="$4"
|
||||
|
||||
title="$(gettext_quoted "%s, with Linux %s")"
|
||||
|
||||
cat << EOF
|
||||
title ${version}
|
||||
root (hd0)
|
||||
kernel ${rel_dirname}/${basename} root=${GRUB_DEVICE} ro ${args}
|
||||
initrd ${rel_dirname}/${initrd}
|
||||
EOF
|
||||
}
|
||||
|
||||
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
|
||||
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
||||
done`
|
||||
prepare_boot_cache=
|
||||
|
||||
while [ "x$list" != "x" ] ; do
|
||||
linux=`version_find_latest $list`
|
||||
basename=`basename $linux`
|
||||
dirname=`dirname $linux`
|
||||
rel_dirname=`make_system_path_relative_to_its_root $dirname`
|
||||
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
|
||||
alt_version=`echo $version | sed -e "s,\.old$,,g"`
|
||||
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
|
||||
|
||||
initrd=
|
||||
for i in "initrd.img-${version}" "initrd-${version}.img" \
|
||||
"initrd-${version}" "initramfs-${version}.img" \
|
||||
"initrd.img-${alt_version}" "initrd-${alt_version}.img" \
|
||||
"initrd-${alt_version}" "initramfs-${alt_version}.img"; do
|
||||
if test -e "${dirname}/${i}" ; then
|
||||
initrd="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
initramfs=
|
||||
for i in "config-${version}" "config-${alt_version}"; do
|
||||
if test -e "${dirname}/${i}" ; then
|
||||
initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
linux_entry "${OS}" "${version}" \
|
||||
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
|
||||
|
||||
list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
|
||||
done
|
35
providers/ec2/tasks/boot.py
Normal file
35
providers/ec2/tasks/boot.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
import os.path
|
||||
|
||||
|
||||
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
|
||||
|
||||
import os
|
||||
import glob
|
||||
grub2_cfgs = glob.glob(os.path.join(info.root, 'etc/grub.d/*'))
|
||||
for cfg in grub2_cfgs:
|
||||
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)
|
||||
|
||||
from common.tools import sed_i
|
||||
grub_def = os.path.join(info.root, 'etc/default/grub')
|
||||
sed_i(grub_def, '^GRUB_TIMEOUT=[0-9]+', 'GRUB_TIMEOUT=0\nGRUB_HIDDEN_TIMEOUT=true')
|
||||
|
||||
from common.tools import log_check_call
|
||||
log_check_call(['chroot', info.root, 'update-grub'])
|
||||
log_check_call(['chroot', info.root, 'ln', '-s', '/boot/grub/grub.cfg', '/boot/grub/menu.lst'])
|
Loading…
Add table
Reference in a new issue