mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-04 13:05:00 +08:00
specialize overlay script & refactor
kernel parameters normally identify root filesystem as readonly before boot process remounts them writable, so the readonly parameter does not identify readonly filesystems the script reduces scope to btrfs for simplicity as a standard linux util, findmnt is copied & used arrange commands so executables are checked before file system queries and short-circuit evaluation skips unavailable commands for robustness, trap on error & exit events replace panic with failure logging, since panic doesn't appear to break to shell
This commit is contained in:
@@ -12,3 +12,4 @@ esac
|
||||
|
||||
. /usr/share/initramfs-tools/hook-functions
|
||||
manual_add_modules overlay
|
||||
copy_exec /usr/bin/findmnt /usr/bin
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
#!/bin/sh -e
|
||||
PREREQ=
|
||||
prereqs() {
|
||||
echo "$PREREQ"
|
||||
echo "$PREREQ"
|
||||
}
|
||||
case $1 in
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
. /scripts/functions
|
||||
on_err() {
|
||||
panic 'script error'
|
||||
log_failure_msg 'error setting up overlay'
|
||||
}
|
||||
trap on_err ERR
|
||||
if [ "$readonly" = y ]
|
||||
if [ -x /usr/bin/btrfs -a -x /usr/bin/findmnt ] &&
|
||||
[ "$(findmnt -no FSTYPE -M "$rootmnt")" = btrfs ] &&
|
||||
[ "$(btrfs property get $rootmnt ro)" != ro=false ]
|
||||
then
|
||||
log_begin_msg 'remount read-only root as read-only layer in non-persistent, writable overlay'
|
||||
lower_dir="$(mktemp -d -p /)"
|
||||
ram_dir="$(mktemp -d -p /)"
|
||||
log_begin_msg 'remount read-only subvolume as read-only layer in non-persistent, writable overlay'
|
||||
trap log_end_msg EXIT
|
||||
lower_dir="$(mktemp -dp /)"
|
||||
ram_dir="$(mktemp -dp /)"
|
||||
upper_dir="$ram_dir"/upper
|
||||
work_dir="$ram_dir"/work
|
||||
mount --move "$rootmnt" "$lower_dir"
|
||||
mount -t tmpfs cowspace "$ram_dir"
|
||||
mkdir -p "$upper_dir" "$work_dir"
|
||||
mount -t overlay -o lowerdir="$lower_dir",upperdir="$upper_dir",workdir="$work_dir" rootfs "$rootmnt"
|
||||
log_end_msg
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user