qubes-core-admin-linux/system-config/kernel-xen-efi.install
Jean-Philippe Ouellet 9b7667c3a5
Ignore EFI boot args when parsing for filename
I need to set some flags in order to boot as described here:
https://www.qubes-os.org/doc/uefi-troubleshooting/

My settings look like this:
    $ efibootmgr -v
    BootCurrent: 0000
    Boot0000* Qubes HD(...)/File(\EFI\qubes\xen.efi)p.l.a.c.e.h.o...

which causes awk to get confused and think my $EFI_DIR should be:
    /EFI/qubesp.l.a.c.e.h.o.l.d.e.r. ./.m.a.p.b.s. ./.n.o.e.x.i.t.b.o.o.t.

This causes the script to later bail:
    if [ ! -d "$EFI_DIR" ]; then
        # non-EFI system
        exit 0;
    fi

So my xen.cfg did not get new entries when installing dom0 kernel packages.
2016-11-11 16:22:23 -05:00

106 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
set -e
COMMAND="$1"
KVER="$2"
ESP_MOUNTPOINT=/boot/efi
EFI_DIR=$(efibootmgr -v 2>/dev/null | awk '
/^BootCurrent:/ { current=$2; }
/^Boot....\* / {
if ("Boot" current "*" == $1) {
sub(".*File\\(", "");
sub("\\\\xen.efi\\).*", "");
gsub("\\\\", "/");
print;
}
}')
if [ -z "$EFI_DIR" ]; then
EFI_DIR="$ESP_MOUNTPOINT/EFI/qubes"
else
EFI_DIR="$ESP_MOUNTPOINT$EFI_DIR"
fi
if [ ! -d "$EFI_DIR" ]; then
# non-EFI system
exit 0;
fi
case "$COMMAND" in
add)
if ! fgrep -q "[${KVER}]" $EFI_DIR/xen.cfg; then
# take the default section and use it as a template for the new entry
awk -F = --assign "kver=${KVER}" '
/^\[/ {
# section header - previous section (if any) ended
# if default section already processed, that is all
if (in_default) exit;
in_global=0;
in_default=0;
}
/\[global\]/ {
in_global=1;
}
/^\[/ {
if ("[" default_name "]" == $0) {
in_default=1;
print "[" kver "]";
next;
}
}
/^default=/ {
if (in_global)
default_name=$2;
}
/^kernel=/ {
if (in_default) {
sub("=[^ ]*", "=vmlinuz-" kver);
}
}
/^ramdisk=/ {
if (in_default) {
sub("=[^ ]*", "=initramfs-" kver ".img");
}
}
{
if (in_default) {
print;
}
}' $EFI_DIR/xen.cfg >> $EFI_DIR/xen.cfg
# then change the default
sed -e "s/default=.*/default=$KVER/" -i $EFI_DIR/xen.cfg
fi
cp "/boot/vmlinuz-$KVER" "$EFI_DIR/"
dracut -f "$EFI_DIR/initramfs-${KVER}.img" "$KVER"
;;
remove)
# don't care about changing default= line - yum should prevent removing
# currently running kernel
if [ -r $EFI_DIR/xen.cfg ]; then
awk -F = --assign "kver=${KVER}" '
/^\[/ {
# section header - previous section (if any) ended
in_current=0;
}
/^\[/ {
if ($0 == "[" kver "]")
in_current=1;
}
{
if (!in_current) {
print;
}
}' $EFI_DIR/xen.cfg > $EFI_DIR/xen.cfg.new
mv $EFI_DIR/xen.cfg.new $EFI_DIR/xen.cfg
fi
rm -f "$EFI_DIR/initramfs-${KVER}.img"
;;
esac