-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathbuild_image.sh
executable file
·383 lines (345 loc) · 12.6 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
#!/bin/bash
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
#
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:=https://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
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/real-mode system/boot/wanboot/internal
system/boot/loader 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/i40e
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/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/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 driver/storage/pvscsi"
PARTS="release/name release/notices service/picl install/beadm SUNWcs SUNWcsd
library/libidn shell/pipe-viewer text/less editor/vim web/curl
developer/linker file/gnu-coreutils openssh openssh-server
diagnostic/diskinfo"
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.7 /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
# So "bootadm update-archive" can work.
cp $SRCDIR/digest $WORKDIR/mnt/usr/bin/digest
chmod 0755 $WORKDIR/mnt/usr/bin/digest
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