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