Skip to content

Commit c663755

Browse files
authored
Move from bootctl to mokutil when checking for Secure Boot status (sonic-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]
1 parent 5fc0ee6 commit c663755

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

scripts/fast-reboot

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ if is_secureboot && grep -q aboot_machine= /host/machine.conf; then
673673
else
674674
# check if secure boot is enable in UEFI
675675
CHECK_SECURE_UPGRADE_ENABLED=0
676-
SECURE_UPGRADE_ENABLED=$(bootctl status 2>/dev/null | grep -c "Secure Boot: enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
676+
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
677677
if [[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]; then
678678
debug "Loading kernel without secure boot"
679679
load_kernel

scripts/soft-reboot

+18-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function clear_lingering_reboot_config()
9393
if [[ -f ${WARM_DIR}/${REDIS_FILE} ]]; then
9494
mv -f ${WARM_DIR}/${REDIS_FILE} ${WARM_DIR}/${REDIS_FILE}.${TIMESTAMP} || /bin/true
9595
fi
96-
/sbin/kexec -u || /bin/true
96+
/sbin/kexec -u -a || /bin/true
9797
}
9898
9999
SCRIPT=$0
@@ -147,9 +147,17 @@ function setup_reboot_variables()
147147
fi
148148
}
149149
150+
function invoke_kexec() {
151+
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" $@
152+
}
153+
150154
function load_kernel() {
151155
# Load kernel into the memory
152-
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
156+
invoke_kexec -a
157+
}
158+
159+
function load_kernel_secure() {
160+
invoke_kexec -s
153161
}
154162
155163
function reboot_pre_check()
@@ -215,7 +223,14 @@ stop_sonic_services
215223
216224
clear_lingering_reboot_config
217225
218-
load_kernel
226+
# check if secure boot is enabled
227+
CHECK_SECURE_UPGRADE_ENABLED=0
228+
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
229+
if [[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]; then
230+
load_kernel
231+
else
232+
load_kernel_secure
233+
fi
219234
220235
# Update the reboot cause file to reflect that user issued 'reboot' command
221236
# Upon next boot, the contents of this file will be used to determine the

sonic_installer/bootloader/grub.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def is_secure_upgrade_image_verification_supported(self):
164164
if ! [ -n "$(ls -A /sys/firmware/efi/efivars 2>/dev/null)" ]; then
165165
mount -t efivarfs none /sys/firmware/efi/efivars 2>/dev/null
166166
fi
167-
SECURE_UPGRADE_ENABLED=$(bootctl status 2>/dev/null | grep -c "Secure Boot: enabled")
167+
SECURE_UPGRADE_ENABLED=$(mokutil --sb-state 2>/dev/null | grep -c "enabled")
168168
else
169169
echo "efi not supported - exiting without verification"
170170
exit 1

0 commit comments

Comments
 (0)