#! /bin/bash # # Normally installed in /etc/initramfs/post-update.d/ and marked # executable. # # Move newly installed initramfs to /boot/efi and ensure corresponding # kernel is also moved. If the kernel has to be moved, also update # the EFI Boot Manager with the new kernel and prune old kernels. # # This routine is called the kernel version in argument #1 and the # name of the initramfs file in argument #2 # Obtain root fs info for boot command line source <(blkid -o export $(df / |grep -o '^/dev/[^ ]\+')) if test "${DEVNAME:0:12}" == "/dev/mapper/" ; then export RootSpec="$DEVNAME" else if test "${DEVNAME:0:5}" == "/dev/" ; then vglv="${DEVNAME:5}" vg="${vglv%%/*}" lv="${vglv#$vg}" if test -n "$lv" ; then export RootSpec="$DEVNAME" else export RootSpec="UUID=$UUID" fi else export RootSpec="UUID=$UUID" fi fi # Destinations must have a trailing slash. for DEST in /bootB/ /bootA/ do # First, copy the updated initramfs. cp "$2" "$DEST" # Construct the target kernel efi file name and check for existence export KF="${DEST}vmlinuz-$1.efi" test -f "$KF" && continue # Need to copy and register the kernel. echo "Copying $KF ..." cp "/boot/vmlinuz-$1" "$KF" # Obtain EFI boot fs info for boot partition info and file locations source <(blkid -o export $(df "$DEST" |grep -o '^/dev/[^ ]\+')) BOOT="$(sed -r -e 's/(.+[^0-9])([0-9]+)/\1:\2/' <<< "$DEVNAME")" read dummy1 MOUNTPT other <<< "$(grep "^$DEVNAME " /proc/mounts)" EFIROOT="$(echo ${DEST##$MOUNTPT} |sed 's/\//\\/g')" # Set the new boot record efibootmgr -q -c --disk "${BOOT%%:*}" --part "${BOOT##*:}" \ --label "EFI Direct $DEST $1" \ --loader "${EFIROOT}vmlinuz-$1.efi" \ -u "initrd=${EFIROOT}$(basename "$2") root=${RootSpec}" echo "Configured EFI Direct $DEST $1 as $EFIROOT on $BOOT" done