#!/bin/sh default=0 timeout=5 verbose=0 conf=/boot/extlinux.conf myconf=/etc/update-extlinux.conf # read in extlinux settings if [ -f "$myconf" ]; then . $myconf fi everbose() { if [ "$verbose" = "0" ]; then return fi echo $* } ewarn() { echo "WARNING:" $@ >&2 } eerror() { echo "ERROR:" $@ >&2 return 1 } everbose "Updating extlinux configuration." if [ "x$root" = "x" ]; then ewarn "Root device is not specified in $myconf." blkid_export=$(blkid -o export /dev/root) if [ -n "$blkid_export" ]; then export $blkid_export fi if [ -z "$UUID" ]; then # try parse /proc/mount for mounted / dev=$(awk '$2 == "/" {dev=$1} END {print dev}' /proc/mounts) if [ -n "$dev" ]; then blkid_export=$(blkid -o export $dev) if [ -n "$blkid_export" ]; then export "$blkid_export" fi fi fi if [ -z "$UUID" ]; then if [ -z "$dev" ]; then eerror "Failed to detect root device" exit 1 else root=$dev fi else root=UUID=$UUID fi everbose "Root device is: $root" fi everbose "Installing mboot.c32 to /boot." cp /usr/share/syslinux/mboot.c32 /boot everbose "Installing menu.c32 to /boot." cp /usr/share/syslinux/menu.c32 /boot rtimeout=$((${timeout}\*10)) syslinux_menu=menu.c32 menu_hidden= # vesa menu has been requested? if [ "$vesa_menu" = "1" ]; then syslinux_menu=vesamenu.c32 fi everbose "Installing $syslinux_menu to /boot." cp /usr/share/syslinux/vesamenu.c32 /boot echo "# Generated by update-extlinux" > $conf.new echo "DEFAULT $syslinux_menu" >> $conf.new echo "PROMPT 0" >> $conf.new echo "MENU TITLE Alpine/$(uname -s) Boot Menu" >> $conf.new if [ "$hidden" = "1" ]; then echo "MENU HIDDEN" >> $conf.new fi echo "MENU AUTOBOOT Alpine will be booted automatically in # seconds." >> $conf.new echo "TIMEOUT $rtimeout" >> $conf.new lst=0 if [ -f "/boot/xen.gz" ]; then for kernel in $(find /boot -name vmlinuz-* -type f); do tag=$(basename $kernel | cut -b9-) everbose "Found Xen hypervisor: /boot/xen.gz, kernel: $kernel" if [ -f "/boot/initramfs-$tag" ]; then everbose "Found initramfs: /boot/initramfs-$tag" initramfs="initramfs-$tag" fi echo "LABEL $lst" >> $conf.new if [ "$lst" = "$default" ]; then echo " MENU DEFAULT" >> $conf.new fi echo " MENU LABEL Xen + Linux $tag" >> $conf.new echo " KERNEL mboot.c32" >> $conf.new echo " APPEND xen.gz $xen_opts --- $(basename $kernel) root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts --- $initramfs" >> $conf.new echo "" >> $conf.new lst=$(($lst + 1)) done fi for kernel in $(find /boot -name vmlinuz-* -type f); do tag=$(basename $kernel | cut -b9-) everbose "Found kernel: $kernel" if [ -f "/boot/initramfs-$tag" ]; then everbose "Found initramfs: /boot/initramfs-$tag" initramfs="initrd=initramfs-$tag" fi label=$(grep -w -l $tag /usr/share/kernel/*/kernel.release | cut -d/ -f5) if [ -z "$label" ]; then label=$lst fi echo "LABEL $label" >> $conf.new if [ "$label" = "$default" ]; then echo " MENU DEFAULT" >> $conf.new fi echo " MENU LABEL Linux $tag" >> $conf.new echo " KERNEL $(basename $kernel)" >> $conf.new echo " APPEND $initramfs root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $conf.new echo "" >> $conf.new lst=$(($lst + 1)) done if [ -f "/boot/memtest" ]; then everbose "Found memtest86+: /boot/memtest" echo "LABEL memtest" >> $conf.new echo " MENU LABEL Memtest86+" >> $conf.new echo " KERNEL memtest" >> $conf.new echo "" >> $conf.new lst=$(($lst + 1)) fi everbose "$lst entries found." for entry in /etc/update-extlinux.d/*; do [ -f "$entry" ] && cat $entry >> $conf.new done if [ "$overwrite" = "1" ]; then # keep a backup just in case if [ -f "$conf" ]; then mv $conf $conf.old fi mv $conf.new $conf fi