The ostree-grub-generator populates the grub.cfg menu entries using the BLS config files. But it uses the ls command that by default sorts the entries alphabetically, so the order won't be correct if there are more than 10 deployments, i.e: $ ls -1 /boot/loader/entries/ ostree-fedora-workstation-0.conf ostree-fedora-workstation-10.conf ostree-fedora-workstation-1.conf ... So instead the -v option should be used to make ls use version sorting: $ ls -1 -v /boot/loader/entries/ ostree-fedora-workstation-0.conf ostree-fedora-workstation-1.conf ... ostree-fedora-workstation-10.conf Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Closes: #1653 Approved by: cgwalters
108 lines
3.0 KiB
Bash
108 lines
3.0 KiB
Bash
#!/bin/sh
|
|
|
|
# The builtin grub.cfg generator.
|
|
#
|
|
# This script is called by ostree/src/libostree/ostree-bootloader-grub2.c whenever
|
|
# boot loader configuration file needs to be updated. It can be used as a template
|
|
# for a custom grub.cfg generator. What to consider when writing a custom grub.cfg
|
|
# generator:
|
|
#
|
|
# - The populate_menu() function converts boot loader entries as defined by
|
|
# https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ into GRUB2
|
|
# menuentry sections. This is the core logic that is required by OSTree
|
|
# based system.
|
|
#
|
|
# - Embedded systems: Be aware that this script is executed not only on a host machine by OS
|
|
# installer, but also on a target device, thus think about shell portability. A target device
|
|
# for example might be using busybox with a limited shell.
|
|
#
|
|
# Feel free to edit this script to fit your requirements.
|
|
|
|
set -e
|
|
|
|
script=$(basename ${0})
|
|
# Atomically safe location where to generete grub.cfg when executing system upgrade.
|
|
new_grub2_cfg=${2}
|
|
entries_path=$(dirname $new_grub2_cfg)/entries
|
|
|
|
read_config()
|
|
{
|
|
config_file=${1}
|
|
title=""
|
|
initrd=""
|
|
options=""
|
|
linux=""
|
|
|
|
while read -r line
|
|
do
|
|
record=$(echo ${line} | cut -f 1 -d ' ')
|
|
value=$(echo ${line} | cut -s -f2- -d ' ')
|
|
case "${record}" in
|
|
"title")
|
|
title=${value}
|
|
;;
|
|
"initrd")
|
|
initrd=${value}
|
|
;;
|
|
"linux")
|
|
linux=${value}
|
|
;;
|
|
"options")
|
|
options=${value}
|
|
;;
|
|
esac
|
|
done < ${config_file}
|
|
|
|
if [ -z "${title}" ]; then
|
|
title="(Untitled)"
|
|
fi
|
|
}
|
|
|
|
populate_menu()
|
|
{
|
|
# Default to /boot if OSTREE_BOOT_PARTITION is not set and /boot is on the same device than ostree/repo
|
|
if [ -z ${OSTREE_BOOT_PARTITION+x} ] && [ -d /boot/ostree ] && [ -d /ostree/repo ] && [ $(stat -c '%d' /boot/ostree) -eq $(stat -c '%d' /ostree/repo) ]; then
|
|
boot_prefix="/boot"
|
|
else
|
|
boot_prefix="${OSTREE_BOOT_PARTITION}"
|
|
fi
|
|
for config in $(ls -v $entries_path/*.conf); do
|
|
read_config ${config}
|
|
menu="${menu}menuentry '${title}' {\n"
|
|
menu="${menu}\t linux ${boot_prefix}${linux} ${options}\n"
|
|
if [ -n "${initrd}" ] ; then
|
|
menu="${menu}\t initrd ${boot_prefix}${initrd}\n"
|
|
fi
|
|
menu="${menu}}\n\n"
|
|
done
|
|
# The printf command seems to be more reliable across shells for special character (\n, \t) evaluation
|
|
printf "$menu" >> ${new_grub2_cfg}
|
|
}
|
|
|
|
populate_warning()
|
|
{
|
|
cat >> ${new_grub2_cfg} <<EOF
|
|
# This file was generated by ${script}. Do not modify the generated file - all changes will
|
|
# be lost the next time file is regenerated. For more details refer to the ${script} script.
|
|
EOF
|
|
}
|
|
|
|
populate_header()
|
|
{
|
|
cat >> ${new_grub2_cfg} <<EOF
|
|
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
|
|
default=boot
|
|
timeout=10
|
|
|
|
EOF
|
|
}
|
|
|
|
generate_grub2_cfg()
|
|
{
|
|
populate_warning
|
|
populate_header
|
|
populate_menu
|
|
}
|
|
|
|
generate_grub2_cfg
|