From 3591f5ee9e85a761380a424ff2917d9fc9054ac9 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 31 May 2023 13:48:16 +0800 Subject: [PATCH] update: kernel-modules-hook-hardlinks: fix umount issue caused by udevd try 1 --- kernel-modules-hook-hardlinks/linux-modules-restore | 12 +++++++++++- kernel-modules-hook-hardlinks/linux-modules-save | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel-modules-hook-hardlinks/linux-modules-restore b/kernel-modules-hook-hardlinks/linux-modules-restore index 89d06c4..7fd0241 100644 --- a/kernel-modules-hook-hardlinks/linux-modules-restore +++ b/kernel-modules-hook-hardlinks/linux-modules-restore @@ -4,8 +4,18 @@ kver=$(uname -r) while read -r line; do # We only care about the running kernel if [[ "$line" == usr/lib/modules/$kver/vmlinuz && -d usr/lib/modules/running-kernel ]];then - mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} + mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} || continue # Mounting read-only since the only modification here should be unmounting # when rebooting or reinstalling the running kernel + mount_unit="usr-lib-modules-${kver//-/\\x2d}.mount" + install -Dm644 <( +cat << EOF +[Unit] +After=$mount_unit +Requires=$mount_unit +EOF + ) /run/systemd/system/systemd-udevd.service.d/kernel-modules-hook-hardlinks.conf + systemctl daemon-reload + # Required for clean umount on shutdown fi done diff --git a/kernel-modules-hook-hardlinks/linux-modules-save b/kernel-modules-hook-hardlinks/linux-modules-save index 90069dd..3cd8fde 100644 --- a/kernel-modules-hook-hardlinks/linux-modules-save +++ b/kernel-modules-hook-hardlinks/linux-modules-save @@ -9,7 +9,8 @@ while read -r line; do # This means we already ran that hook during 'remove case' # # Remove the mount so we can reinstall the kernel - umount ${line%vmlinuz} + # Fixme: systemd-udevd would likely block the umount + umount /${line%vmlinuz} elif [[ -f "$line" && ! -d "/usr/lib/modules/running-kernel/" ]];then # Kernel install is present and we do not have a copy #