From: Valentin Vidic Date: Mon, 13 Jun 2011 13:23:05 +0000 (+0200) Subject: Update default kernel detection. X-Git-Tag: debian/6.0.0~27 X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=commitdiff_plain;h=33da5f865daf104ca29d21bb1780d490ac6ea023;p=carnet-upgrade.git Update default kernel detection. --- diff --git a/src/functions.sh b/src/functions.sh index 5683139..bdb78e9 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -536,23 +536,35 @@ check_reboot () { reboot_required () { local default_kernel kernel_package running_release running_version - # try to get default kernel from lilo - if type lilo >/dev/null 2>&1; then - default_kernel=$( lilo -t -v 2>/dev/null \ - | grep -B3 '[*]$' \ - | sed -n -e '/^Boot image: / { s///p; q; }' ) + # try to get default kernel from grub2 + if [ -z "$default_kernel" -a -r "/boot/grub/grub.cfg" ]; then + default_kernel=$( awk ' + $0 ~ /^set default=".*"/ { + def = gensub(/default="(.*)"/, "\\1", "1", $2); + if (def !~ /^[0-9]+$/) { exit } + } + $1 == "menuentry" { menuentry+=1 } + $1 == "linux" && menuentry==def+1 { print $2; exit }' \ + /boot/grub/grub.cfg 2>/dev/null ) fi - # fallback to grub if lilo not installed + # try to get default kernel from grub-legacy if [ -z "$default_kernel" -a -r "/boot/grub/menu.lst" ]; then default_kernel=$( awk ' - $1 == "default" { default = $2; - if (default !~ /^[0-9]+$/) { exit } } + $1 == "default" { def = $2; + if (def !~ /^[0-9]+$/) { exit } } $1 == "title" { title+=1 } - $1 == "kernel" && title==default+1 { print $2; exit }' \ + $1 == "kernel" && title==def+1 { print $2; exit }' \ /boot/grub/menu.lst 2>/dev/null ) fi + # try to get default kernel from lilo + if [ -z "$default_kernel" ] && type lilo >/dev/null 2>&1; then + default_kernel=$( lilo -t -v 2>/dev/null \ + | grep -B3 '[*]$' \ + | sed -n -e '/^Boot image: / { s///p; q; }' ) + fi + if [ -z "$default_kernel" ]; then log "Could not find default kernel" return 1 @@ -561,8 +573,12 @@ reboot_required () { log "Default kernel image: $default_kernel" if [ ! -e "$default_kernel" ]; then - log "Default kernel image doesn't exist!?" - return 1 + # /boot prefix might be missing + default_kernel="/boot/$default_kernel" + if [ ! -e "$default_kernel" ]; then + log "Default kernel image doesn't exist!?" + return 1 + fi fi kernel_package=$( dpkg -S $default_kernel | cut -d: -f 1 )