2011-04-16 20:42:16 +00:00
|
|
|
# TODO
|
|
|
|
# settime
|
|
|
|
# handle rootspec
|
|
|
|
# handle rootdir
|
|
|
|
# clean rc environment before running init(8)
|
|
|
|
# kfs
|
|
|
|
# caching
|
|
|
|
|
|
|
|
rfork e
|
|
|
|
# boot methods
|
|
|
|
mlocal = (configlocal connectlocal)
|
|
|
|
mtcp = (configtcp connecttcp)
|
|
|
|
mtab = (mlocal mtcp)
|
|
|
|
config=1
|
|
|
|
connect=2
|
|
|
|
|
|
|
|
. /rc/lib/local.rc
|
|
|
|
. /rc/lib/tcp.rc
|
|
|
|
|
|
|
|
fn fatal {
|
|
|
|
echo $*
|
|
|
|
exit $"*
|
|
|
|
}
|
|
|
|
|
|
|
|
fn must {
|
|
|
|
$* || fatal $"*^': '^$status
|
|
|
|
}
|
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
fn ask {
|
|
|
|
echo -n $1
|
|
|
|
echo -n $2
|
|
|
|
if(! ~ $#3 0){
|
|
|
|
echo -n ' ['
|
|
|
|
echo -n $3
|
|
|
|
echo -n '] '
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
$1=`{read}
|
|
|
|
if(~ $#$1 0)
|
|
|
|
$1=$3
|
|
|
|
if(~ $"$1 '!rc'){
|
|
|
|
rc -i
|
|
|
|
$1=()
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $#$1 0)
|
|
|
|
ask $*
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn readmethod{
|
2011-04-18 05:58:04 +00:00
|
|
|
found=0
|
2011-04-16 20:42:16 +00:00
|
|
|
while(~ $found 0){
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $#nobootprompt 0){
|
|
|
|
echo
|
|
|
|
showlocaldevs
|
|
|
|
ask bootargs ' are? (tcp, local!device)' $"bootargs
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
if not {
|
|
|
|
bootargs=$nobootprompt
|
|
|
|
nobootprompt=()
|
|
|
|
}
|
|
|
|
method=`{echo $bootargs | awk -F! '{print $1}'}
|
|
|
|
NF=`{echo $bootargs | awk -F! '{print NF}'}
|
2011-04-16 20:42:16 +00:00
|
|
|
for(i in `{seq 1 $#mtab}){
|
|
|
|
if(~ $mtab($i) m^$method)
|
2011-04-19 05:24:46 +00:00
|
|
|
found=$i
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $found 0)
|
2011-04-16 20:42:16 +00:00
|
|
|
echo method $method not found
|
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
methodarg = `{echo $bootargs | awk -F! '{print $2}'}
|
2011-04-16 20:42:16 +00:00
|
|
|
mp = $$mtab($found)
|
|
|
|
}
|
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
fn main{
|
2011-04-19 05:24:46 +00:00
|
|
|
rm -f /srv/boot
|
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
readmethod
|
2011-04-19 05:24:46 +00:00
|
|
|
$mp($config) $methodarg
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
switch($method){
|
|
|
|
case local
|
|
|
|
islocal=1
|
|
|
|
case hybrid
|
|
|
|
ishybrid=1
|
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# authentication agent
|
2011-04-19 05:24:46 +00:00
|
|
|
if(! test -f /srv/factotum){
|
|
|
|
x=(/boot/factotum -sfactotum)
|
|
|
|
if(~ $cpuflag 1)
|
|
|
|
x=($x -kS)
|
|
|
|
if not
|
|
|
|
x=($x -u)
|
|
|
|
if(! ~ $#authaddr 0)
|
|
|
|
x=($x -a $authaddr)
|
|
|
|
if(! ~ $#debugfactotum 0)
|
|
|
|
x=($x -p)
|
|
|
|
must $x
|
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# connect to the root file system
|
2011-04-19 05:24:46 +00:00
|
|
|
$mp($connect) $methodarg
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
# mount root filesystem
|
2011-04-18 06:33:38 +00:00
|
|
|
must mount -c /srv/boot /root
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
# start pager
|
|
|
|
if(test -x /dev/swap)
|
|
|
|
echo -n start >/dev/swap
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# remove part of our temporary root
|
2011-04-19 05:24:46 +00:00
|
|
|
/mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
|
2011-04-18 05:58:04 +00:00
|
|
|
/mnt/broot/$cputype/bin/unmount /rc/bin /bin
|
|
|
|
/mnt/broot/$cputype/bin/unmount /
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# create the name space, mount the root fs
|
|
|
|
/mnt/broot/$cputype/bin/bind / /
|
|
|
|
/mnt/broot/$cputype/bin/mount -ac '#s/boot' /
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# remove the remaining temporary root
|
|
|
|
/mnt/broot/$cputype/bin/unmount /mnt/broot
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
rootdir=/root
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
if(~ $#init 0){
|
|
|
|
init=/$cputype/init
|
|
|
|
if(~ $cpuflag 1)
|
|
|
|
init=($init -c)
|
|
|
|
if not
|
|
|
|
init=($init -t)
|
|
|
|
# TODO handle mflag
|
|
|
|
}
|
|
|
|
exec $init
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 06:33:38 +00:00
|
|
|
bind -q '#p' /proc
|
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
bind -qa '#S' /dev
|
|
|
|
bind -qa '#f' /dev
|
|
|
|
bind -qa '#k' /dev
|
|
|
|
bind -qa '#æ' /dev
|
|
|
|
|
|
|
|
if(test -e '#u'){
|
|
|
|
bind -a '#u' /dev
|
|
|
|
usb/usbd
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if(! ~ $#kbmap 0){
|
|
|
|
bind -a '#κ' /dev
|
|
|
|
if(test -r $"kbmap)
|
|
|
|
cat $"kbmap >/dev/kbmap
|
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 06:33:38 +00:00
|
|
|
configlocal # add partitions and binds
|
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
while()@{
|
|
|
|
rfork n
|
|
|
|
main
|
2011-04-18 05:58:04 +00:00
|
|
|
}
|