Skip to content
Newer
Older
100755 120 lines (100 sloc) 3.59 KB
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
1 #!/bin/sh
2 #
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 11, 2011
3 # Builds a 48MB kernel to put on a USB-stick
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
4
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 4, 2011
5 # Functions
6 function getrandomduid {
7 # Generates a 16 chars long hex string
8 tempduid=`cat /dev/urandom | tr -dc "a-f0-9" | fold -w 16 | head -1`
9 echo ${tempduid}
10 }
11
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
12 CWD=`pwd`
13 WORKDIR=sandbox
14 DISKTAB=disktab.48mb
15 NBLKS=98304
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
16 SRCDIR=${BSDSRCDIR:-/usr/src}
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
17 DESTDIR=${DESTDIR:-${CWD}/${WORKDIR}}
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
18 DUID=${2:-`getrandomduid`}
19 export SRCDIR DESTDIR CWD WORKDIR DISKTAB NBLKS DUID
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
20
21 # Don't start without a kernel as a parameter
22 if [ "$1" = "" ]; then
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
23 echo "usage: $0 kernel [duid]"
24 echo
25 echo "The options are as follows:"
26 echo "[duid]: Optional 16-character hexadecimal string used as"
27 echo " disklabel UID for the storage device mounted as /flash"
28 echo " If unset a random number is generated and printed at"
29 echo " the end of the script"
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
30 exit 1
31 fi
32
33 # Does the kernel exist at all
34 if [ ! -r $1 ]; then
35 echo "ERROR! $1 does not exist or is not readable."
36 exit 1
37 fi
38
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
39 # Quick test to see if sandbox exist
40 if ! [ -d ${CWD}/${WORKDIR}/dev ]; then
41 echo "You must build your release first. Run sudo ./build-release.sh"
42 exit
43 fi
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
44
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
45 # Check DUID format (hex and 16 char long string)
46 if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
47 echo "DUID: ${DUID} is not a 16-character hexadecimal string"
48 exit
49 fi;
50
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
51 # Which kernel to use?
dc9ea68 Removed referenses to list.largekernel since it has been merged into …
rancor authored Sep 25, 2011
52 export KERNEL=$1
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
53
54 # Create the kernelfile (with increased MINIROOTSIZE)
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
55 grep -v MINIROOTSIZE $1 > ${CWD}/${WORKDIR}/${KERNEL}
56 echo "option MINIROOTSIZE=${NBLKS}" >> ${CWD}/${WORKDIR}/${KERNEL}
57
58 echo "Setting up environment.."
59
60 umount ${CWD}/${WORKDIR}/dev
61 mount_mfs -o nosuid -s 32768 swap ${CWD}/${WORKDIR}/dev
62 cp -p ${CWD}/${WORKDIR}/dev-orig/MAKEDEV ${CWD}/${WORKDIR}/dev/MAKEDEV
63 cd ${CWD}/${WORKDIR}/dev
64 ./MAKEDEV all
65 cp -p ${CWD}/$1 ${CWD}/${WORKDIR}/
66 cp -p ${CWD}/Makefile ${CWD}/${WORKDIR}/
67 cp -p ${CWD}/build-usbkernel-injail.sh ${CWD}/${WORKDIR}/
68 cp -p ${CWD}/list ${CWD}/${WORKDIR}/
69 cp -p ${CWD}/list.recovery ${CWD}/${WORKDIR}/
bb9a0ba @jryberg Fixed USB kernel and image scripts. Now working as long the computer …
jryberg authored Oct 2, 2011
70 # Include custom list if exist
71 if [ -r ${CWD}/list.custom ]; then
72 cp -p ${CWD}/list.custom ${CWD}/${WORKDIR}/
73 fi
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
74 cp -p ${CWD}/conf ${CWD}/${WORKDIR}/
75 cp -p ${CWD}/mtree.conf ${CWD}/${WORKDIR}/
76 cp -pR ${CWD}/disktabs ${CWD}/${WORKDIR}/
77 cp -pR ${CWD}/tools ${CWD}/${WORKDIR}/
78 cp -pR ${CWD}/initial-conf ${CWD}/${WORKDIR}/
79 rm -r ${CWD}/${WORKDIR}/obj
80 mkdir -p ${CWD}/${WORKDIR}/obj
bb9a0ba @jryberg Fixed USB kernel and image scripts. Now working as long the computer …
jryberg authored Oct 1, 2011
81 mkdir -p ${CWD}/obj
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
82
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
83 # Don't want anything mounted to /mnt when we starts
84 umount /mnt
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
85
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
86 echo "Going into chroot to build kernel"
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
87 /usr/sbin/chroot ${CWD}/${WORKDIR} ./build-usbkernel-injail.sh ${DUID}
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
88
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
89 echo "Comming back from chroot"
90
91 # Clean up /dev for the creation of file system
92 rm -rf ${CWD}/${WORKDIR}/dev/*
93 cd ${CWD}/${WORKDIR}
94 umount ${CWD}/${WORKDIR}/dev
95 cp -p ${CWD}/${WORKDIR}/dev-orig/MAKEDEV ${CWD}/${WORKDIR}/dev/MAKEDEV
96
97 echo "Building file system"
98 cd ${CWD}/${WORKDIR}/
99
100 # From Makefile that could not run in a chroot
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
101 make mr.fs rdsetroot KCONF=${KERNEL} LIST=${CWD}/${WORKDIR}/list.temp NBLKS=${NBLKS} DISKPROTO=${CWD}/${WORKDIR}/disktabs/${DISKTAB}
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
102 cp ${CWD}/${WORKDIR}/obj/bsd ${CWD}/${WORKDIR}/obj/bsd.rd
103 ${CWD}/${WORKDIR}/obj/rdsetroot ${CWD}/${WORKDIR}/obj/bsd.rd < ${CWD}/${WORKDIR}/obj/mr.fs
104 gzip -c9 ${CWD}/${WORKDIR}/obj/bsd.rd > ${CWD}/${WORKDIR}/obj/bsd.gz
105
106 # Clean up
107 rm -rf ${CWD}/${WORKDIR}/dev/*
108 rm -r ${CWD}/obj/*
2882a54 @jryberg Booting USB kernel with duid and added more sd devices to make bootin…
jryberg authored Oct 3, 2011
109 rm -f list.temp
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
110 rm -f $KERNEL
111
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
112 # Move kernel files from sandbox to the "old" location as before chroot
113 mv ${CWD}/${WORKDIR}/obj/* ${CWD}/obj/
114
32e5b6b @jschlyter import from mindrot
jschlyter authored Aug 9, 2011
115 # Done
8e9aba3 Modifications to build OpenBSD 4.9 in chroot. Based on resent changes…
rancor authored Aug 10, 2011
116 echo "Your kernel is stored here ${CWD}/obj/"
daaf1c9 @jryberg Building with custom or random DUID instead of static value.
jryberg authored Oct 3, 2011
117 echo "The UID that are used in the ramdisk kernel is ${DUID}"
118 echo "You *MUST* pass this UID to build-usbimage.sh as the second parameter"
119 echo "or the image will fail to mount /flash."
Something went wrong with that request. Please try again.