Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/bin/rc
2
# mkusbboot - make a bootable standalone plan 9 image to copy to a usb disk.
3
#
4
# due to name clashes in /srv, will only work on a machine
5
# without a fossil named `fossil' already running.
6
 
7
rfork en
8
syscfg=/sys/lib/sysconfig
9
proto=$syscfg/proto/stand-usb
10
srcroot=/n/boot
11
quantum=1000000
12
# size of image in $quantum-byte units.  1900 is enough for production system
13
# (fs, /n/boot, ~1.2GB); 900 is ample for our install image
14
# (sources, /n/sources/plan9, ~370MB).
15
defsize=1900
16
size=()
17
 
18
fn usage {
19
	echo usage: $argv0 '[-b boot] [-p proto] [-r root] [-s 10⁶-bytes]' >[1=2]
20
	exit usage
21
}
22
 
23
fn sigint sighup sigterm {
24
	rm -f /tmp/9load
25
	exit note
26
}
27
 
28
# process arguments
29
done=0
30
argv0=$0
31
boot=/386/9loadusb
32
while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
33
	switch ($1) {
34
	case -b;	boot=$2; shift
35
	case -p;	proto=$2; shift
36
	case -r;	srcroot=$2; shift
37
	case -s;	size=$2; shift
38
	case --;	done=1			# no break in rc, alas
39
	case -*;	usage
40
	}
41
	shift
42
}
43
if (! ~ $#* 0)
44
	usage
45
 
46
# special case sources
47
if (~ $srcroot /n/*)
48
	srcfs=`{ echo $srcroot | sed 's;^/n/([^/]+).*;\1;' }
49
if (~ $srcfs sources)
50
	defsize=900
51
if (~ $#size 0)
52
	size=$defsize
53
 
54
# make empty disk image file of maximum size
55
echo -n 'image: ' >[1=2]
56
dd -ibs $quantum -obs $quantum -oseek `{hoc -e $size'-1'} -count 1 -quiet 1 \
57
	</dev/zero >image
58
 
59
# partition it
60
disk/partfs image
61
cd /dev/sdXX
62
 
63
# prep it: lay down mbr, fdisk partitions, 9 partitions
64
echo -n mbr+fdisk+prep... >[1=2]
65
disk/mbr -m /386/mbr data
66
disk/fdisk -baw data
67
disk/prep -bw -a^(9fat nvram fscfg fossil) plan9 >/dev/null
68
 
69
# populate 9fat, nvram, fsconfig
70
echo -n 9fat... >[1=2]
71
switch ($objtype) {
72
case 386
73
	# we don't normally keep gzipped kernels around,
74
	# but usb can be flakey and slow, so we'll make one.
75
	k=/tmp/9pccpuf.gz
76
	gzip -9 </$objtype/9pccpuf >$k
77
case amd64
78
	k=/$objtype/9k8cpu
79
case *
80
	echo $0: 'can''t cope with architecture' $objtype >[1=2]
81
	exit unknown-arch
82
}
83
cp $boot /tmp/9load		# force format to record the name `9load'
84
disk/format -b /386/pbslba -d -r 2 9fat /tmp/9load $k \
85
	$syscfg/usb/plan9.ini >[2=1] |
86
	grep -v '^(add .* at clust |Init|type |Adding file|used )'
87
if (~ $objtype 386)
88
	rm -f $k
89
rm -f /tmp/9load
90
cp /dev/zero nvram >[2]/dev/null
91
cp /dev/zero fscfg >[2]/dev/null
92
 
93
# fill the fossil
94
9fs $srcfs
95
echo -n load fossil... >[1=2]
96
exec loadfossil /dev/sdXX/fossil $srcroot $proto $syscfg/usb/fossil.conf