2023-10-31 07:43:40 +00:00
|
|
|
#!/hint/bash -euE
|
|
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2023-12-01 17:28:10 +00:00
|
|
|
packages+=(
|
|
|
|
# Normal runtime
|
|
|
|
lvm2
|
|
|
|
|
|
|
|
# Updates
|
|
|
|
arch-install-scripts
|
|
|
|
pv
|
|
|
|
)
|
2023-10-31 07:43:40 +00:00
|
|
|
|
2023-11-04 07:12:33 +00:00
|
|
|
pre_install+=(20:umorpha-disk:pre_install)
|
|
|
|
post_install+=(20:umorpha-disk:post_install)
|
2023-10-31 07:43:40 +00:00
|
|
|
|
|
|
|
umorpha-disk:pre_install() {
|
|
|
|
local arg_mountpoint=$1
|
|
|
|
|
|
|
|
mkdir -p "$arg_mountpoint/etc/pacman.d/hooks"
|
|
|
|
ln -sT /dev/null "$arg_mountpoint/etc/pacman.d/hooks/90-mkinitcpio-install.hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
umorpha-disk:post_install() {
|
|
|
|
local arg_mountpoint=$1
|
|
|
|
|
|
|
|
rm "$arg_mountpoint/etc/pacman.d/hooks/90-mkinitcpio-install.hook"
|
|
|
|
rmdir "$arg_mountpoint/etc/pacman.d/hooks" || true
|
2023-10-31 08:53:18 +00:00
|
|
|
|
2023-10-31 23:18:47 +00:00
|
|
|
########################################################################
|
|
|
|
|
|
|
|
cat >"$arg_mountpoint/etc/mkinitcpio.conf.d/umorpha.conf" <<'EOF'
|
|
|
|
#!/hint/bash
|
|
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
# Insert 'umorpha-overlayfs' and 'lvm2' into HOOKS.
|
|
|
|
for ((i=0; i<${#HOOKS[@]}; i++)); do
|
|
|
|
if [[ ${HOOKS[i]} == filesystems ]]; then
|
|
|
|
HOOKS=("${HOOKS[@]:0:i}" umorpha-overlayfs lvm2 "${HOOKS[@]:i}" )
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
|
2023-10-31 08:53:18 +00:00
|
|
|
cat >"$arg_mountpoint/usr/lib/initcpio/install/umorpha-overlayfs" <<-'EOF'
|
|
|
|
#!/hint/bash
|
|
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
build() {
|
2023-10-31 23:18:47 +00:00
|
|
|
add_module 'overlay'
|
2023-10-31 08:53:18 +00:00
|
|
|
|
2023-12-05 23:29:02 +00:00
|
|
|
add_binary umorpha-mount
|
2023-10-31 23:18:47 +00:00
|
|
|
add_runscript
|
2023-10-31 08:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
2023-10-31 23:18:47 +00:00
|
|
|
cat <<HELPEOF
|
2023-10-31 08:53:18 +00:00
|
|
|
This hook mounts a read-only root filesystem with a persistent
|
|
|
|
overlayfs on top of it.
|
|
|
|
|
2023-12-05 23:29:02 +00:00
|
|
|
Standard mkinitcpio boot parameters:
|
|
|
|
ro / rw default: 'ro' whether to mount the 'overlay' device
|
|
|
|
and (if if there is one) the 'boot'
|
|
|
|
device read-only or read+write
|
|
|
|
root required device of the read-only root filesystem
|
|
|
|
rootfstype default: 'auto' filesystem type of the 'root' device
|
|
|
|
rootflags default: empty mount options for the 'root' device
|
|
|
|
Additional boot parameters:
|
|
|
|
overlay required device of the persistent overlay filesystem
|
|
|
|
overlayfstype default: 'auto' filesystem type of the 'overlay' device
|
|
|
|
overlayflags default: empty mount options for the 'overlay' device
|
|
|
|
boot default: none device of the '/boot' filesystem
|
|
|
|
bootfstype default: 'auto' filesystem type of the 'boot' device
|
|
|
|
bootflags default: empty mount options for the 'boot' device
|
2023-10-31 23:18:47 +00:00
|
|
|
HELPEOF
|
2023-10-31 08:53:18 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >"$arg_mountpoint/usr/lib/initcpio/hooks/umorpha-overlayfs" <<-'EOF'
|
2023-11-09 22:42:46 +00:00
|
|
|
#!/hint/ash
|
2023-10-31 08:53:18 +00:00
|
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
# args: errmsg
|
|
|
|
umorpha_emergency_shell() {
|
2023-10-31 23:18:47 +00:00
|
|
|
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
|
|
|
|
err "$*"
|
|
|
|
echo "You are now being dropped into an emergency shell."
|
|
|
|
launch_interactive_shell
|
|
|
|
msg "Trying to continue (this will most likely fail) ..."
|
2023-10-31 08:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# args: /path/to/newroot
|
|
|
|
umorpha_mount_handler() {
|
2023-10-31 23:18:47 +00:00
|
|
|
local newroot="$1"
|
|
|
|
|
2023-12-05 23:29:02 +00:00
|
|
|
msg ":: mounting '$root'+'$overlay' on real root"
|
|
|
|
if ! umorpha-mount \
|
|
|
|
--root="$root:$rootfstype:ro${rootflags:+,$rootflags}" \
|
|
|
|
--overlay="$overlay:$overlayfstype:${rwopt:-ro}${overlayflags:+,$overlayrootflags}" \
|
|
|
|
${boot:+--boot="$boot:$bootfstype:${rwopt:-ro}${bootflags:+,$bootflags}"} \
|
|
|
|
--basedir=/run/umorpah-root \
|
|
|
|
--final-mountpoint="$newroot"
|
|
|
|
then
|
|
|
|
umorpha_emergency_shell "Failed to mount base filesystem"
|
2023-10-31 23:18:47 +00:00
|
|
|
fi
|
2023-10-31 08:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_hook() {
|
2023-10-31 23:18:47 +00:00
|
|
|
export mount_handler='umorpha_mount_handler'
|
2023-10-31 08:53:18 +00:00
|
|
|
}
|
|
|
|
EOF
|
2023-10-31 07:43:40 +00:00
|
|
|
}
|