115 lines
3.3 KiB
Bash
115 lines
3.3 KiB
Bash
#!/hint/bash -euE
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
packages+=(
|
|
# Functionality
|
|
sudo
|
|
|
|
# Experience
|
|
less
|
|
bash-completion
|
|
rxvt-unicode-terminfo
|
|
)
|
|
|
|
pre_install+=(10:umorpha-disk:pre_install)
|
|
post_install+=(10:umorpha-disk:post_install)
|
|
|
|
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
|
|
|
|
cat >"$arg_mountpoint/usr/share/mkinitcpio/hook.preset" <<-'EOF'
|
|
#!/hint/bash
|
|
# mkinitcpio preset file for the '%PKGBASE%' package
|
|
|
|
#ALL_config="/etc/mkinitcpio.conf"
|
|
ALL_kver="/boot/vmlinuz-%PKGBASE%"
|
|
ALL_microcode=(/boot/*-ucode.img)
|
|
|
|
PRESETS=('default' 'fallback')
|
|
|
|
#default_config="/etc/mkinitcpio.conf"
|
|
#default_image="/boot/initramfs-%PKGBASE%.img"
|
|
default_uki="/efi/EFI/Linux/parabola-%PKGBASE%.efi"
|
|
#default_options="--splash /usr/share/systemd/bootctl/splash-parabola.bmp"
|
|
|
|
#fallback_config="/etc/mkinitcpio.conf"
|
|
#fallback_image="/boot/initramfs-%PKGBASE%-fallback.img"
|
|
fallback_uki="/efi/EFI/Linux/parabola-%PKGBASE%-fallback.efi"
|
|
fallback_options="-S autodetect"
|
|
EOF
|
|
|
|
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() {
|
|
add_modlule 'overlay'
|
|
|
|
add_runscript
|
|
}
|
|
|
|
help() {
|
|
cat <<HELPEOF
|
|
This hook mounts a read-only root filesystem with a persistent
|
|
overlayfs on top of it.
|
|
|
|
Boot parameters:
|
|
- overlay_root
|
|
- overlay_rootfstype
|
|
- overlay_rootflags
|
|
HELPEOF
|
|
}
|
|
EOF
|
|
|
|
cat >"$arg_mountpoint/usr/lib/initcpio/hooks/umorpha-overlayfs" <<-'EOF'
|
|
#!/hint/bash
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# args: errmsg
|
|
umorpha_emergency_shell() {
|
|
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) ..."
|
|
}
|
|
|
|
# args: /path/to/newroot
|
|
umorpha_mount_handler() {
|
|
local newroot="$1"
|
|
|
|
msg ":: mounting '$root'+'$overlay_root' on real root"
|
|
mkdir -p /run/umorpha-root/root /run/umorpha-root/overlay
|
|
local mnt_root=/run/umorpha-root/root
|
|
local mnt_overlay=/run/umorpha-root/overlay
|
|
if ! mount -t "${rootfstype:-auto}" -o "ro${rootflags:+,$rootflags}" "$root" "$mnt_root"; then
|
|
umorpha_emergency_shell "Failed to mount root '$root'"
|
|
fi
|
|
if ! mount -t "${overlay_rootfstype:-auto}" -o "${rwopt:-ro}${overlay_rootflags:+,$overlayrootflags}" "$overlay_root" "$mnt_overlay"; then
|
|
umorpha_emergency_shell "Failed to mount overlay root '$overlay_root'"
|
|
fi
|
|
mkdir -p -- "$mnt_overlay/upperdir" "$mnt_overlay/workdir"
|
|
if ! mount -t overlay -o "lowerdir=${mnt_root},upperdir=${mnt_overlay}/upperdir,workdir=${mnt_overlay}/workdir" umorpha-rootfs "$newroot"; then
|
|
umorpha_emergency_shell "Failed to mount overlayfs lowerdir='${mnt_root}' overlaydir='${mnt_overlay}'"
|
|
fi
|
|
}
|
|
|
|
run_hook() {
|
|
export mount_handler='umorpha_mount_handler'
|
|
}
|
|
EOF
|
|
}
|