xref: /plan9-contrib/sys/lib/dist/pc/inst/bootsetup (revision dde9ca9f41802c2bb76896698b395a8424814328)
1#!/bin/rc
2
3# desc: create a boot floppy or configure hard disk to boot plan 9
4# prereq: copydist
5
6switch($1) {
7case go
8	echo
9	echo 'Initializing Plan 9 FAT configuration partition (9fat)'
10	echo
11
12	fat=(/dev/sd*/9fat)
13	fat=$fat(1)
14	disk=`{echo $fat | sed 's:/dev/::;s:/9fat::'}
15	bootfs=`{echo $fs | sed 's:/dev/(sd..)/(.*):\1!\2:'}
16	bootfat=`{echo $fs | sed 's:/dev/(sd..)/(.*):\1!9fat:'}
17	if(! test -f /dev/$disk/9fat) {
18		echo 'You have no 9fat partition.  Can''t setup booting.'
19		exit
20	}
21
22	if(! test -f /tmp/plan9.ini) {
23		{
24			sfs=`{echo $fs | sed 's;/dev;#S;'}
25			if(~ $fstype fossil fossil+venti){
26				echo bootfile'='$bootfat!9pcf
27				echo 'bootargs=local!'^$sfs
28				echo 'bootdisk=local!'^$sfs
29			}
30			if not {
31				echo bootfile'='$bootfs!/386/9pcdisk
32				echo 'bootdisk=local!'^$sfs
33			}
34			if(~ $fstype fossil+venti){
35				venti=`{echo $ventiarena | sed 's;/dev;#S;'}
36				echo venti'='^$venti
37			}
38			grep -v '(^\[)|menuitem|adisk|bootfile|bootdisk|bootargs|nobootprompt|mouseport|vgasize|monitor|cdboot' /tmp/plan9.orig
39			echo 'mouseport='^$mouseport
40			echo 'monitor='^$monitor
41			echo 'vgasize='^$vgasize
42		} >/tmp/plan9.ini
43	}
44	if(! test -f /tmp/plan9ini.bak)
45		cp /tmp/plan9.ini /tmp/plan9ini.bak
46
47	need9fatformat=no
48	if(! isfat /dev/$disk/9fat)
49		need9fatformat=yes
50	if not if(! mount -c /srv/dos /n/9fat /dev/$disk/9fat >[2]/dev/null)
51		need9fatformat=yes
52	if not if(! test -f /n/9fat/plan9.ini)
53		need9fatformat=yes
54
55	if(~ $need9fatformat yes){
56		log Initializing Plan 9 FAT partition.
57		disk/format -r 2 -d -b /386/pbs \
58			/dev/$disk/9fat /n/newfs/386/9load
59		# silently install pbslba if the partition is way into the disk.
60		# it''s our only hope.  only need this for >8.5GB into the disk.
61		# but...
62		# there are so few non-LBA bioses out
63		# there anymore that we'll do this even if we're only 2GB into
64		# the disk.  it's just not worth the headaches of dealing with
65		# crappy bioses that don't address the whole 8.5GB properly
66
67		9fatoffset=`{grep '^part 9fat ' /dev/$disk/ctl | awk '{print $4}'}
68		if(! ~ $#9fatoffset 1) {
69			echo 'could not find plan 9 partition.'
70			echo 'cannot happen'
71			exit bad
72		}
73		if(test $9fatoffset -gt 2097152)	# 2GB
74			disk/format -b /386/pbslba /dev/$disk/9fat
75
76		mount -c /srv/dos /n/9fat /dev/$disk/9fat
77	}
78
79	if(! test -f /n/9fat/4e){
80		logprog cp /n/newfs/386/9load /n/9fat/9load
81		logprog cp /n/newfs/386/9pcf /n/9fat/9pcf
82		if(test -f /n/9fat/plan9.ini && ! test -f /n/9fat/plan9-3e.ini)
83			logprog mv /n/9fat/plan9.ini /n/9fat/plan9-3e.ini
84		if(test -f /n/9fat/9pcdisk && ! test -f /n/9fat/9pc3e)
85			logprog mv /n/9fat/9pcdisk /n/9fat/9pc3e
86
87		awk -f /bin/inst/mkini.awk >/n/9fat/plan9.ini
88		>/n/9fat/4e
89	}
90
91	echo
92	echo 'There are myriad ways to boot a Plan 9 system.'
93	echo 'You can use any of the following.'
94	echo
95	echo '  floppy - create a boot floppy'
96	echo '  plan9  - make the plan 9 disk partition the default for booting'
97	echo '  win9x  - add a plan 9 option to windows 9x boot menu'
98	echo '  winnt  - add a plan 9 option to windows nt/2000/xp boot manager'
99	echo
100	echo 'If you are upgrading an extant third edition installation and booting'
101	echo 'from something other than a floppy, you needn''t run anything here.'
102	echo 'Just type ctl-d.'
103
104	oldbootsetup=$didbootsetup
105	didbootsetup=1
106	export didbootsetup
107	prompt 'Enable boot method' floppy plan9 win9x winnt
108
109	if(! boot$rd){
110		didbootsetup=$oldbootsetup
111		export didbootsetup
112	}
113
114case checkdone
115	xxxfat=(/dev/sd*/9fat)
116	if(! isfat $xxxfat(1) || ! ~ $didbootsetup 1){
117		bootsetup=ready
118		export bootsetup
119	}
120}
121