11.5Salnsn# $NetBSD: cgdroot.rc,v 1.5 2019/11/22 00:27:30 alnsn Exp $ 21.1Skhorben# 31.1Skhorben# Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> 41.1Skhorben# All rights reserved. 51.1Skhorben# 61.1Skhorben# Redistribution and use in source and binary forms, with or without 71.1Skhorben# modification, are permitted provided that the following conditions 81.1Skhorben# are met: 91.1Skhorben# 1. Redistributions of source code must retain the above copyright 101.1Skhorben# notice, this list of conditions and the following disclaimer. 111.1Skhorben# 2. Redistributions in binary form must reproduce the above copyright 121.1Skhorben# notice, this list of conditions and the following disclaimer in the 131.1Skhorben# documentation and/or other materials provided with the distribution. 141.1Skhorben# 151.1Skhorben# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161.1Skhorben# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 171.1Skhorben# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 181.1Skhorben# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 191.1Skhorben# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 201.1Skhorben# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 211.1Skhorben# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 221.1Skhorben# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 231.1Skhorben# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 241.1Skhorben# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251.1Skhorben 261.1SkhorbenPATH=/sbin:/usr/sbin:/bin:/usr/bin 271.1Skhorbenexport PATH 281.1SkhorbenTERM=wsvt25 291.1Skhorbenexport TERM 301.1SkhorbenHOME=/ 311.1Skhorbenexport HOME 321.1SkhorbenBLOCKSIZE=1k 331.1Skhorbenexport BLOCKSIZE 341.1SkhorbenEDITOR=ed 351.1Skhorbenexport EDITOR 361.1Skhorben 371.1Skhorbenumask 022 381.1Skhorben 391.5Salnsn# Mount /etc/cgd. 401.5Salnsnetc_cgd_mount= 411.4Salnsnfor dev in NAME=cgd.conf /dev/wd0a /dev/ld0a ; do 421.2Salnsn if mount -o ro $dev /etc/cgd 2>/dev/null ; then 431.5Salnsn etc_cgd_mount=$dev 441.3Salnsn break 451.2Salnsn fi 461.2Salnsndone 471.5Salnsnif [ -z "${etc_cgd_mount}" ]; then 481.1Skhorben echo "Could not mount the boot partition" 1>&2 491.1Skhorben exit 2 501.1Skhorbenfi 511.5Salnsn 521.5Salnsn# Configure cgd device(s). 531.1Skhorben/sbin/wsconsctl -d -w splash.enable=0 > /dev/null 2>&1 541.1Skhorbencgdconfig -C 551.1Skhorbenif [ $? -ne 0 ]; then 561.1Skhorben echo "Could not decrypt the encrypted volume" 1>&2 571.1Skhorben umount /etc/cgd 581.1Skhorben exit 2 591.1Skhorbenfi 601.5Salnsn 611.5Salnsn# Select candidates for a root mount. 621.5Salnsnroot_mounts= 631.5Salnsnif [ -z "${etc_cgd_mount##NAME=*}" ]; then 641.5Salnsn root_mounts="NAME=cgdroot /dev/cgd0a" 651.5Salnsnelse 661.5Salnsn root_mounts=/dev/cgd0a 671.5Salnsnfi 681.5Salnsn 691.5Salnsn# Mount the root filesystem. 701.5Salnsnmounted= 711.5Salnsnfor dev in ${root_mounts} ; do 721.5Salnsn if mount -o ro $dev /altroot 2>/dev/null ; then 731.5Salnsn mounted=$dev 741.5Salnsn break 751.5Salnsn fi 761.5Salnsndone 771.5Salnsn 781.5Salnsnif [ -z "$mounted" ]; then 791.1Skhorben echo "Could not mount the root partition" 1>&2 801.1Skhorben cgdconfig -U 811.1Skhorben umount /etc/cgd 821.1Skhorben exit 2 831.1Skhorbenfi 841.5Salnsn 851.5Salnsn# Boot into /altroot. 861.1Skhorbenumount /etc/cgd 871.1Skhorben/sbin/wsconsctl -d -w splash.enable=1 > /dev/null 2>&1 881.1Skhorbensysctl -w init.root=/altroot 89