forked from omniti-labs/kayak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_image.sh
executable file
·387 lines (354 loc) · 12.9 KB
/
build_image.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/bin/bash
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
# Use is subject to license terms.
#
fail() {
echo "ERROR: $*"
exit 1
}
# NOTE --> The URL needs to be updated with every release.
# Change "bloody" to whatever release the current branch is.
PUBLISHER=omnios
: ${PKGURL:=http://pkg.omniti.com/omnios/bloody}
: ${GZIP_CMD:=gzip}
SRCDIR=$(dirname $0)
DIDWORK=0
BUILDNUM=${VERSION//r/}
if [[ ${SRCDIR:0:1} != "/" ]]; then
SRCDIR=`pwd`/$SRCDIR
fi
if [[ -z "${1}" ]]; then
echo "$0 <zfs pool> [checkpoint]"
exit 1
else
BASE=${1}
shift
BASEDIR=`zfs get -o value -H mountpoint $BASE`
fi
MKFILEDIR=/tmp
WORKDIR=$BASEDIR
ROOTDIR=$WORKDIR/root
if [[ ! -d $ROOTDIR ]]; then
zfs create -o compression=off $BASE/root || fail "zfs create failed"
fi
SVCCFG_DTD=${ROOTDIR}/usr/share/lib/xml/dtd/service_bundle.dtd.1
SVCCFG_REPOSITORY=${ROOTDIR}/etc/svc/repository.db
#SVCCFG=/usr/sbin/svccfg
if [[ -f ${PREBUILT_ILLUMOS}/usr/src/cmd/svc/svccfg/svccfg-native ]]; then
SVCCFG=${PREBUILT_ILLUMOS}/usr/src/cmd/svc/svccfg/svccfg-native
else
echo "WARNING -- Not using 'native' svccfg, may hang on build."
echo " We recommend a pre-built illumos's svccfg-native."
echo " Set PREBUILT_ILLUMOS in your environment to point"
echo " to a built illumos-omnios repository."
SVCCFG=/usr/sbin/svccfg
fi
export WORKDIR ROOTDIR SVCCFG_DTD SVCCFG_REPOSITORY SVCCFG
# This was uber-helpful
# http://alexeremin.blogspot.com/2008/12/preparing-small-miniroot-with-zfs-and.html
PKG=/bin/pkg
UNNEEDED_MANIFESTS="application/management/net-snmp.xml
application/pkg/pkg-server.xml application/pkg/pkg-mdns.xml
system/rmtmpfiles.xml system/mdmonitor.xml
system/fm/notify-params.xml system/device/allocate.xml
system/device/devices-audio.xml system/auditd.xml
system/metasync.xml system/pkgserv.xml system/fcoe_initiator.xml
system/metainit.xml system/zonestat.xml
system/cron.xml system/rbac.xml system/sac.xml
system/auditset.xml system/hotplug.xml
system/wusb.xml system/zones.xml
system/intrd.xml system/coreadm.xml
system/extended-accounting.xml
system/scheduler.xml
system/logadm-upgrade.xml system/resource-mgmt.xml
system/idmap.xml
network/ldap/client.xml network/shares/reparsed.xml
network/shares/group.xml network/inetd-upgrade.xml
network/smb/client.xml network/smb/server.xml
network/network-iptun.xml network/ipsec/policy.xml
network/ipsec/ipsecalgs.xml network/ipsec/ike.xml
network/ipsec/manual-key.xml network/forwarding.xml
network/inetd.xml network/npiv_config.xml
network/ssl/kssl-proxy.xml network/rpc/metamed.xml
network/rpc/mdcomm.xml network/rpc/gss.xml
network/rpc/bind.xml network/rpc/keyserv.xml
network/rpc/meta.xml network/rpc/metamh.xml
network/socket-filter-kssl.xml network/network-netcfg.xml
network/nfs/status.xml network/nfs/cbd.xml
network/nfs/nlockmgr.xml network/nfs/mapid.xml
network/nfs/client.xml network/network-ipqos.xml
network/security/ktkt_warn.xml network/security/krb5kdc.xml
network/security/kadmin.xml network/network-install.xml
network/bridge.xml network/network-initial.xml
network/network-ipmgmt.xml network/routing/legacy-routing.xml
network/network-service.xml network/network-physical.xml
network/network-netmask.xml network/dlmgmt.xml
network/network-location.xml network/ibd-post-upgrade.xml
network/network-routing-setup.xml network/network-loopback.xml
network/dns/client.xml network/dns/install.xml
network/dns/multicast.xml platform/i86pc/acpihpd.xml
system/hostid.xml system/power.xml system/pfexecd.xml
system/consadm.xml system/pools.xml system/console-login.xml
system/stmf.xml system/fmd.xml system/utmp.xml
system/poold.xml system/dumpadm.xml"
SYSTEM="system/boot/grub system/boot/real-mode system/boot/wanboot/internal
system/boot/wanboot system/data/hardware-registry
system/data/keyboard/keytables system/data/terminfo
system/data/zoneinfo system/extended-system-utilities
system/file-system/autofs system/file-system/nfs
system/file-system/smb system/file-system/udfs
system/file-system/zfs system/flash/fwflash
system/fru-id/platform system/fru-id system/ipc
system/kernel/dynamic-reconfiguration/i86pc
system/kernel/security/gss system/library/math
system/library/platform system/library/policykit
system/library/processor
system/library/storage/fibre-channel/hbaapi
system/library/storage/fibre-channel/libsun_fc
system/library/storage/ima/header-ima
system/library/storage/ima
system/library/storage/libmpapi
system/library/storage/libmpscsi_vhci
system/library/storage/scsi-plugins
system/library system/network
system/prerequisite/gnu system/storage/luxadm
system/storage/fibre-channel/port-utility"
DEBUG_PKGS="developer/debug/mdb system/dtrace developer/dtrace"
DRIVERS="driver/audio driver/crypto/dca driver/crypto/tpm driver/firewire
driver/graphics/agpgart driver/graphics/atiatom driver/graphics/drm
driver/i86pc/fipe driver/i86pc/ioat driver/i86pc/platform
driver/misc/virtio
driver/network/afe driver/network/amd8111s driver/network/atge
driver/network/bfe driver/network/bge driver/network/bnx
driver/network/bnxe driver/network/bpf driver/network/chxge
driver/network/dmfe driver/network/e1000g driver/network/elxl
driver/network/emlxs driver/network/eoib driver/network/fcip
driver/network/fcp driver/network/fcsm driver/network/fp
driver/network/hermon driver/network/hme driver/network/hxge
driver/network/ib driver/network/ibdma driver/network/ibp
driver/network/igb driver/network/iprb driver/network/ixgb
driver/network/ixgbe driver/network/mxfe driver/network/myri10ge
driver/network/nge driver/network/ntxn driver/network/nxge
driver/network/vmxnet3s driver/network/sfxge
driver/network/ofk driver/network/pcn driver/network/platform
driver/network/qlc driver/network/rds driver/network/rdsv3
driver/network/rge driver/network/rpcib driver/network/rtls
driver/network/sdp driver/network/sdpib driver/network/sfe
driver/network/tavor driver/network/usbecm driver/network/vr
driver/network/xge driver/network/yge driver/pcmcia driver/serial/pcser
driver/serial/usbftdi driver/serial/usbsacm driver/serial/usbser
driver/serial/usbser_edge driver/serial/usbsksp
driver/serial/usbsksp/usbs49_fw driver/serial/usbsprl
driver/storage/aac driver/storage/adpu320 driver/storage/ahci
driver/storage/amr driver/storage/arcmsr driver/storage/ata
driver/storage/bcm_sata driver/storage/blkdev driver/storage/cpqary3
driver/storage/glm driver/storage/lsimega driver/storage/marvell88sx
driver/storage/mega_sas driver/storage/mpt_sas driver/storage/mr_sas
driver/storage/nv_sata driver/storage/pcata driver/storage/pmcs
driver/storage/sbp2 driver/storage/scsa1394 driver/storage/sdcard
driver/storage/ses driver/storage/si3124 driver/storage/smp
driver/usb driver/usb/ugen driver/xvm/pv driver/storage/vioblk
driver/network/vioif driver/storage/nvme"
PARTS="release/name release/notices service/picl install/beadm SUNWcs SUNWcsd
library/libidn shell/pipe-viewer text/less editor/vim
developer/linker file/gnu-coreutils openssh openssh-server"
PKGS="$PARTS $SYSTEM $DRIVERS"
if [ -n "$DEBUG" ]; then
PKGS="$PKGS $DEBUG_PKGS"
BIGROOT=1
fi
CULL="perl python package/pkg snmp"
RMRF="/var/pkg /usr/share/man /usr/lib/python2.6 /usr/lib/iconv"
ID=`id -u`
if [[ "$ID" != "0" ]]; then
echo "must run as root"
exit 1
fi
chkpt() {
SNAP=`zfs list -H -t snapshot $BASE/root@${1} 2> /dev/null`
if [[ "$DIDWORK" -ne "0" ]]; then
if [[ -n "$SNAP" ]]; then
zfs destroy $BASE/root@${1} || \
fail "zfs destroy ${1} failed"
fi
zfs snapshot $BASE/root@${1} || fail "zfs snapshot failed"
fi
if [[ "${1}" != "begin" ]]; then
echo " === Proceeding to phase $1 (zfs @${1}) ==="
zfs rollback -r $BASE/root@${1} || fail "zfs rollback failed"
else
echo " === Proceeding to phase $1 ==="
fi
CHKPT=$1
DIDWORK=1
}
if [[ -n "$1" ]]; then
echo "Explicit checkpoint requested: '$1'"
CHKPT=$1
chkpt $CHKPT
fi
if [[ -z "$CHKPT" ]]; then
CHKPT="begin"
fi
declare -A keep_list
load_keep_list() {
for datafile in $*
do
FCNT=0
while read file
do
if [[ -n "$file" ]]; then
keep_list+=([$file]="x")
FCNT=$(($FCNT + 1))
fi
done < <(cut -f2- -d/ $datafile)
echo " --- keeping $FCNT files from $datafile"
done
}
step() {
CHKPT=""
case "$1" in
"begin")
zfs destroy -r $BASE/root 2> /dev/null
zfs create -o compression=off $BASE/root || fail "zfs create failed"
chkpt pkg
;;
"pkg")
echo "Creating image of $PUBLISHER from $PKGURL"
$PKG image-create -F -p $PUBLISHER=$PKGURL $ROOTDIR || fail "image-create"
# If a version was requested, respect it
if [[ -n $BUILDNUM ]]; then
$PKG -R $ROOTDIR install illumos-gate@11-0.$BUILDNUM omnios-userland@11-0.$BUILDNUM || fail "version constraint prep"
fi
$PKG -R $ROOTDIR install $PKGS || fail "install"
if [[ -n $BUILDNUM ]]; then
$PKG -R $ROOTDIR uninstall illumos-gate omnios-userland || fail "version constraint cleanup"
fi
chkpt fixup
;;
"fixup")
echo "Fixing up install root"
(cp $ROOTDIR/etc/vfstab $WORKDIR/vfstab && \
awk '{if($3!="/"){print;}}' $WORKDIR/vfstab > $ROOTDIR/etc/vfstab && \
echo "/devices/ramdisk:a - / ufs - no nologging" >> $ROOTDIR/etc/vfstab) || \
fail "vfstab / updated"
rm $WORKDIR/vfstab
cp $ROOTDIR/lib/svc/seed/global.db $ROOTDIR/etc/svc/repository.db
sed -i 's,PASSREQ=YES,PASSREQ=NO,' $ROOTDIR/etc/default/login
${SVCCFG} import ${ROOTDIR}/lib/svc/manifest/milestone/sysconfig.xml
for xml in $UNNEEDED_MANIFESTS; do
rm -f ${ROOTDIR}/lib/svc/manifest/$xml && echo " --- tossing $xml"
done
echo " --- initial manifest import"
# See if we can transform manifest-import to use the 'native' svccfg.
sed 's/\/usr\/sbin\/svccfg/\$SVCCFG/g' \
< ${ROOTDIR}/lib/svc/method/manifest-import \
> /tmp/manifest-import.$$
chmod 0755 /tmp/manifest-import.$$
export SVCCFG
/tmp/manifest-import.$$ -f ${ROOTDIR}/etc/svc/repository.db \
-d ${ROOTDIR}/lib/svc/manifest
/bin/rm -f /tmp/manifest-import.$$
${SVCCFG} -s 'system/boot-archive' setprop 'start/exec=:true'
${SVCCFG} -s 'system/manifest-import' setprop 'start/exec=:true'
${SVCCFG} -s "system/intrd:default" setprop "general/enabled=false"
${SVCCFG} -s "system/initial-boot" setprop "start/timeout_seconds=600"
echo " --- neutering the manifest import"
echo "#!/bin/ksh" > ${ROOTDIR}/lib/svc/method/manifest-import
echo "exit 0" >> ${ROOTDIR}/lib/svc/method/manifest-import
chmod 555 ${ROOTDIR}/lib/svc/method/manifest-import
chkpt cull
;;
"cull")
if [[ -z "$BIGROOT" ]]; then
load_keep_list data/*
while read file
do
if [[ -n "$file" && \
${keep_list[$file]} == "" && \
-e "$ROOTDIR/$file" && \
! -d $ROOTDIR/$file ]] ; then
rm -f $ROOTDIR/$file
fi
done < <(cd $ROOTDIR && find ./ | cut -c3-)
for path in $RMRF ; do
rm -rf ${ROOTDIR}$path && echo " -- tossing $path"
done
fi
chkpt mkfs
;;
"mkfs")
size=`/usr/bin/du -ks ${ROOTDIR}|/usr/bin/nawk '{print $1+10240}'`
echo " --- making image of size $size"
/usr/sbin/mkfile ${size}k $MKFILEDIR/miniroot || fail "mkfile"
lofidev=`/usr/sbin/lofiadm -a $MKFILEDIR/miniroot`
rlofidev=`echo $lofidev |sed s/lofi/rlofi/`
yes | /usr/sbin/newfs -m 0 $rlofidev 2> /dev/null > /dev/null || fail "newfs"
chkpt mount
;;
"mount")
mkdir -p $WORKDIR/mnt
/usr/sbin/mount -o nologging $lofidev $WORKDIR/mnt || fail "mount"
chkpt copy
;;
"copy")
pushd $ROOTDIR >/dev/null
/usr/bin/find . | /usr/bin/cpio -pdum $WORKDIR/mnt 2> /dev/null > /dev/null || fail "populate root"
/usr/sbin/devfsadm -r $WORKDIR/mnt > /dev/null
popd >/dev/null
mkdir $WORKDIR/mnt/kayak
cp $SRCDIR/*.sh $WORKDIR/mnt/kayak/
chmod a+x $WORKDIR/mnt/kayak/*.sh
make_initial_boot $WORKDIR/mnt/.initialboot
if [[ -n "$DEBUG" ]]; then
cp $SRCDIR/anon.system $WORKDIR/mnt/etc/system
cp $SRCDIR/anon.dtrace.conf $WORKDIR/mnt/kernel/drv/dtrace.conf
fi
chkpt umount
;;
"umount")
/usr/sbin/umount $WORKDIR/mnt || fail "umount"
/usr/sbin/lofiadm -d $MKFILEDIR/miniroot || fail "lofiadm delete"
chkpt compress
;;
"compress")
$GZIP_CMD -c -f $MKFILEDIR/miniroot > $WORKDIR/miniroot.gz
rm -f $MKFILEDIR/miniroot
chmod 644 $WORKDIR/miniroot.gz
echo " === Finished ==="
ls -l $WORKDIR/miniroot.gz
;;
esac
}
make_initial_boot() {
FILE=$1
cat > $FILE <<EOF
/kayak/install_image.sh
exit \$?
EOF
}
while [[ -n "$CHKPT" ]]; do
step $CHKPT
done