mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-08-24 01:03:15 +08:00
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
33 lines
811 B
Bash
Executable File
33 lines
811 B
Bash
Executable File
#!/bin/sh -e
|
|
PREREQ=
|
|
prereqs() {
|
|
echo "$PREREQ"
|
|
}
|
|
case $1 in
|
|
prereqs)
|
|
prereqs
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
. /scripts/functions
|
|
on_err() {
|
|
log_failure_msg 'error setting up overlay'
|
|
}
|
|
trap on_err ERR
|
|
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 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"
|
|
fi
|