boot.fs 4.6 KB

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