logo

make-initrd

Unnamed repository; edit this file 'description' to name the repository. git clone https://anongit.hacktivis.me/git/make-initrd.git/

init (1980B)


  1. #!/bin/sh
  2. # Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  3. # SPDX-License-Identifier: ISC
  4. export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  5. export init=/sbin/init newroot=/newroot root=zroot/ROOT/gentoo sh=/bin/sh level=3\ -a dev_hotplug=mdev
  6. rescueshell() {
  7. export PS1='rsh:$(tty | cut -c6-):$PWD # '
  8. if command -v setsid >/dev/null; then
  9. # shellcheck disable=SC2094
  10. setsid "$sh" -i -0<"$console" 1>"$console" 2>&1
  11. else
  12. # shellcheck disable=SC2094
  13. "$sh" -i 0<"$console" 1>"$console" 2>&1
  14. fi
  15. }
  16. die() {
  17. echo "Dropping into a rescueshell..."
  18. rescueshell || exec $sh -i
  19. }
  20. getdev() {
  21. blkid | grep "$1" | cut -d: -f1
  22. }
  23. set -v
  24. /bin/busybox --install /usr/bin
  25. umask 0077
  26. mount -t proc proc /proc
  27. mount -t sysfs sysfs /sys
  28. if grep -q devtmpfs /proc/filesystems; then
  29. mount -t devtmpfs devtmpfs /dev
  30. else
  31. mount -t tmpfs tmpfs /dev
  32. fi
  33. # shellcheck disable=SC2013
  34. for arg in $(cat /proc/cmdline); do
  35. case $arg in
  36. rescue*)
  37. export rescue=1
  38. ;;
  39. single)
  40. export level=2
  41. ;;
  42. level*|init*|root*|crypt_root*|sh*|dev_hotplug*)
  43. # shellcheck disable=SC2163
  44. export "$arg"
  45. ;;
  46. esac
  47. done
  48. root="${root/#ZFS=}"
  49. "$dev_hotplug" -s || die
  50. command -v "$dev_hotplug" > /proc/sys/kernel/hotplug
  51. [ -h /dev/fd ] || ln -fs /proc/self/fd /dev/fd
  52. [ -h /dev/stderr ] || ln -fs /proc/self/stderr /dev/stderr
  53. [ -h /dev/stdin ] || ln -fs /proc/self/stdin /dev/stdin
  54. [ -h /dev/stdout ] || ln -fs /proc/self/stdout /dev/stdout
  55. : "${console:=/dev/console}"
  56. # shellcheck disable=SC2094
  57. exec 0<"$console" 1>"$console" 2>&1
  58. #root=$(getdev $crypt_root)
  59. #[ $root ] || root=/dev/sda2
  60. #cryptsetup open $root root || die
  61. #
  62. #mount /dev/mapper/root $newroot || die
  63. modprobe zfs || die
  64. cryptsetup open /dev/sda2 cryptrpool || die
  65. zpool import -d /dev/mapper -d /dev -N rpool || die
  66. mount -t zfs -o rw,zfsutil "$root" "$newroot" || die
  67. for d in /proc /sys /dev; do umount -l "$d"; done
  68. exec switch_root "$newroot" "${init:-/sbin/init}" "$level" || die