From 78d26166a8ad1bc8d29822d45a6a382b87fa095d Mon Sep 17 00:00:00 2001 From: Awais Belal Date: Mon, 14 Jan 2019 19:40:50 +0500 Subject: [PATCH 4/7] init-install-efi: pick kernel and rootfs from grub.env This allows for simply modifying variables to switch between different kernels and rootfs from user-space without having to modify grub configurations directly. Signed-off-by: Awais Belal --- init-install-efi.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/init-install-efi.sh b/init-install-efi.sh index 2adfe02..d69520f 100644 --- a/init-install-efi.sh +++ b/init-install-efi.sh @@ -287,6 +287,7 @@ mkdir -p $EFIDIR cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR GRUBCFG="$EFIDIR/grub.cfg" +GRUBENV="$EFIDIR/grub.env" if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs1}) cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG @@ -297,9 +298,14 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then sed -i "/initrd /d" $GRUBCFG # Delete any LABEL= strings sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG + # Mentor- SWUpdate - force grub to load our env which we'll use to specify RFS and KERNEL + sed -i "1iload_env --file ${GRUBENV#\/boot}" $GRUBCFG + # Set current and fallback rootfs using variable via our grub.env + grub-editenv $GRUBENV set "RFS=PARTUUID=$root_part_uuid" + grub-editenv $GRUBENV set "FB_RFS=PARTUUID=$root_part_uuid" # Replace root= and add additional standard boot options # We use root as a sentinel value, as vmlinuz is no longer guaranteed - sed -i "s/ root=[^ ]*/ root=PARTUUID=$root_part_uuid rw $rootwait quiet /g" $GRUBCFG + sed -i "s/ root=[^ ]*/ root=\$RFS rw $rootwait quiet /g" $GRUBCFG fi if [ -d /run/media/$1/loader ]; then @@ -321,15 +327,25 @@ fi umount /tgt_root +if [ -e "/proc/cmdline" ]; then + current_kernel=$(basename $(cat /proc/cmdline | awk '{print $1}' | cut -d"=" -f2)) +fi # Copy kernel artifacts. To add more artifacts just add to types # For now just support kernel types already being used by something in OE-core for types in bzImage zImage vmlinux vmlinuz fitImage; do # MEL - SWUpdate - copy all kernel images as A, this is our first copy for kernel in `find /run/media/$1/ -name $types*`; do kernel_name=$(basename $kernel) - cp $kernel /boot/${kernel_name}A + cp ${kernel} /boot/${kernel_name}A if [ -e $GRUBCFG ]; then - sed -i "s/\/${kernel_name} /\/${kernel_name}A /" $GRUBCFG + if [ "${kernel_name}" = "${current_kernel}" ]; then + sed -i "s/\/${kernel_name} /\/\$KERNEL /" $GRUBCFG + # Set the current and fallback kernel to current kernel's A + grub-editenv $GRUBENV set "KERNEL=${kernel_name}A" + grub-editenv $GRUBENV set "FB_KERNEL=${kernel_name}A" + else + sed -i "s/\/${kernel_name} /\/${kernel_name}A /" $GRUBCFG + fi fi done done -- 2.11.1