init (1980B)
- #!/bin/sh
- # Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
- # SPDX-License-Identifier: ISC
- export PATH=/bin:/sbin:/usr/bin:/usr/sbin
- export init=/sbin/init newroot=/newroot root=zroot/ROOT/gentoo sh=/bin/sh level=3\ -a dev_hotplug=mdev
- rescueshell() {
- export PS1='rsh:$(tty | cut -c6-):$PWD # '
- if command -v setsid >/dev/null; then
- # shellcheck disable=SC2094
- setsid "$sh" -i -0<"$console" 1>"$console" 2>&1
- else
- # shellcheck disable=SC2094
- "$sh" -i 0<"$console" 1>"$console" 2>&1
- fi
- }
- die() {
- echo "Dropping into a rescueshell..."
- rescueshell || exec $sh -i
- }
- getdev() {
- blkid | grep "$1" | cut -d: -f1
- }
- set -v
- /bin/busybox --install /usr/bin
- umask 0077
- mount -t proc proc /proc
- mount -t sysfs sysfs /sys
- if grep -q devtmpfs /proc/filesystems; then
- mount -t devtmpfs devtmpfs /dev
- else
- mount -t tmpfs tmpfs /dev
- fi
- # shellcheck disable=SC2013
- for arg in $(cat /proc/cmdline); do
- case $arg in
- rescue*)
- export rescue=1
- ;;
- single)
- export level=2
- ;;
- level*|init*|root*|crypt_root*|sh*|dev_hotplug*)
- # shellcheck disable=SC2163
- export "$arg"
- ;;
- esac
- done
- root="${root/#ZFS=}"
- "$dev_hotplug" -s || die
- command -v "$dev_hotplug" > /proc/sys/kernel/hotplug
- [ -h /dev/fd ] || ln -fs /proc/self/fd /dev/fd
- [ -h /dev/stderr ] || ln -fs /proc/self/stderr /dev/stderr
- [ -h /dev/stdin ] || ln -fs /proc/self/stdin /dev/stdin
- [ -h /dev/stdout ] || ln -fs /proc/self/stdout /dev/stdout
- : "${console:=/dev/console}"
- # shellcheck disable=SC2094
- exec 0<"$console" 1>"$console" 2>&1
- #root=$(getdev $crypt_root)
- #[ $root ] || root=/dev/sda2
- #cryptsetup open $root root || die
- #
- #mount /dev/mapper/root $newroot || die
- modprobe zfs || die
- cryptsetup open /dev/sda2 cryptrpool || die
- zpool import -d /dev/mapper -d /dev -N rpool || die
- mount -t zfs -o rw,zfsutil "$root" "$newroot" || die
- for d in /proc /sys /dev; do umount -l "$d"; done
- exec switch_root "$newroot" "${init:-/sbin/init}" "$level" || die