diff --git a/debian/changelog b/debian/changelog index 9eb29b1..312af00 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nuts (1.0.8) nitrux; urgency=medium + + * Add check to not use kexec after upgrading when Nvidia hardware is detected. + + -- Uri Herrera Fri, 18 Aug 2023 00:34:00 -0500 + nuts (1.0.7) nitrux; urgency=medium * Correct syntax for case statements. diff --git a/usr/bin/nuts-crr b/usr/bin/nuts-crr index 26f165c..24b3b8f 100755 --- a/usr/bin/nuts-crr +++ b/usr/bin/nuts-crr @@ -120,6 +120,17 @@ dl_file() { fi } +unmount_directory() { + local DIRECTORY="$1" + + if mountpoint -q "$DIRECTORY"; then + echo "Unmounting: $DIRECTORY" + umount "$DIRECTORY" + else + echo "Directory is not mounted: $DIRECTORY" + fi +} + # -- Mount the devices filesystem. # -- Check if /dev is already mounted. @@ -277,20 +288,7 @@ rm -f /tmp/nuts-ccr update-grub >"$OUTPUT_FILE" 2>&1 -# -- Unmount the SquashFS. -# -- Unmount the devices filesystem. -# -- Unmount the /home partition. - -unmount_directory() { - local DIRECTORY="$1" - - if mountpoint -q "$DIRECTORY"; then - echo "Unmounting: $DIRECTORY" - umount "$DIRECTORY" - else - echo "Directory is not mounted: $DIRECTORY" - fi -} +# -- Unmount all the stuff. unmount_directory "$NUTS_DIR_SQS" >"$OUTPUT_FILE" unmount_directory "/home" >"$OUTPUT_FILE" diff --git a/usr/bin/nuts-cru b/usr/bin/nuts-cru index 6793533..3777841 100755 --- a/usr/bin/nuts-cru +++ b/usr/bin/nuts-cru @@ -70,6 +70,15 @@ print_message() { } +# -- Print warning messages to stderr. + +puts_warning() { + if [ -n "$1" ]; then + printf "%s: \e[33mWarning:\e[0m %s\n" "$TOOL_NAME" "$*" >&2 + fi +} + + # -- Define the path of the nuts configuration file. CONFIG_FILE="/etc/nuts.conf" @@ -134,6 +143,20 @@ bak_cc() { find "$NUTS_DIR_BAK" -maxdepth 1 -type f | sort -r | tail -n +$((BACKUPS_TO_KEEP + 1)) | xargs --no-run-if-empty rm } +get_gpu_manufacturer() { + nvidia-smi -L | awk -F ' ' '$3=="NVIDIA"{print $3; exit}' +} + +unmount_directory() { + local DIRECTORY="$1" + + if mountpoint -q "$DIRECTORY"; then + echo "Unmounting: $DIRECTORY" + umount "$DIRECTORY" + else + echo "Directory is not mounted: $DIRECTORY" + fi +} # -- Mount the devices filesystem. # -- Check if /dev is already mounted. @@ -360,12 +383,26 @@ update-grub >"$OUTPUT_FILE" 2>&1 # -- Use kexec to load the new kernel without rebooting the computer. # -- Check if kexec exists and continue if not. -if command -v kexec >"$OUTPUT_FILE"; then - KERNEL_PARAMETERS=$(tail -n 1 /proc/cmdline) - kexec -l --initrd="$KEXEC_INITRD" --append="@${KERNEL_PARAMETERS}" "$KEXEC_VMLINUZ" - kexec -e +if [ "$(get_gpu_manufacturer)" == "NVIDIA" ]; then + puts_warning "Nvidia GPU detected. Cannot use kexec; the kernel cannot be replaced live. Reboot to load the new kernel." else - puts_error "Can't find kexec; the kernel cannot be replaced live. Reboot to load the new kernel." + if command -v kexec >"$OUTPUT_FILE"; then + KERNEL_PARAMETERS=$(tail -n 1 /proc/cmdline) + kexec -l --initrd="$KEXEC_INITRD" --append="@${KERNEL_PARAMETERS}" "$KEXEC_VMLINUZ" + + # -- Unmount stuff before doing switching the kernel. + + unmount_directory "$NUTS_DIR_SQS" + unmount_directory "$NUTS_DIR_ISO" + unmount_directory "/home" + unmount_directory "/dev" + + sync + + kexec -e + else + puts_error "Can't find kexec; the kernel cannot be replaced live. Reboot to load the new kernel." + fi fi @@ -373,17 +410,6 @@ fi # -- Unmount the devices filesystem. # -- Unmount the /home partition. -unmount_directory() { - local DIRECTORY="$1" - - if mountpoint -q "$DIRECTORY"; then - echo "Unmounting: $DIRECTORY" - umount "$DIRECTORY" - else - echo "Directory is not mounted: $DIRECTORY" - fi -} - unmount_directory "$NUTS_DIR_SQS" >"$OUTPUT_FILE" unmount_directory "$NUTS_DIR_ISO" >"$OUTPUT_FILE" unmount_directory "/home" >"$OUTPUT_FILE"