#!/hint/bash -euE # Copyright (C) 2023 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later packages+=( # Normal runtime lvm2 # Updates arch-install-scripts pv ) pre_install+=(20:umorpha-disk:pre_install) post_install+=(20: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/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 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_module 'overlay' add_binary umorpha-mount add_runscript } help() { cat <"$arg_mountpoint/usr/lib/initcpio/hooks/umorpha-overlayfs" <<-'EOF' #!/hint/ash # 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' 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" fi } run_hook() { export mount_handler='umorpha_mount_handler' } EOF }