Skip to content

Instantly share code, notes, and snippets.

@Skirmisher
Created August 24, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skirmisher/1051868d46a0626ff9dd9e5c52f204cd to your computer and use it in GitHub Desktop.
Save Skirmisher/1051868d46a0626ff9dd9e5c52f204cd to your computer and use it in GitHub Desktop.
#!/bin/sh
header() {
echo "TIMEOUT ${TIMEOUT}" > ${OUTFILE}
echo "DEFAULT entry0" >> ${OUTFILE}
echo "MENU TITLE Boot menu" >> ${OUTFILE}
}
get_bootpath() {
echo ${1} | sed "s#${BOOTPART}/#/#"
}
add_kernel() {
ver=${1}
kernel=$(get_bootpath "/boot/vmlinux-${ver}")
initrd=$(get_bootpath "/boot/initramfs-${ver}.img")
fdt=$(get_bootpath "/boot/dtbs/dtbs-${ver}/${DTBPATH}")
cmdline="root=UUID=${UUID} ${CMDLINE}"
echo "LABEL entry${ENTRY}" >> ${OUTFILE}
echo "\tMENU LABEL Void GNU/Linux, with Linux ${ver}" >> ${OUTFILE}
echo "\tLINUX ${kernel}" >> ${OUTFILE}
if [ -e "${BOOTPART}/${initrd}" ]; then
echo "\tINITRD ${initrd}" >> ${OUTFILE}
fi
if [ -n "${DTBPATH}" ] && [ -e "${BOOTPART}/${fdt}" ]; then
echo "\tFDT ${fdt}" >> ${OUTFILE}
fi
if [ -n "${cmdline}" ]; then
echo "\tAPPEND ${cmdline}" >> ${OUTFILE}
fi
ENTRY=$(expr ${ENTRY} + 1)
}
main() {
if [ ! -d /boot/extlinux ]; then
mkdir -p /boot/extlinux
fi
if [ -e ${CONF} ]; then
. ${CONF}
fi
if [ -z "${CMDLINE}" ]; then
CMDLINE=$(cat /proc/cmdline)
fi
header
for kernel in $(ls /boot/vmlinu[xz]-* | sort -rV); do
ver=$(echo ${kernel} | sed "s#/boot/vmlinu[xz]-\(.*\)#\\1#")
echo "Adding kernel ${ver}"
add_kernel ${ver}
done
mv ${OUTFILE} /boot/extlinux/extlinux.conf
}
CONF=/etc/default/extlinux
OUTFILE=$(mktemp)
BOOTPART=$(df -P /boot | tail -1 | awk '{ print $6 }')
ROOTDEV=$(df -P / | tail -1 | awk '{ print $1 }')
eval $(blkid -o export ${ROOTDEV})
ENTRY=0
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment