plan9fox/sys/src/9/boot/bootrc

212 lines
3.7 KiB
Plaintext
Raw Normal View History

2011-04-30 20:17:33 +00:00
#!/bin/rc
# mount points
mntgen -s slashn /n && chmod 666 /srv/slashn
mntgen -s slashmnt /mnt && chmod 666 /srv/slashmnt
mntgen -s mntexport /mnt/exportfs && chmod 666 /srv/mntexport
2011-06-04 05:19:29 +00:00
bind /root /mnt/broot
unmount /root
bind -q '#σ' /shr
bind -q '#d' /fd
2011-04-30 20:17:33 +00:00
bind -q '#p' /proc
for(i in ¶ P S f æ t b m)
2011-08-16 08:15:36 +00:00
bind -qa '#'^$i /dev
2011-05-09 08:32:14 +00:00
2011-08-16 08:15:36 +00:00
# bind in an ip interface
for(i in I l^(0 1 2 3))
bind -qa '#'$i /net
# usually better than 1970
2011-08-22 09:20:32 +00:00
cat '#r/rtc' >/dev/time >[2]/dev/null
# reparse variables
for(i in `{ls -Qp /env}){
switch($i){
2012-12-06 02:46:22 +00:00
case '*'* 'fn#'* e820 apm0 apid ifs path pid prompt status ?
# ignore these
case *
$i=`{echo $$i}
}
2011-04-30 20:17:33 +00:00
}
fn sigint {
status=interrupted
}
fn fatal {
echo $* >[1=2]
exit $"*
}
fn must {
$* || fatal $"*^': '^$status
}
2011-04-19 05:24:46 +00:00
fn ask {
echo -n $1
echo -n $2
2011-04-23 18:22:24 +00:00
if(! ~ $#3 0){
echo -n '['
2011-04-19 05:24:46 +00:00
echo -n $3
echo -n '] '
}
$1=`{dd -bs 64 -count 1 >[2]/dev/null}
2011-04-19 05:24:46 +00:00
if(~ $#$1 0)
$1=$3
if(~ $"$1 '!rc'){
rc -i
$1=()
}
2011-04-19 05:24:46 +00:00
if(~ $#$1 0)
ask $*
}
2011-04-30 20:17:33 +00:00
mt=()
fn main{
mp=()
while(~ $#mp 0){
2022-06-14 08:16:57 +00:00
if(! ~ $#bootloop 0){
nobootprompt=$bootloop
# 'flatten' for the next boot
echo -n $bootloop > '#ec/bootloop'
}
2011-04-19 05:24:46 +00:00
if(~ $#nobootprompt 0){
echo
showlocaldevs
ask bootargs ' is (tcp, tls, il, local!device)' $"bootargs
2011-04-19 05:24:46 +00:00
}
2011-04-30 20:17:33 +00:00
if not bootargs=$nobootprompt
nobootprompt=()
mn=`{echo $bootargs | sed 's,!, ,'}
ma=$mn(2-)
mn=$mn(1)
2011-06-04 07:18:11 +00:00
switch(m$"mn){
case $mt
mp=m$mn
mp=$$mp
}
}
# authentication agent
if(! test -f /srv/factotum){
# we remount ip inteface after hostowner is set
unmount '#I' /net >[2]/dev/null
x=(/boot/factotum -n -sfactotum)
if(~ $service cpu)
x=($x -S)
if not
x=($x -u)
if(! ~ $#debugfactotum 0)
x=($x -p)
must $x
bind -qa '#I' /net
}
# config method
$mp(1) $ma
# load keys from secstore if $auth or $secstore is not empty
x=secstore
if(~ $#$x 0) x=auth
if(! ~ $#$x 0 && test -x /bin/auth/secstore && test -f /mnt/factotum/ctl){
x=(auth/secstore -G factotum -s^$$x)
if(~ $service cpu)
$x -n >/mnt/factotum/ctl
if(~ $status *readnvram* || ! ~ $service cpu)
$x >/mnt/factotum/ctl
2011-04-19 05:24:46 +00:00
}
# connect method
$mp(2) $ma
2011-06-15 12:50:29 +00:00
# insert cfs in the pipeline
if(test -x /bin/cfs){
if(~ $#bootdisk 1 && ~ $#cfs 0)
cfs=$bootdisk/cache
if(~ $#cfs 1 && ! ~ $cfs off && test -f $cfs){
{/bin/cfs -s -f $cfs </srv/boot &} | echo 0 >/srv/cfs
2011-06-15 12:50:29 +00:00
rm /srv/boot
mv /srv/cfs /srv/boot
}
}
2011-04-30 20:17:33 +00:00
# mount and change root in new enviroment and namespace
rfork ne
2011-04-30 20:17:33 +00:00
# mount root filesystem
if(~ $#rootdir 0)
rootdir=/root
must mount -c '#s/boot' /root $rootspec
# compile init command
if(~ $#init 0){
init=/$cputype/init
2011-06-16 15:35:07 +00:00
if(~ $service cpu)
init=($init -c)
if not
init=($init -t)
}
# remove enviroment variables
2014-12-10 02:16:36 +00:00
rm -f '#e/'^$mt '#e/'? '#e/'?? '#e/fn#'*
# remove part of our temporary root
2011-04-19 05:24:46 +00:00
/mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
/mnt/broot/$cputype/bin/unmount /rc/bin /bin
/mnt/broot/$cputype/bin/unmount /
# create the name space, mount the root fs
/mnt/broot/$cputype/bin/bind / /
/mnt/broot/$cputype/bin/bind -ac $rootdir /
# remove the remaining temporary root
/mnt/broot/$cputype/bin/unmount /mnt/broot
exec $init
}
2011-08-16 08:15:36 +00:00
# keyboard and serial console
if(test -x /bin/aux/kbdfs){
2011-05-13 08:53:43 +00:00
a=$console(1)
if(! ~ $#a 0)
a=/dev/eia^$a
2011-09-02 13:16:10 +00:00
aux/kbdfs -q -s cons $a
if(! ~$#kbmap 0){
if(test -f /sys/lib/kbmap/$kbmap){
echo 'setting kbmap to' $kbmap
cat /sys/lib/kbmap/$kbmap >/dev/kbmap
}
}
2011-04-19 05:24:46 +00:00
}
2011-08-16 08:15:36 +00:00
# usb devices
if(test -x /bin/nusbrc && ! test -e /env/nousbrc)
nusbrc
# load boot methods
fn showlocaldevs {}
fn configlocal {}
for(i in /rc/lib/*.rc){
. $i
}
2011-06-16 15:35:07 +00:00
# add partitions and binds
configlocal
2011-04-18 06:33:38 +00:00
2011-04-30 20:17:33 +00:00
while(){
@{main}
# subshell doesnt wait on interrupts
while(~ $status interrupted){wait}
2011-04-30 20:17:33 +00:00
# cleanup so it can be restarted
nobootprompt=()
rm -f /srv/^(cfs boot cs dns)
} </dev/cons