#!/bin/rc
-bind -q '#p' /proc
+mntgen -s slash /mnt
+bind /root /mnt/broot
+unmount /root
-if(test -e '#b' && ! test -e /dev/kbd){
- bind -a '#b' /dev
- aux/kbdfs -s cons
- exec /rc/bin/bootrc </dev/cons >/dev/cons >[2]/dev/cons
-}
+bind -q '#p' /proc
+for(i in S f k æ t b m)
+ bind -qa '#'^$i /dev
-bind -qa '#S' /dev
-bind -qa '#f' /dev
-bind -qa '#k' /dev
-bind -qa '#æ' /dev
+# bind in an ip interface
+for(i in I l^(0 1 2 3))
+ bind -qa '#'$i /net
-fn set {
- a=$$1
- $1=()
- rm -f '#e'/$1 '#ec'/$1 /env/$1
+# reparse #ec variables, move to #e
+for(i in init service sysname user nvram rootdir cfs bootdisk bootargs \
+ nobootprompt debugfactotum fs fsaddr auth authaddr console){
+ a=`{echo $$i}
+ $i=()
+ rm -f '#e'/$i '#ec'/$i
if(! ~ $#a 0)
- $1=$a
+ $i=$a
}
-# convert plan9.ini variables
-set init
-set user
-set nvram
-set rootdir
-set bootargs
-set nobootprompt
-set sysname
-set debugfactotum
-set fs
-set fsaddr
-set auth
-set authaddr
-
fn fatal {
echo $*
exit $"*
echo -n $3
echo -n '] '
}
- $1=`{read}
+ $1=`{dd -bs 64 -count 1 >[2]/dev/null}
if(~ $#$1 0)
$1=$3
if(~ $"$1 '!rc'){
if(~ $#nobootprompt 0){
echo
showlocaldevs
- ask bootargs ' is (tcp, local!device)' $bootargs
+ ask bootargs ' is (tcp, local!device)' $"bootargs
}
if not bootargs=$nobootprompt
+ nobootprompt=()
mn=`{echo $bootargs | awk -F! '{print $1}'}
- ma=`{echo $bootargs | sed 's/[^!]+!?//'}
- for(i in `{seq 1 $#mt}){
- if(~ $mt($i) m^$mn)
- mp=$$mt($i)
+ ma=`{echo $bootargs | sed 's/[^!]*!?//'}
+ switch(m$"mn){
+ case $mt
+ mp=m$mn
+ mp=$$mp
}
}
# authentication agent
if(! test -f /srv/factotum){
x=(/boot/factotum -sfactotum)
- if(~ $cpuflag 1)
+ if(~ $service cpu){
x=($x -S)
+ if(~ -k $ff)
+ x=($x -k)
+ }
if not
x=($x -u)
if(! ~ $#authaddr 0)
# connect method
$mp(2) $ma
+ # 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){
+ x=(/bin/cfs -s -f $cfs)
+ if(~ -f $ff)
+ x=($x -r)
+ {$x </srv/boot &} | echo 0 >/srv/cfs
+ rm /srv/boot
+ mv /srv/cfs /srv/boot
+ }
+ }
+
# mount and change root in new enviroment and namespace
rfork ne
rootdir=/root
must mount -c /srv/boot $rootdir
+ # compile init command
+ if(~ $#init 0){
+ init=/$cputype/init
+ if(~ $service cpu)
+ init=($init -c)
+ if not
+ init=($init -t)
+ if(~ -m $ff)
+ init=($init -m)
+ }
+
# remove enviroment variables
rm -f /env/^$mt /env/? /env/?? '/env/fn#'*
# remove the remaining temporary root
/mnt/broot/$cputype/bin/unmount /mnt/broot
- if(~ $#init 0){
- init=/$cputype/init
- if(~ $cpuflag 1)
- init=($init -c)
- if not
- init=($init -t)
- }
exec $init
}
-if(test -e '#u'){
- bind -a '#u' /dev
- usb/usbd
+# keyboard and serial console
+if(test -x /bin/aux/kbdfs){
+ a=$console(1)
+ if(! ~ $#a 0)
+ a=/dev/eia^$a
+ aux/kbdfs -s cons $a
}
-if(! ~ $#kbmap 0){
- bind -a '#κ' /dev
- if(test -r $"kbmap)
- cat $"kbmap >/dev/kbmap
+# usb devices
+nusbrc
+
+# add partitions and binds
+configlocal
+
+# boot(8) command line arguments
+ff=()
+aa=()
+while(! ~ $#* 0){
+ if(~ $1 -*){
+ if(~ $1 -u*){
+ if(~ $1 -u){
+ user=$2
+ shift
+ }
+ if not {
+ user=`{echo $1 | sed 's,^-u,,g'}
+ }
+ }
+ if not {
+ if(~ $1 -*f*)
+ ff=($ff -f)
+ if(~ $1 -*k*)
+ ff=($ff -k)
+ if(~ $1 -*m*)
+ ff=($ff -m)
+ }
+ shift
+ }
+ if not {
+ while(! ~ $#* 0){
+ aa=($aa $1)
+ shift
+ }
+ }
+}
+if(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){
+ bootargs=$aa
+ nobootprompt=$aa
}
-
-# bind in an ip interface
-for(i in I l`{seq 0 3})
- bind -qa '#'$i /net
-
-configlocal # add partitions and binds
while(){
@{main}
- sleep 1
# cleanup so it can be restarted
nobootprompt=()
user=()
- rm -f /srv/boot /srv/slashn /srv/cs /srv/dns
-}
+ rm -f /srv/^(cfs boot slashn cs dns)
+} </dev/cons >/dev/cons >[2]/dev/cons