]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/boot.fs
fix kernel: pio()/mfreeseg() race
[plan9front.git] / sys / src / 9 / pc / boot.fs
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
19 cd /boot
20 echo -n boot...
21 if (! test -e /env/vmpc)
22         vmpc=23                 # % of free memory for venti
23 cp '#r/rtc' '#c/time'
24 bind -a '#I0' /net
25 bind -a '#l0' /net
26 bind -a '#¤' /dev
27 bind -a '#S' /dev
28 bind -a '#k' /dev
29 bind -a '#æ' /dev
30 bind -a '#u' /dev
31 bind '#p' /proc
32 bind '#d' /fd
33 bind -c '#s' /srv
34 # bind -a /boot /
35
36 # start usb for keyboard, disks, etc.
37 if (test -e /dev/usb/ctl) {
38         echo -n usb...
39         usbd
40 }
41 if 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
51 echo -n disks...
52 if(! ~ $dmaon no)
53         for (ctl in /dev/sd[C-H]?/ctl)
54                 if (test -e $ctl)
55                         echo 'dma on' >$ctl
56
57 diskparts
58
59 # set up any fs(3) partitions (HACK)
60 # don't match AoE disks, as those may be shared.
61 if (test ! -e /env/fscfg)
62         fscfg=`{ls -d /dev/sd[~e-h]?/fscfg >[2]/dev/null | sed 1q}
63 if (~ $#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.
68 if(! 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 }
76 if (test -e     /dev/fs/fossil)
77         fossil= /dev/fs/fossil
78 if not if (test -e      /dev/sd[~e-h]?/fossil)
79         fossil=         /dev/sd[~e-h]?/fossil
80 if 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
88 echo -n ip...
89 if (~ $#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 }
94 if not
95         ipconfig
96 switch (`{sed '/\.(0|255)[       ]/d' /net/ipselftab}) {
97 case 204.178.31.*
98         echo 'add 135.104.9.0 255.255.255.0 204.178.31.10' >>/net/iproute
99 }
100 ipconfig loopback /dev/null 127.1
101
102 # local hackery: add extra sr luns
103 if (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
105 if (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
107 diskparts
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
114 echo -n factotum...
115 if(~ $#auth 1){
116         echo start factotum on $auth
117         factotum -sfactotum -S -a $auth
118 }
119 if not
120         factotum -sfactotum -S
121 mount -b /srv/factotum /mnt
122
123 # if a keys partition exists, add its contents to factotum's
124 keys=`{ls -d /dev/sd*/keys >[2]/dev/null | sed 1q}
125 if (~ $#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
131 if (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
140 if (! ~ $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 }
150 if 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
154 if (! ~ $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
164 rootdir=/root
165 rootspec=main/active
166
167 # factotum is now mounted in /mnt; keep it visible.
168 # newns() needs it, among others.
169
170 # mount new root
171 if (test -e /srv/boot)
172         srv=boot
173 if not if (test -e /srv/fossil)
174         srv=fossil
175 if not if (test -e /srv/fsmain)
176         srv=fsmain
177 if not {
178         echo cannot find a root in /srv:
179         ls -l /srv
180 }
181 echo -n mount -cC /srv/$srv $rootdir...
182         mount -cC /srv/$srv $rootdir
183 bind -a $rootdir /
184
185 if (test -d $rootdir/mnt)
186         bind -ac $rootdir/mnt /mnt
187 mount -b /srv/factotum /mnt
188
189 # standard bin
190 if (! test -d /$cputype) {
191         echo /$cputype missing!
192         exec ./rc -m/boot/rcmain -i
193 }
194 bind /$cputype/bin /bin
195 bind -a /rc/bin /bin
196
197 # run cpurc
198 echo cpurc...
199 path=(/bin . /boot)
200 /$cputype/init -c
201
202 exec ./rc -m/boot/rcmain -i