-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathufs_install.sh
executable file
·494 lines (455 loc) · 11.8 KB
/
ufs_install.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
#!/bin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# {{{ CDDL HEADER
#
# 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 2024 Peter Tribble
#
#
# FIXME: do fdisk and partitions first
#
# This installs to ufs. Must be a partition on a single physical disk.
#
# The assumption is that root=s0 swap=s1
# and that the drive is already partitioned
#
case $# in
0)
echo "Usage: $0 device [overlay ... ]"
exit 1
;;
esac
#
# these properties are available for customization
#
REBOOT="no"
OVERLAYS=""
NODENAME=""
TIMEZONE=""
DOMAINNAME=""
BEGIN_SCRIPT=""
FINISH_SCRIPT=""
FIRSTBOOT_SCRIPT=""
DRIVE1=""
PKGLOC="/.cdrom/pkgs"
SMFREPODIR="/usr/lib/zap"
ALTROOT="/a"
WCLIENT=/usr/bin/curl
WARGS="-f -s -S --retry 6 -o"
if [ ! -x $WCLIENT ]; then
WCLIENT=/usr/bin/wget
WARGS="-q --tries=6 --retry-connrefused --waitretry=2 -O"
fi
#
# read an external configuration file, if supplied
#
IPROFILE=$(/sbin/devprop install_profile)
if [ -n "$IPROFILE" ]; then
REBOOT="yes"
case $IPROFILE in
nfs*)
TMPMNT="/tmp/mnt1"
mkdir -p ${TMPMNT}
IPROFDIR=${IPROFILE%/*}
IPROFNAME=${IPROFILE##*/}
mount "$IPROFDIR" $TMPMNT
if [ -f "${TMPMNT}/${IPROFNAME}" ]; then
. "${TMPMNT}/${IPROFNAME}"
fi
umount ${TMPMNT}
rmdir ${TMPMNT}
;;
http*)
TMPF="/tmp/profile.$$"
DELAY=0
while [ ! -f "$TMPF" ]
do
sleep $DELAY
DELAY=$((DELAY+1))
${WCLIENT} ${WARGS} $TMPF "$IPROFILE"
done
. $TMPF
rm -fr $TMPF
;;
esac
fi
#
# begin script handling
# the begin script is run and its output saved
# then we source the output, this allows you to
# dynamically create install settings
#
if [ -n "$BEGIN_SCRIPT" ]; then
BEGINF="/tmp/begin.$$"
case $BEGIN_SCRIPT in
nfs*)
TMPMNT="/tmp/mnt1"
mkdir -p ${TMPMNT}
IPROFDIR=${BEGIN_SCRIPT%/*}
IPROFNAME=${BEGIN_SCRIPT##*/}
mount "$IPROFDIR" $TMPMNT
if [ -f "${TMPMNT}/${IPROFNAME}" ]; then
"${TMPMNT}/${IPROFNAME}" > $BEGINF
fi
umount ${TMPMNT}
rmdir ${TMPMNT}
;;
http*)
TMPF="/tmp/profile.$$"
${WCLIENT} ${WARGS} $TMPF "$BEGIN_SCRIPT"
if [ -s "$TMPF" ]; then
chmod a+x $TMPF
$TMPF > $BEGINF
fi
rm -f $TMPF
;;
esac
if [ -s "$BEGINF" ]; then
. $BEGINF
fi
rm -f $BEGINF
fi
#
# interactive argument handling
#
while getopts "n:t:" opt; do
case $opt in
n)
NODENAME="$OPTARG"
;;
t)
TIMEZONE="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
case $# in
0)
echo "Usage: $0 device [overlay ... ]"
exit 1
;;
esac
DRIVE1=$1
shift
if [ ! -e /dev/dsk/$DRIVE1 ]; then
echo "ERROR: Unable to find device $DRIVE1"
exit 1
fi
case $DRIVE1 in
*s0)
SWAPDEV=`echo $DRIVE1 | sed 's:s0$:s1:'`
;;
*)
echo "ERROR: Root slice must be slice 0"
exit 1
;;
esac
/usr/bin/mkdir -p ${ALTROOT}
echo "Creating root file system"
env NOINUSE_CHECK=1 /usr/sbin/newfs "/dev/rdsk/$DRIVE1"
/usr/sbin/mount "/dev/dsk/$DRIVE1" ${ALTROOT}
mkdir -p ${ALTROOT}/export/home
echo "Copying main filesystems"
cd /
ZONELIB=""
if [ -d zonelib ]; then
ZONELIB="zonelib"
fi
/usr/bin/find boot kernel lib platform root sbin usr etc var opt ${ZONELIB} -print -depth | cpio -pdm ${ALTROOT}
#
echo "Adding extra directories"
cd ${ALTROOT}
/usr/bin/ln -s ./usr/bin .
/usr/bin/mkdir -m 1777 tmp
/usr/bin/mkdir -p system/contract system/object system/boot proc mnt dev devices/pseudo
/usr/bin/mkdir -p dev/fd dev/rmt dev/swap dev/dsk dev/rdsk dev/net dev/ipnet
/usr/bin/mkdir -p dev/sad dev/pts dev/term dev/vt dev/zcons
/usr/bin/chgrp -R sys dev devices mnt
/usr/bin/chmod 555 system system/* proc
cd dev
/usr/bin/ln -s ./fd/2 stderr
/usr/bin/ln -s ./fd/1 stdout
/usr/bin/ln -s ./fd/0 stdin
/usr/bin/ln -s ../devices/pseudo/dld@0:ctl dld
cd /
#
# the man pages might be compressed to save space
#
if [ -f ${ALTROOT}/usr/share/liveman.tar.bz2 ] ; then
cd ${ALTROOT}/usr/share
bzcat liveman.tar.bz2 | tar xf -
rm -f liveman.tar.bz2
cd /
fi
#
# delete mkisofs from the installed image, we have an unpackaged copy
# on the bootable /usr which we use to optimize boot archive creation
#
/usr/bin/rm -f ${ALTROOT}/usr/bin/mkisofs
#
# add overlays, from the pkgs directory on the iso
# or an alternate location supplied by boot
#
# we create a zap config based on boot properties, should we copy that
# to the installed image as the highest priority repo? The problem
# there is that it will block all future updates
#
# give ourselves some swap to avoid /tmp exhaustion
# do it after copying the main OS as it changes the dump settings
#
swap -a "/dev/dsk/$SWAPDEV"
LOGFILE="${ALTROOT}/var/sadm/install/logs/initial.log"
echo "Installing overlays" | tee $LOGFILE
/usr/bin/date | tee -a $LOGFILE
TMPDIR=/tmp
export TMPDIR
echo "${ALTROOT}/var/zap/cache" > /etc/zap/cache_dir
if [ -d ${PKGLOC} ]; then
for overlay in base $*
do
echo "Installing $overlay overlay" | tee -a $LOGFILE
/usr/lib/zap/install-overlay -R ${ALTROOT} -s ${PKGLOC} "$overlay" | tee -a $LOGFILE
done
else
echo "No local packages found, trying to install overlays from the network"
echo "Installing base overlay" | tee -a $LOGFILE
/usr/lib/zap/install-overlay -R ${ALTROOT} base | tee -a $LOGFILE
# only try other overlays if base worked, to minimize wasteage
if [ -f ${ALTROOT}/var/sadm/overlays/installed/base ]; then
for overlay in $OVERLAYS
do
echo "Installing $overlay overlay" | tee -a $LOGFILE
/usr/lib/zap/install-overlay -R ${ALTROOT} "$overlay" | tee -a $LOGFILE
done
else
echo "Ignoring overlay installation due to failure" | tee -a $LOGFILE
fi
fi
echo "Overlay installation complete" | tee -a $LOGFILE
/usr/bin/date | tee -a $LOGFILE
echo "Deleting live package" | tee -a $LOGFILE
/usr/bin/zap uninstall -R ${ALTROOT} TRIBsys-install-media-internal
#
# use a prebuilt repository if available
#
/usr/bin/rm ${ALTROOT}/etc/svc/repository.db
if [ -f ${SMFREPODIR}/repository-installed.db.gz ]; then
/usr/bin/cp -p ${SMFREPODIR}/repository-installed.db.gz ${ALTROOT}/etc/svc/repository.db.gz
/usr/bin/gunzip ${ALTROOT}/etc/svc/repository.db.gz
else
/usr/bin/cp -p /lib/svc/seed/global.db ${ALTROOT}/etc/svc/repository.db
fi
#
# We have an x11 version because we have to enable hal
#
if [ -f ${ALTROOT}/var/sadm/overlays/installed/x11 ]; then
if [ -f ${SMFREPODIR}/repository-x11.db.gz ]; then
/usr/bin/rm ${ALTROOT}/etc/svc/repository.db
/usr/bin/cp -p ${SMFREPODIR}/repository-x11.db.gz ${ALTROOT}/etc/svc/repository.db.gz
/usr/bin/gunzip ${ALTROOT}/etc/svc/repository.db.gz
fi
fi
if [ -f ${ALTROOT}/var/sadm/overlays/installed/kitchen-sink ]; then
if [ -f ${SMFREPODIR}/repository-kitchen-sink.db.gz ]; then
/usr/bin/rm ${ALTROOT}/etc/svc/repository.db
/usr/bin/cp -p ${SMFREPODIR}/repository-kitchen-sink.db.gz ${ALTROOT}/etc/svc/repository.db.gz
/usr/bin/gunzip ${ALTROOT}/etc/svc/repository.db.gz
fi
fi
#
# reset the SMF profile from the live image to regular
#
/usr/bin/rm ${ALTROOT}/etc/svc/profile/generic.xml
/usr/bin/ln -s generic_limited_net.xml ${ALTROOT}/etc/svc/profile/generic.xml
#
# shut down pkgserv, as it blocks the unmount of the target filesystem
#
pkgadm sync -R ${ALTROOT} -q
#
# if there are filelists on the ISO, copy them across
#
if [ -f ${PKGLOC}/illumos.filelist.bz2 ]; then
cp ${PKGLOC}/illumos.filelist.bz2 ${ALTROOT}/etc/zap/repositories
fi
if [ -f ${PKGLOC}/tribblix.filelist.bz2 ]; then
cp ${PKGLOC}/tribblix.filelist.bz2 ${ALTROOT}/etc/zap/repositories
fi
#
echo "Installing boot loader"
/usr/sbin/installboot -f -m /boot/pmbr /boot/gptzfsboot /dev/rdsk/$DRIVE1
echo "Configuring devices"
${ALTROOT}/usr/sbin/devfsadm -r ${ALTROOT}
touch ${ALTROOT}/reconfigure
#
# mount / at boot and enable swap
#
/bin/echo "/dev/dsk/$DRIVE1\t/dev/rdsk/$DRIVE1\t/\tufs\t1\tno\tlogging" >> ${ALTROOT}/etc/vfstab
/bin/echo "/dev/dsk/$SWAPDEV\t-\t-\tswap\t-\tno\t-" >> ${ALTROOT}/etc/vfstab
#
# need to put the device path of the root slice into bootenv.rc so
# the boot can find it
#
BOOTDEV=`/bin/ls -l /dev/dsk/$DRIVE1 | awk '{print $NF}' | sed 's:../../devices::'`
echo "setprop bootpath '$BOOTDEV'" >> ${ALTROOT}/boot/solaris/bootenv.rc
#
# set nodename if requested
#
if [ -n "$NODENAME" ]; then
echo "$NODENAME" > ${ALTROOT}/etc/nodename
fi
#
# set domain name if requested
#
if [ -n "$DOMAINNAME" ]; then
echo "$DOMAINNAME" > ${ALTROOT}/etc/defaultdomain
fi
#
# set timezone if requested
#
if [ -n "$TIMEZONE" ]; then
/usr/bin/sed -i s:PST8PDT:${TIMEZONE}: ${ALTROOT}/etc/default/init
fi
#
# Copy /jack to the installed system
#
cd /
find jack -print | cpio -pmud ${ALTROOT}
/usr/bin/rm -f ${ALTROOT}/jack/.bash_history
#
# this is to fix a 3s delay in xterm startup
#
echo "*openIm: false" > ${ALTROOT}/jack/.Xdefaults
/usr/bin/chown jack:staff ${ALTROOT}/jack/.Xdefaults
#
# if specified, run a finish script
# the new root directory is passed as the only argument
#
if [ -n "$FINISH_SCRIPT" ]; then
case $FINISH_SCRIPT in
nfs*)
TMPMNT="/tmp/mnt1"
mkdir -p ${TMPMNT}
IPROFDIR=${FINISH_SCRIPT%/*}
IPROFNAME=${FINISH_SCRIPT##*/}
mount "$IPROFDIR" $TMPMNT
if [ -f "${TMPMNT}/${IPROFNAME}" ]; then
"${TMPMNT}/${IPROFNAME}" ${ALTROOT}
fi
umount ${TMPMNT}
rmdir ${TMPMNT}
;;
http*)
TMPF="/tmp/profile.$$"
${WCLIENT} ${WARGS} $TMPF "$FINISH_SCRIPT"
if [ -s "$TMPF" ]; then
chmod a+x $TMPF
$TMPF ${ALTROOT}
fi
rm -f $TMPF
;;
esac
fi
#
# remove the autoinstall startup script
#
/bin/rm -f ${ALTROOT}/etc/rc2.d/S99auto_install
sync
sleep 2
#
# if specified, enable a first-boot script
#
if [ -n "$FIRSTBOOT_SCRIPT" ]; then
FIRSTDIR="${ALTROOT}/etc/tribblix"
FIRSTF="${FIRSTDIR}/firstboot"
mkdir ${FIRSTDIR}
case $FIRSTBOOT_SCRIPT in
nfs*)
TMPMNT="/tmp/mnt1"
mkdir -p ${TMPMNT}
IPROFDIR=${FIRSTBOOT_SCRIPT%/*}
IPROFNAME=${FIRSTBOOT_SCRIPT##*/}
mount "$IPROFDIR" $TMPMNT
if [ -f "${TMPMNT}/${IPROFNAME}" ]; then
cp "${TMPMNT}/${IPROFNAME}" ${FIRSTF}
fi
umount ${TMPMNT}
rmdir ${TMPMNT}
;;
http*)
TMPF="/tmp/profile.$$"
${WCLIENT} ${WARGS} $TMPF "$FIRSTBOOT_SCRIPT"
if [ -s "$TMPF" ]; then
cp $TMPF $FIRSTF
fi
rm -f $TMPF
;;
esac
if [ -s "${FIRSTF}" ]; then
chmod a+x $FIRSTF
cat >> ${ALTROOT}/etc/rc3.d/S99firstboot <<EOF
#!/bin/sh
if [ -f /etc/tribblix/firstboot ]; then
mv /etc/tribblix/firstboot /etc/tribblix/firstboot.run
/etc/tribblix/firstboot.run
rm /etc/tribblix/firstboot.run
fi
rm /etc/rc3.d/S99firstboot
EOF
chmod a+x ${ALTROOT}/etc/rc3.d/S99firstboot
fi
fi
#
# copy selected keyboard type to installed system
#
KLAYOUT=`/usr/bin/kbd -l | /usr/bin/awk -F'[= ]' '{if ($1 == "layout") print $2}'`
if [ -n "${KLAYOUT}" ]; then
NLAYOUT=`/usr/bin/awk -v ntyp=${KLAYOUT} -F= '{if ($2 == ntyp) print $1}' /usr/share/lib/keytables/type_6/kbd_layouts`
if [ -n "${NLAYOUT}" ]; then
/usr/bin/grep -v keyboard-layout ${ALTROOT}/boot/solaris/bootenv.rc > ${ALTROOT}/boot/solaris/bootenv.rc.tmp
echo "setprop keyboard-layout ${NLAYOUT}" >> ${ALTROOT}/boot/solaris/bootenv.rc.tmp
/usr/bin/mv ${ALTROOT}/boot/solaris/bootenv.rc.tmp ${ALTROOT}/boot/solaris/bootenv.rc
/usr/bin/rm -f /tmp/keymap-set
echo "repository ${ALTROOT}/etc/svc/repository.db" > /tmp/keymap-set
echo "select keymap:default" >> /tmp/keymap-set
echo "setprop keymap/layout=${NLAYOUT}" >> /tmp/keymap-set
/usr/sbin/svccfg -f /tmp/keymap-set
/usr/bin/rm -f /tmp/keymap-set
fi
fi
#
# moved later, must be done after we change any files such as bootenv.rc
#
echo "Updating boot archive"
/usr/bin/mkdir -p ${ALTROOT}/platform/i86pc/amd64
/sbin/bootadm update-archive -R ${ALTROOT}
/sbin/sync
sleep 2
#
# if specified, reboot
#
case $REBOOT in
yes)
echo "Install complete, rebooting"
/sbin/sync
/usr/sbin/reboot -p
;;
esac
#
# welcome
#
echo ""
echo "Welcome to Tribblix"
echo "Any feedback will be gratefully received at [email protected]"
echo ""