1#!/boot/rc -m /boot/rcmain 2# boot script for file servers, including standalone ones 3path=(/boot /$cputype/bin /rc/bin .) 4fn diskparts { 5 # set up any /dev/sd partitions 6 for(disk in /dev/sd*) { 7 if(test -f $disk/data && test -f $disk/ctl) 8 fdisk -p $disk/data >$disk/ctl >[2]/dev/null 9 if(test -f $disk/plan9) 10 parts=($disk/plan9*) 11 if not 12 parts=($disk/data) 13 for(part in $parts) 14 if(test -f $part) 15 prep -p $part >$disk/ctl >[2]/dev/null 16 } 17} 18 19cd /boot 20echo -n boot... 21if (! test -e /env/vmpc) 22 vmpc=23 # % of free memory for venti 23cp '#r/rtc' '#c/time' 24bind -a '#I0' /net 25bind -a '#l0' /net 26bind -a '#¤' /dev 27bind -a '#S' /dev 28bind -a '#k' /dev 29bind -a '#æ' /dev 30bind -a '#u' /dev 31bind '#p' /proc 32bind '#d' /fd 33bind -c '#s' /srv 34# bind -a /boot / 35 36# start usb for keyboard, disks, etc. 37if (test -e /dev/usb/ctl) { 38 echo -n usb... 39 usbd 40} 41 42echo -n disks... 43if(! ~ $dmaon no) 44 for (ctl in /dev/sd[C-H]?/ctl) 45 if (test -e $ctl) 46 echo 'dma on' >$ctl 47 48diskparts 49 50# set up any fs(3) partitions (HACK) 51# don't match AoE disks, as those may be shared. 52if (test ! -e /env/fscfg) 53 fscfg=`{ls -d /dev/sd[~e-h]?/fscfg >[2]/dev/null | sed 1q} 54if (~ $#fscfg 1 && test -r $fscfg) 55 zerotrunc <$fscfg | read -m >/dev/fs/ctl 56 57# figure out which arenas and fossil partitions to use. 58# don't match AoE disks, as those may be shared. 59if(! test -e /env/arena0){ 60 if (test -e /dev/fs/arena0) 61 arena0= /dev/fs/arena0 62 if not if (test -e /dev/sd[~e-h]?/arena0) 63 arena0= /dev/sd[~e-h]?/arena0 64 if not 65 arena0=/dev/null 66} 67if (test -e /dev/fs/fossil) 68 fossil= /dev/fs/fossil 69if not if (test -e /dev/sd[~e-h]?/fossil) 70 fossil= /dev/sd[~e-h]?/fossil 71if not 72 fossil=/dev/null 73 74# 75# the local disks are now sorted out. 76# set up the network, auth, venti and fossil. 77# 78 79echo -n ip... 80if (~ $#ip 1 && ! ~ $ip '') { 81 # need to supply ip, ipmask and ipgw in plan9.ini to use this 82 ipconfig -g $ipgw ether /net/ether0 $ip $ipmask 83 echo 'add 0 0 '^$ipgw >>/net/iproute 84} 85if not 86 ipconfig 87# if outside, add explicit vfw routing to the inside 88switch (`{sed '/\.(0|255)[ ]/d' /net/ipselftab}) { 89case 135.104.24.* # new outside 90 echo 'add 135.104.9.0 255.255.255.0 135.104.24.13' >>/net/iproute 91} 92ipconfig loopback /dev/null 127.1 93 94# local hackery: add extra sr luns of shelf 1 95if (test -e /dev/aoe/1.1 && ! test -e /dev/sdf0) 96 echo config switch on spec f type aoe//dev/aoe/1.1 >/dev/sdctl 97if (test -e /dev/aoe/1.2 && ! test -e /dev/sdg0) 98 echo config switch on spec g type aoe//dev/aoe/1.2 >/dev/sdctl 99diskparts 100 101# so far we're using the default key from $nvram, usually 102# for insideout.plan9.bell-labs.com on outside machines, 103# and have mounted our root over the net, if running diskless. 104# factotum always mounts itself (on /mnt by default). 105 106echo -n factotum... 107if(~ $#auth 1){ 108 echo start factotum on $auth 109 factotum -sfactotum -S -a $auth 110} 111if not 112 factotum -sfactotum -S 113mount -b /srv/factotum /mnt 114 115# if a keys partition exists, add its contents to factotum's 116keys=`{ls -d /dev/sd*/keys >[2]/dev/null | sed 1q} 117if (~ $#keys 1 && test -r $keys) { 118 echo -n add keys... 119 zerotrunc <$keys | aescbc -n -d | read -m >/mnt/factotum/ctl 120} 121 122# get root from network if fsaddr set in plan9.ini, and bail out here 123if (test -e /env/fs) { 124 echo -n fs root... 125 if(! srv tcp!$fs!564 boot) 126 exec ./rc -m/boot/rcmain -i 127 if(! mount -c /srv/boot /root) 128 exec ./rc -m/boot/rcmain -i 129} 130 131# start venti store 132if (! ~ $arena0 /dev/null && test -r $arena0) { 133 echo -n start venti on $arena0... 134 venti=tcp!127.0.0.1!17034 135 vcfg=`{ls -d /dev/sd*/venticfg >[2]/dev/null | sed 1q} 136 if (~ $#vcfg 1 && test -r $vcfg) 137 venti -m $vmpc -c $vcfg 138 if not 139 venti -m $vmpc -c $arena0 140 sleep 10 141} 142if not if (! test -e /env/venti) 143 venti=tcp!135.104.9.33!17034 # local default 144 145# start root fossil, may serve /srv/boot 146if (! ~ $fossil /dev/null && test -r $fossil) { 147 echo -n root fossil on $fossil... 148 fossil -m 2 -f $fossil 149 sleep 3 150} 151 152# 153# normal start up on local fossil root 154# 155 156rootdir=/root 157rootspec=main/active 158 159# factotum is now mounted in /mnt; keep it visible. 160# newns() needs it, among others. 161 162# mount new root 163if (test -e /srv/boot) 164 srv=boot 165if not if (test -e /srv/fossil) 166 srv=fossil 167if not if (test -e /srv/fsmain) 168 srv=fsmain 169if not { 170 echo cannot find a root in /srv: 171 ls -l /srv 172} 173echo -n mount -cC /srv/$srv $rootdir... 174 mount -cC /srv/$srv $rootdir 175bind -a $rootdir / 176 177if (test -d $rootdir/mnt) 178 bind -ac $rootdir/mnt /mnt 179mount -b /srv/factotum /mnt 180 181# standard bin 182if (! test -d /$cputype) { 183 echo /$cputype missing! 184 exec ./rc -m/boot/rcmain -i 185} 186bind /$cputype/bin /bin 187bind -a /rc/bin /bin 188 189# run cpurc 190echo cpurc... 191path=(/bin . /boot) 192/$cputype/init -c 193 194exec ./rc -m/boot/rcmain -i 195