install gawk by default (required for gcc49 build)
[unleashed-kayak.git] / build_iso.sh
blob73e8118abd4800dbd321ac14fab3caa9b01fb590
1 #!/usr/bin/bash
3 # {{{ CDDL HEADER
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 # }}}
15 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
16 # Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
20 # Build an ISO installer using the Kayak tools.
23 if [ `id -u` != "0" ]; then
24 echo "You must be root to run this script."
25 exit 1
28 if [ -z "$BUILDSEND_MP" ]; then
29 echo "Using /rpool/kayak_image for BUILDSEND_MP"
30 BUILDSEND_MP=/rpool/kayak_image
33 if [ -z "$VERSION" ]; then
34 echo "VERSION not set." >&2
35 exit 1
37 echo "Using version $VERSION..."
39 stage()
41 echo "***"
42 echo "*** $*"
43 echo "***"
46 # Allow temporary directory override
47 : ${TMPDIR:=/tmp}
49 KAYAK_MINIROOT=$BUILDSEND_MP/miniroot.gz
50 ZFS_IMG=$BUILDSEND_MP/kayak_${VERSION}.zfs.bz2
52 [ ! -f $KAYAK_MINIROOT -o ! -f $ZFS_IMG ] && echo "Missing files." && exit 1
54 ISO_ROOT=$TMPDIR/iso_root
55 BA_ROOT=$TMPDIR/boot_archive
57 KAYAK_ROOT=$TMPDIR/miniroot.$$
58 KR_FILE=$TMPDIR/kr.$$
59 MNT=/mnt
60 BA_SIZE=300M
61 DST_ISO=$BUILDSEND_MP/${VERSION}.iso
63 #############################################################################
65 # The kayak mini-root is used for both the ISO root filesystem and for the
66 # miniroot that is loaded and mounted on / when booted.
69 set -o errexit
71 mkdir $KAYAK_ROOT
72 mkdir $ISO_ROOT
74 # Create a UFS lofi file and mount the UFS filesystem in $MNT. This will
75 # form the boot_archive for the ISO.
77 stage "Mounting source miniroot"
78 # Uncompress and mount the miniroot
79 gunzip -c $KAYAK_MINIROOT > $KR_FILE
80 LOFI_RPATH=`lofiadm -a $KR_FILE`
81 mount $LOFI_RPATH $KAYAK_ROOT
83 stage "Creating UFS image for new miniroot"
84 mkfile $BA_SIZE $BA_ROOT
85 LOFI_PATH=`lofiadm -a $BA_ROOT`
86 echo 'y' | newfs $LOFI_PATH
87 mount $LOFI_PATH $MNT
89 # Copy the files from the miniroot to the new miniroot...
90 sz=`du -sh $KAYAK_ROOT | awk '{print $1}'`
91 stage "Adding files to new miniroot"
92 tar -cf - -C $KAYAK_ROOT . | pv -s $sz | tar -xf - -C $MNT
93 # ...and to the ISO root
94 stage "Adding files to ISO root"
95 tar -cf - -C $KAYAK_ROOT . | pv -s $sz | tar -xf - -C $ISO_ROOT
97 # Clean-up
98 stage "Unmounting source miniroot"
99 umount $KAYAK_ROOT
100 rmdir $KAYAK_ROOT
101 lofiadm -d $LOFI_RPATH
102 rm $KR_FILE
104 # Place the full ZFS image into the ISO root so it does not form part of the
105 # boot archive (otherwise the boot seems to hang for several minutes while
106 # the miniroot is loaded)
108 stage "Adding ZFS image to ISO root"
109 mkdir -p $ISO_ROOT/image
110 pv $ZFS_IMG > $ISO_ROOT/image/`basename $ZFS_IMG`
111 # Create a file to indicate that this is the right volume set on which to
112 # find the image - see src/mount_media.c
113 echo "unleashed-installer" > $ISO_ROOT/.volsetid
115 # Put additional files into the boot-archive on $MNT, which is
116 # what will be / (via ramdisk) once the ISO is booted.
118 stage "Adding extra files to miniroot"
120 # Extra files
121 cp takeover-console mount_media $MNT/kayak/
123 if [ -n "$REFRESH_KAYAK" ]; then
124 # For testing, make sure files in miniroot are current
125 for f in $MNT/kayak/*; do
126 [ -f "$f" ] || continue
127 echo "REFRESH $f"
128 cp `basename $f` $MNT/kayak
129 done
132 cat <<EOF > $MNT/root/.bashrc
133 export PATH=/usr/bin:/usr/sbin:/sbin
134 export HOME=/root
137 # Refresh the devices on the miniroot.
138 devfsadm -r $MNT
141 # The ISO's miniroot is going to be larger than the PXE miniroot. To that
142 # end, some files not listed in the exception list do need to show up on
143 # the miniroot. Use PREBUILT_ILLUMOS if available, or the current system
144 # if not.
146 from_one_to_other() {
147 dir=$1
149 FROMDIR=/
150 [ -n "$PREBUILT_ILLUMOS" -a -d $PREBUILT_ILLUMOS/proto/root_i386/$dir ] \
151 && FROMDIR=$PREBUILT_ILLUMOS/proto/root_i386
153 shift
154 tar -cf - -C $FROMDIR/$dir ${@:-.} | tar -xf - -C $MNT/$dir
157 # Add from_one_to_other for any directory {file|subdir file|subdir ...} you need
158 from_one_to_other usr/share/lib/zoneinfo
159 from_one_to_other usr/share/lib/keytables
160 from_one_to_other usr/share/terminfo
161 from_one_to_other usr/sbin ping
162 from_one_to_other usr/bin netstat
164 # Remind people this is the installer.
165 cat <<EOF > $ISO_ROOT/boot/loader.conf.local
166 loader_menu_title="Welcome to the Unleashed installer"
167 autoboot_delay=10
171 # Okay, we've populated the new miniroot. Close it up and install it
172 # on $ISO_ROOT as the boot archive.
174 stage "Miniroot size"
175 df -h $MNT
176 stage "Unmounting boot archive image"
177 umount $MNT
178 lofiadm -d $LOFI_PATH
179 stage "Installing boot archive"
180 pv $BA_ROOT | gzip -9c > $ISO_ROOT/platform/i86pc/boot_archive.gz
181 ls -lh $ISO_ROOT/platform/i86pc/boot_archive.gz | awk '{print $5}'
182 digest -a sha1 $BA_ROOT \
183 > $ISO_ROOT/platform/i86pc/boot_archive.hash
184 rm -f $BA_ROOT
185 stage "Removing unecessary files from ISO root"
186 rm -rf $ISO_ROOT/{usr,bin,sbin,lib,kernel}
187 stage "ISO root size: `du -sh $ISO_ROOT/.`"
189 # And finally, burn the ISO.
190 LC_ALL=C mkisofs -N -l -R -U -d -D \
191 -o $DST_ISO \
192 -b boot/cdboot \
193 -c .catalog \
194 -no-emul-boot \
195 -boot-load-size 4 \
196 -boot-info-table \
197 -allow-multidot \
198 -no-iso-translate \
199 -cache-inodes \
200 -V "Unleashed $VERSION" \
201 $ISO_ROOT
203 rm -rf $ISO_ROOT
204 stage "$DST_ISO is ready"
205 ls -lh $DST_ISO
207 # Vim hints
208 # vim:fdm=marker