2023-04-02 11:04:23 +08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
kver=$(uname -r)
|
|
|
|
while read -r line; do
|
|
|
|
# We only care about the running kernel
|
2023-04-02 11:05:50 +08:00
|
|
|
if [[ "$line" == usr/lib/modules/$kver/vmlinuz && -d usr/lib/modules/running-kernel ]];then
|
2023-05-31 13:48:16 +08:00
|
|
|
mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} || continue
|
2023-04-02 11:04:23 +08:00
|
|
|
# Mounting read-only since the only modification here should be unmounting
|
|
|
|
# when rebooting or reinstalling the running kernel
|
2023-05-31 13:48:16 +08:00
|
|
|
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
|
2023-04-02 11:04:23 +08:00
|
|
|
fi
|
|
|
|
done
|