indigoparadox

ramdisk-cgdroot.fs/etc/rc

Oct 30th, 2026
333
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.46 KB | Software | 0 0
  1. #   $NetBSD: cgdroot.rc,v 1.5 2019/11/22 00:27:30 alnsn Exp $
  2. #
  3. # Copyright (c) 2013 Pierre Pronchery <[email protected]>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions and the following disclaimer in the
  13. #    documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  
  26. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  27. export PATH
  28. TERM=wsvt25
  29. export TERM
  30. HOME=/
  31. export HOME
  32. BLOCKSIZE=1k
  33. export BLOCKSIZE
  34. EDITOR=ed
  35. export EDITOR
  36.  
  37. umask 022
  38.  
  39. # Mount /etc/cgd.
  40. etc_cgd_mount=
  41. for dev in NAME=cgd.conf /dev/wd0a /dev/ld0a ; do
  42.     if mount -o ro $dev /etc/cgd 2>/dev/null ; then
  43.         etc_cgd_mount=$dev
  44.         break
  45.     fi
  46. done
  47. if [ -z "${etc_cgd_mount}" ]; then
  48.     echo "Could not mount the boot partition" 1>&2
  49.     exit 2
  50. fi
  51.  
  52. # IP Mod: Mount writable filesystem to /tmp for pidfiles, cryptroot trigger, etc.
  53. mount_mfs -s 1024 swap /tmp
  54.  
  55. # IP Mod: Configure networking.
  56. if [ -f /etc/cgd/boot_ip ]; then
  57.     /sbin/ifconfig re0 inet `cat /etc/cgd/boot_ip` up
  58. fi
  59. if [ -f /etc/cgd/boot_route ]; then
  60.     /sbin/route add default `cat /etc/cgd/boot_route`
  61. fi
  62.  
  63. # IP Mod: Start dropbear SSH server.
  64. # (Anything in /boot, the cgd.conf GPT slice, will show up in /etc/cgd in the ramdisk.)
  65. /sbin/dropbear -E -s -g -j -k -p 22022 -r /etc/cgd/dropbear_ed25519_host_key -D /etc/cgd -P /tmp/dropbear.pid -c /sbin/cryptroot-unlock
  66.  
  67. # IP Mod: Disable the main TTY prompt, only allow remote.
  68. # Configure cgd device(s).
  69. #/sbin/wsconsctl -d -w splash.enable=0 > /dev/null 2>&1
  70. #cgdconfig -C
  71. #if [ $? -ne 0 ]; then
  72. #   echo "Could not decrypt the encrypted volume" 1>&2
  73. #   umount /etc/cgd
  74. #   exit 2
  75. #fi
  76.  
  77. # IP Mod: Wait for remote unlock.
  78. echo "Waiting for remote cgd unlock..."
  79. while [ ! -f /tmp/cgd-unlocked ]; do
  80.     :
  81. done
  82.  
  83. # IP Mod: Kill dropbear.
  84. kill `cat /tmp/dropbear.pid`
  85.  
  86. # IP Mod: Unmount writable /tmp.
  87. umount /tmp
  88.  
  89. # Select candidates for a root mount.
  90. root_mounts=
  91. if [ -z "${etc_cgd_mount##NAME=*}" ]; then
  92.     root_mounts="NAME=cgdroot /dev/cgd0a"
  93. else
  94.     root_mounts=/dev/cgd0a
  95. fi
  96.  
  97. # Mount the root filesystem.
  98. mounted=
  99. for dev in ${root_mounts} ; do
  100.     if mount -o ro $dev /altroot 2>/dev/null ; then
  101.         mounted=$dev
  102.         break
  103.     fi
  104. done
  105.  
  106. if [ -z "$mounted" ]; then
  107.     echo "Could not mount the root partition" 1>&2
  108.     cgdconfig -U
  109.     umount /etc/cgd
  110.     exit 2
  111. fi
  112.  
  113. # Boot into /altroot.
  114. umount /etc/cgd
  115. /sbin/wsconsctl -d -w splash.enable=1 > /dev/null 2>&1
  116. sysctl -w init.root=/altroot
  117.  
Advertisement