blob: 10ffc32aae93a40b7bc72e050f5c64f0f2dbad62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/bin/sh
#
# mkmemstick.sh: Create memory stick image from NetBSD installation CDs
#
# Copyright (C) 2009 Jared D. McNeill <jmcneill@NetBSD.org>
src="$1"
img="$2"
dstbase="/tmp/makeimg$(id -u)"
dst="${dstbase}/rootfs"
tmpimg="${dstbase}/netbsd.img"
disklabel="
type: unknown
disk: Memory Stick
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1000
cylinders: @TCYLINDERS@
total sectors: @TSECTORS@
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0
track-to-track seek: 0
drivedata: 0
16 partitions:
a: @SECTORS@ 0 4.2BSD 1024 8192 0
d: @SECTORS@ 0 unused 0 0
"
die() {
echo "fatal: $0"
exit 2
}
if [ -z "$img" ]; then
echo "usage: $0 source.iso memdisk.img"
exit 1
fi
if [ ! -r "$src" ]; then
echo "$src not found"
exit 1
fi
if [ -d "$dst" ]; then
echo "$dst already exists"
exit 1
fi
if [ -f "$img" ]; then
echo "$img already exists"
exit 1
fi
mkdir -p "$dst" || die "couldn't create directory $dst"
printf " => extracting iso image"
isoinfo -R -f -i "$src" | while read x; do
dstdir="$dst/$(dirname $x)"
dstfile="$(basename $x)"
if [ -f "$dstdir" ]; then
rm "$dstdir"
fi
mkdir -p "$dstdir"
printf .
isoinfo -R -x "$x" -i "$src" > "${dstdir}/${dstfile}"
done
printf " done.\n"
if [ -f "${dst}/boot.cfg" ]; then
echo " => patching bootloader banner"
cp "${dst}/boot.cfg" "${dstbase}/boot.cfg" || die "couldn't copy boot.cfg to ${dstbase}"
cat "${dstbase}/boot.cfg" | sed 's/installation CD/installation memory stick/' > "${dst}/boot.cfg"
fi
echo " => copying /usr/mdec/boot to $dst"
cp /usr/mdec/boot "$dst" || die "couldn't copy /usr/mdec/boot"
echo " => building filesystem image"
makefs "$img" "$dst" || die "couldn't build filesystem image"
echo " => installing bootxx_ffsv1"
/usr/sbin/installboot "$img" /usr/mdec/bootxx_ffsv1 || die "couldn't install bootxx_ffsv1"
echo " => writing disklabel"
imgsize=$(stat -L -f %z "${img}")
echo "$disklabel" | \
sed "s/@SECTORS@/$(expr $imgsize / 512)/" | \
sed "s/@TCYLINDERS@/$(expr $imgsize / 512 / 1000 + 1)/" | \
sed "s/@TSECTORS@/$(expr $imgsize / 512 + 1)/" >${dstbase}/disklabel
disklabel -R -F "${img}" "${dstbase}/disklabel" || die "couldn't write disklabel"
echo " => cleaning up"
rm -rf "${dstbase}"
echo " => done!"
|