From 849c7c5f29f3689a4879204c23a6e89e2e6c0d7e Mon Sep 17 00:00:00 2001 From: maximilian attems Date: Fri, 13 Oct 2006 08:52:12 +0200 Subject: - add backup handling to initramfs-tools - allow conservative settings for skipping updated initramfs. - debug output to screen - parse mbr for lilo + small fixes --- update-initramfs | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) (limited to 'update-initramfs') diff --git a/update-initramfs b/update-initramfs index 45d4631..4995553 100755 --- a/update-initramfs +++ b/update-initramfs @@ -2,10 +2,13 @@ STATEDIR=/var/lib/initramfs-tools BOOTDIR=/boot +CONF=/etc/initramfs-tools/update-initramfs.conf KPKGCONF=/etc/kernel-img.conf set -e +[ -r ${CONF} ] && . ${CONF} + usage() { if [ -n "${1}" ]; then @@ -62,6 +65,46 @@ set_initramfs() initramfs="${BOOTDIR}/initrd.img-${version}" } + +# backup initramfs while running +backup_initramfs() +{ + [ ! -r "${initramfs}" ] && return 0 + initramfs_bak="${initramfs}.dpkg-bak" + [ -r "${initramfs_bak}" ] && rm -f "${initramfs_bak}" + mv -f "${initramfs}" "${initramfs_bak}" + verbose "Keeping ${initramfs_bak}" +} + +# keep booted initramfs +backup_booted_initramfs() +{ + # chroot + [ ! -r /proc/uptime ] && rm -f "${initramfs_bak}" && return 0 + + # no backup yet + initramfs_bak="${initramfs}.dpkg-bak" + if [ ! -r "${initramfs}.bak" ]; then + mv -f ${initramfs_bak} "${initramfs}.bak" + verbose "Backup ${initramfs}.bak" + return 0 + fi + + + # keep booted initramfs + uptime_days=$(awk '{printf "%d", $1 / 3600 / 24}' /proc/uptime) + if [ -n "$uptime_days" ]; then + boot_initramfs=$(find "${initramfs_bak}" -mtime +${uptime_days}) + fi + if [ -n "${boot_initramfs}" ]; then + mv -f "${initramfs_bak}" "${initramfs}.bak" + verbose "Backup ${initramfs}.bak" + return 0 + fi + verbose "Removing current backup ${initramfs_bak}" + rm -f ${initramfs_bak} +} + generate_initramfs() { echo "update-initramfs: Generating ${initramfs}" @@ -91,11 +134,27 @@ run_lilo() fi } +# check if lilo is on mbr +mbr_check() +{ + boot=$(awk -F = '/^boot=/{ print $2}' /etc/lilo.conf) + [ -z "${boot}" ] && return 0 + [ ! -r "${boot}" ] && return 0 + dd if="${boot}" bs=512 skip=0 count=1 2> /dev/null | grep -q LILO + [ $? -eq 0 ] && run_lilo && return 0 + echo + echo "WARNING: grub and lilo installed." + echo "If you use grub as bootloader everything is fine." + echo "If you use lilo as bootloader you must run lilo!" + echo +} + # only run lilo if no grub is around # or if "do_bootloader = yes" is set run_bootloader() { - if [ -x /sbin/grub ] || [ -e /boot/grub/menu.lst ]; then + if [ -x /sbin/grub ] || [ -e /boot/grub/menu.lst ] \ + || [ -x /usr/sbin/grub ]; then if [ -e /etc/lilo.conf ] && [ -x /sbin/lilo ]; then [ -r "${KPKGCONF}" ] && \ do_b=$(awk '/bootloader/{print $3}' "${KPKGCONF}") @@ -103,13 +162,10 @@ run_bootloader() || [ "${do_b}" = "YES" ]; then run_lilo return 0 + else + mbr_check + return 0 fi - - echo - echo "WARNING: grub and lilo installed." - echo "If you use grub as bootloader everything is fine." - echo "If you use lilo as bootloader you must run lilo!" - echo fi return 0 fi @@ -228,6 +284,11 @@ create() update() { + if [ "${update_initramfs}" = "no" ]; then + echo "update-initramfs: Not updating initramfs." + exit 0 + fi + if [ -z "${version}" ]; then set_linked_version fi @@ -251,10 +312,13 @@ update() altered_check + backup_initramfs + generate_initramfs run_bootloader + backup_booted_initramfs } delete() -- cgit v1.2.3