-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use cp instead of rsync + systemd-tmpfiles for cleaning
This use cp with hardlinks + a bind mount for keeping the removed kernel modules accessible. Cleaning up the backup is done by systemd-tmpfiles on next boot. Cleaning up the mount is either done on shutdown implicitly, or when we reinstall the running kernel by the pre-hook script. No systemd service enabling is needed.
- Loading branch information
Showing
9 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
[Trigger] | ||
Operation = Install | ||
Operation = Upgrade | ||
Operation = Remove | ||
Type = Path | ||
Target = usr/lib/modules/*/vmlinuz | ||
|
||
[Action] | ||
Description = Restoring Linux kernel modules... | ||
When = PostTransaction | ||
Depends = coreutils | ||
Depends = rsync | ||
Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/backup/${KVER}"; then rsync -AHXal --ignore-existing "/usr/lib/modules/backup/${KVER}" /usr/lib/modules/; fi; rm -rf /usr/lib/modules/backup' | ||
Exec = /usr/share/libalpm/scripts/linux-modules-restore | ||
NeedsTarget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[Trigger] | ||
Operation = Install | ||
Operation = Upgrade | ||
Operation = Remove | ||
Type = Path | ||
Target = usr/lib/modules/*/vmlinuz | ||
|
||
[Action] | ||
Description = Saving Linux kernel modules... | ||
Description = Saving Linux kernel modules directory (hardlinks)... | ||
When = PreTransaction | ||
Depends = rsync | ||
Exec = /bin/sh -c 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/${KVER}"; then rsync -AHXal --delete-after "/usr/lib/modules/${KVER}" /usr/lib/modules/backup/; fi' | ||
Exec = /usr/share/libalpm/scripts/linux-modules-save | ||
NeedsTarget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
R! /usr/lib/modules/.old/* - - - 4w | ||
R! /usr/lib/modules/running-kernel | ||
r /usr/lib/modules/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
kver = $(uname -r) | ||
while read -r line; do | ||
# We only care about the running kernel | ||
if [[ "$line" == usr/lib/modules/$kver/vmlinuz && -d "${line/$kver/running-kernel}" ]];then | ||
mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} | ||
# Mounting read-only since the only modification here should be unmounting | ||
# when rebooting or reinstalling the running kernel | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash -e | ||
|
||
kver = $(uname -r) | ||
while read -r line; do | ||
# We only care about the running kernel | ||
if [[ "$line" == "usr/lib/modules/$kver/vmlinuz" ]];then | ||
if [[ mountpoint --nofollow --quiet ${line%vmlinuz} ]];then | ||
# Mount point is already present | ||
# This means we already ran that hook during 'remove case' | ||
# | ||
# Remove the mount so we can reinstall the kernel | ||
umount ${line%vmlinuz} | ||
elif [[ -f "$line" && ! -d "/usr/lib/modules/running-kernel/" ]];then | ||
# Kernel install is present and we do not have a copy | ||
# | ||
# This is the removal case, so we save the kernel | ||
mkdir /usr/lib/modules/running-kernel | ||
cp --archive --link /usr/lib/modules/{$kver}/{kernel,modules*} \ | ||
/usr/lib/modules/running-kernel/ | ||
fi | ||
# If we are re-removing the running kernel, (after removing + reinstalling), | ||
# we already have a backup and this hook is a no-op | ||
fi | ||
done |