6 # This file and its contents are supplied under the terms of the
7 # Common Development and Distribution License ("CDDL"), version 1.0.
8 # You may only use this file in accordance with the terms of version
11 # A full copy of the text of the CDDL should have accompanied this
12 # source. A copy of the CDDL is also available via the Internet at
13 # http://www.illumos.org/license/CDDL.
17 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
21 # Build a USB installer using the Kayak tools.
24 if [[ `id -u` != "0" ]]; then
25 echo "You must be root to run this script."
29 if [[ -z $BUILDSEND_MP ]]; then
30 echo "Using /rpool/kayak_image for BUILDSEND_MP"
31 BUILDSEND_MP
=/rpool
/kayak_image
34 if [[ -z $VERSION ]]; then
35 echo "\$VERSION not set" >&2
39 # Many of these depend on sufficient space in /tmp by default. Please
40 # modify as you deem appropriate.
43 KAYAK_ROOTBALL
=$BUILDSEND_MP/miniroot.gz
44 KAYAK_ROOT
=${TMPDIR}/miniroot.$$
45 KR_FILE
=${TMPDIR}/kr.$$
47 UFS_LOFI
=${TMPDIR}/boot_archive
49 DST_IMG
=${BUILDSEND_MP}/${VERSION}.img
50 ZFS_IMG
=$BUILDSEND_MP/kayak_
${VERSION}.zfs.bz2
55 umount
$MNT 2>/dev
/null
56 umount
$KAYAK_ROOT 2>/dev
/null
57 rm -rf $PROTO $UFS_LOFI $KR_FILE $KAYAK_ROOT
58 lofiadm
-d $DST_IMG 2>/dev
/null
59 lofiadm
-d $LOFI_PATH 2>/dev
/null
60 lofiadm
-d $LOFI_RPATH 2>/dev
/null
61 lofiadm
-d $KR_FILE 2>/dev
/null
63 trap cleanup
0 INT TERM
65 # Create a UFS lofi file and mount the UFS filesystem in $MNT. This will
66 # form the boot_archive for the USB.
67 mkfile
$LOFI_SIZE $UFS_LOFI
68 LOFI_PATH
=`lofiadm -a $UFS_LOFI`
69 echo 'y' | newfs
$LOFI_PATH
72 # Clone the already-created Kayak miniroot and copy it into both $MNT, and
73 # into a now-created $PROTO. $PROTO will form the directory that gets
74 # sprayed onto the USB.
75 gunzip
-c $KAYAK_ROOTBALL > $KR_FILE
76 LOFI_RPATH
=`lofiadm -a $KR_FILE`
78 mount
$LOFI_RPATH $KAYAK_ROOT
79 tar -cf - -C $KAYAK_ROOT . |
tar -xf - -C $MNT
81 tar -cf - -C $KAYAK_ROOT . |
tar -xf - -C $PROTO
84 lofiadm
-d $LOFI_RPATH
88 # Put additional goodies into the boot-archive on $MNT, which is
89 # what'll be / (via ramdisk) once one boots the USB.
92 # The full ZFS image (also already-created) for actual installation.
93 cp $ZFS_IMG $MNT/root
/.
95 # A cheesy way to get the boot menu to appear at boot time.
96 cp -p .
/takeover-console
$MNT/kayak
/.
97 cat <<EOF > $MNT/root/.bashrc
98 export PATH=/usr/bin:/usr/sbin:/sbin
102 # Refresh the devices on the miniroot.
106 # The USB's miniroot is going to be larger than the PXE miniroot. To that
107 # end, some files not listed in the exception list do need to show up on
108 # the miniroot. Use PREBUILT_ILLUMOS if available, or the current system
111 from_one_to_other
() {
113 if [[ -z $PREBUILT_ILLUMOS ||
! -d $PREBUILT_ILLUMOS/proto
/root_i386
/$dir ]]
117 FROMDIR
=$PREBUILT_ILLUMOS/proto
/root_i386
121 tar -cf - -C $FROMDIR/$dir ${@:-.} |
tar -xf - -C $MNT/$dir
124 # Add from_one_to_other for any directory {file|subdir file|subdir ...} you need
125 from_one_to_other usr
/share
/lib
/zoneinfo
126 from_one_to_other usr
/share
/lib
/keytables
127 from_one_to_other usr
/share
/lib
/terminfo
128 from_one_to_other usr
/gnu
/share
/terminfo
129 from_one_to_other usr
/sbin
ping
130 from_one_to_other usr
/bin netstat
132 cat <<EOF > $PROTO/boot/loader.conf.local
133 loader_menu_title="Welcome to the unleashed installer"
139 # Okay, we've populated the new miniroot. Close it up and install it on $PROTO
140 # as the boot archive.
143 lofiadm
-d $LOFI_PATH
144 gzip -c $UFS_LOFI > $PROTO/platform
/i86pc
/amd64
/boot_archive
145 digest
-a sha1
$UFS_LOFI > $PROTO/platform
/i86pc
/amd64
/boot_archive.
hash
146 rm -rf $PROTO/{usr
,bin
,sbin
,lib
,kernel
}
147 protosize
=$
(du
-sm $PROTO/.|cut
-f1)
148 imagesize
=$
((protosize
* 11/10))
151 mkfile
-n ${imagesize}M
"${DST_IMG}"
152 devs
="$(lofiadm -la "${DST_IMG}")"
153 rdevs
="${devs/dsk/rdsk}"
154 s0devs
="${devs/p0/s0}"
155 rs0devs
="${rdevs/p0/s0}"
156 rs2devs
="${rdevs/p0/s2}"
158 prtvtoc
"${rs2devs}" | nawk
'
159 /^[^\*]/ { r = $1; for(n = 1; n <= NF; n++) vtoc[r,n] = $n }
164 vtoc[0,4] = vtoc[8,6] + 1;
165 vtoc[0,5] = vtoc[2,6] - vtoc[8,6];
166 vtoc[0,6] = vtoc[2,6];
167 printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n",
168 vtoc[0,1], vtoc[0,2], vtoc[0,3], vtoc[0,4], vtoc[0,5], vtoc[0,6]);
169 printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n",
170 vtoc[2,1], vtoc[2,2], vtoc[2,3], vtoc[2,4], vtoc[2,5], vtoc[2,6]);
171 printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n",
172 vtoc[8,1], vtoc[8,2], vtoc[8,3], vtoc[8,4], vtoc[8,5], vtoc[8,6]);
173 }' | fmthard
-s- "${rs2devs}"
174 # newfs doesn't ask questions if stdin isn't a tty.
175 newfs
"${rs0devs}" </dev
/null
176 mount
-o nologging
"${s0devs}" $MNT
177 tar cf
- -C $PROTO . |
tar xf
- -C $MNT
178 installboot
-mf "${MNT}/boot/pmbr" "${MNT}/boot/gptzfsboot" "${rs0devs}"
181 echo "$DST_IMG is ready"