Skip to content

Commit

Permalink
Move from bootctl to mokutil when checking for Secure Boot status (so…
Browse files Browse the repository at this point in the history
…nic-net#3486)

#### What I did
Moved to use mokutil instead of bootctl as bootctl is no longer available in Bookworm.
This affected reboot scripts, and upgrade scenario.

#### How I did it
Change calls to _bootctl status_ with _mokutil --sb-state_

#### How to verify it
After fixing the scripts to check reboot:

root@sn5600:/home/admin# soft-reboot

SECURE_UPGRADE_ENABLED=1
[[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]
load_kernel_secure
invoke_kexec -s
packet_write_wait: port 22: Broken pipe
admin@sn5600:~$ show reboot-cause
User issued 'soft-reboot' command [User: admin, Time: Tue Jul 23 11:06:43 PM UTC 2024]
  • Loading branch information
DavidZagury authored and mssonicbld committed Sep 17, 2024
1 parent e62f070 commit 2fd5f15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ if is_secureboot && grep -q aboot_machine= /host/machine.conf; then
else
# check if secure boot is enable in UEFI
CHECK_SECURE_UPGRADE_ENABLED=0
SECURE_UPGRADE_ENABLED=$(bootctl status 2>/dev/null | grep -c "Secure Boot: enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
if [[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]; then
debug "Loading kernel without secure boot"
load_kernel
Expand Down
21 changes: 18 additions & 3 deletions scripts/soft-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function clear_lingering_reboot_config()
if [[ -f ${WARM_DIR}/${REDIS_FILE} ]]; then
mv -f ${WARM_DIR}/${REDIS_FILE} ${WARM_DIR}/${REDIS_FILE}.${TIMESTAMP} || /bin/true
fi
/sbin/kexec -u || /bin/true
/sbin/kexec -u -a || /bin/true
}
SCRIPT=$0
Expand Down Expand Up @@ -147,9 +147,17 @@ function setup_reboot_variables()
fi
}
function invoke_kexec() {
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" $@
}
function load_kernel() {
# Load kernel into the memory
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
invoke_kexec -a
}
function load_kernel_secure() {
invoke_kexec -s
}
function reboot_pre_check()
Expand Down Expand Up @@ -215,7 +223,14 @@ stop_sonic_services
clear_lingering_reboot_config
load_kernel
# check if secure boot is enabled
CHECK_SECURE_UPGRADE_ENABLED=0
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
if [[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]; then
load_kernel
else
load_kernel_secure
fi
# Update the reboot cause file to reflect that user issued 'reboot' command
# Upon next boot, the contents of this file will be used to determine the
Expand Down
2 changes: 1 addition & 1 deletion sonic_installer/bootloader/grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def is_secure_upgrade_image_verification_supported(self):
if ! [ -n "$(ls -A /sys/firmware/efi/efivars 2>/dev/null)" ]; then
mount -t efivarfs none /sys/firmware/efi/efivars 2>/dev/null
fi
SECURE_UPGRADE_ENABLED=$(bootctl status 2>/dev/null | grep -c "Secure Boot: enabled")
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled")
else
echo "efi not supported - exiting without verification"
exit 1
Expand Down

0 comments on commit 2fd5f15

Please sign in to comment.