Compare commits

...

6 Commits

Author SHA1 Message Date
Pascal Jäger
6bc0ee806f Makefile: Ignore ubuntu initramfs uninstall fail
this stops the Makefile with an error, if it can not find
`initramfs/ubuntu/setup` (which it wont in case of a non-Ubuntu distro.)

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-01-22 20:00:46 +01:00
Luis Marsano
2b9c1d2730 update Makefile for mkinitramfs
introduce feature flag for mkinitramfs in Makefile
extend install & uninstall targets when feature flag is true
document flag in help target
2023-01-15 14:26:12 -05:00
Luis Marsano
1749789f9a define uninstall subcommand for ubuntu setup
parse options and subcommands in setup script
update readme
2023-01-15 14:26:08 -05:00
Luis Marsano
695f4b06ba add setup instructions for ubuntu initramfs 2022-12-20 20:23:43 -05:00
Luis Marsano
d5541253d3 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
2022-12-20 20:23:38 -05:00
Luis Marsano
4e4e853f2d define initramfs scripts for ubuntu
provide a hook to require overlayfs module so the file system is available
define a general script to overlay any readonly root filesystem into a non-persistent, writable filesystem
2022-12-20 12:36:42 -05:00
5 changed files with 142 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ PKGNAME ?= grub-btrfs
PREFIX ?= /usr
INITCPIO ?= false
MKINITRAMFS ?= false
SYSTEMD ?= true
OPENRC ?= false
@@ -59,6 +60,11 @@ install:
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \
fi
@# Ubuntu like distros only :
@if test "$(MKINITRAMFS)" = true; then \
echo "Installing mkinitramfs hook"; \
initramfs/ubuntu/setup install; \
fi
@install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE
@install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
@install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
@@ -80,6 +86,7 @@ uninstall:
@rm -f "$(DESTDIR)/etc/conf.d/grub-btrfsd;"
@rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"
@rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"
@initramfs/ubuntu/setup uninstall || true
@rm -f "$(MAN_DIR)/man8/grub-btrfs.8.bz2"
@rm -f "$(MAN_DIR)/man8/grub-btrfsd.8.bz2"
@# Arch Linux UNlike distros only :
@@ -108,14 +115,15 @@ help:
@echo " uninstall"
@echo " help"
@echo
@echo " parameter | type | description | defaults"
@echo " ----------+------+--------------------------------+----------------------------"
@echo " DESTDIR | path | install destination | <unset>"
@echo " PREFIX | path | system tree prefix | '/usr'"
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
@echo " INITCPIO | bool | include mkinitcpio hook | false"
@echo " SYSTEMD | bool | include unit files | true"
@echo " OPENRC | bool | include OpenRc daemon | false"
@echo " parameter | type | description | defaults"
@echo " ------------+------+--------------------------------+----------------------------"
@echo " DESTDIR | path | install destination | <unset>"
@echo " PREFIX | path | system tree prefix | '/usr'"
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
@echo " INITCPIO | bool | include mkinitcpio hook | false"
@echo " MKINITRAMFS | bool | include mkinitramfs hook | false"
@echo " SYSTEMD | bool | include unit files | true"
@echo " OPENRC | bool | include OpenRc daemon | false"
@echo

View File

@@ -39,6 +39,13 @@ You notice that the name of the `hook` must match the name of the 2 installed fi
Re-generate your initramfs
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
#### Ubuntu
Install initramfs scripts & re-generate initramfs.
``` shell
sudo initramfs/ubuntu/setup install
```
#### Other distribution
Refer to your distribution's documentation
or contribute to this project to add a paragraph.

View File

@@ -0,0 +1,15 @@
#!/bin/sh -e
PREREQ=
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
manual_add_modules overlay
copy_exec /usr/bin/findmnt /usr/bin

View File

@@ -0,0 +1,32 @@
#!/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

70
initramfs/ubuntu/setup Executable file
View File

@@ -0,0 +1,70 @@
#!/usr/bin/env bash
log() {
local CODE=$?
echo >&2 "$*"
return $CODE
}
print-help() {
log "\
usage: ${0##*/} [-h] [--] (install|uninstall)
Install initramfs scripts for Ubuntu.
# Options
-h display this help & exit
# Subcommands
install install initramfs scripts
uninstall remove initramfs scripts"
}
usage-error() {
print-help
exit 2
}
action-install() {
local SCRIPT_DIR="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd)"
install {"$SCRIPT_DIR",/etc/initramfs-tools}/hooks/grub-btrfs-overlay
install {"$SCRIPT_DIR",/etc/initramfs-tools}/scripts/local-bottom/grub-btrfs-overlay
}
action-uninstall() {
rm -f /etc/initramfs-tools/{hooks,scripts/local-bottom}/grub-btrfs-overlay
}
set -e
while getopts h OPT
do case "$OPT" in
h)
print-help
exit
;;
*)
usage-error
esac done
shift $(( OPTIND - 1 ))
OPTIND=1
ACTION=
case "$#" in
0)
log event: a subcommand is required
usage-error
;;
1)
case "$1" in
install|uninstall)
ACTION="action-$1"
;;
*)
log "\
event: unknown subcommand
subcommand: $1"
usage-error
esac
;;
*)
log "\
event: too many arguments
arguments: $*"
usage-error
esac
"$ACTION" || log "\
event: execution failure
suggestion: rerun with sudo"
exec update-initramfs -u