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
|
#!/bin/bash
set -e
set -u
TMP="${TMP:-/tmp}"
DATE=$(date '+%Y-%m-%d-%H%M')
DIST="${DIST:-bok}"
REPO="${REPO:-http://apt.osdyson.org}"
# We will search for usr archive on CD:
USR_IMG=usr.img.$(echo $DATE | md5sum | cut -f1 -d ' ')
ISONAME="${ISONAME:-dyson-${DIST}-${DATE}}.iso"
ROOT="${TMP}/ROOT"
BOOTARCH="${ROOT}/boot_archive"
if [ -z "${ROOT}" ] || [ "${ROOT}" = / ]; then
echo "WTF? Bad root: \`${ROOT}'" >&2
exit 1
fi
rm -rf "${ROOT}"/*
echo "Preparing base system (debootstrap)..."
debootstrap \
--no-check-gpg \
--exclude=syslogd,gawk \
--include=illumos-grub,illumos-kernel,ufsutils,hsfs,mc,vim,illumos-ssh-client,wget,gzip,bzip2,debootstrap,less \
"${DIST}" \
"${ROOT}" \
"${REPO}"
# This stuff does not make sense for LiveCD:
rm -rf "${ROOT}"/var/lib/dpkg/info
rm -rf "${ROOT}"/var/lib/apt
rm -rf "${ROOT}"/var/cache/*
rm -rf "${ROOT}"/etc/cron.*
rm -rf "${ROOT}"/var/log/*
rm -rf "${ROOT}"/var/adm/*
rm -rf "${ROOT}"/usr/share/doc/*
# Remove 32-bit modules:
( cd "${ROOT}"
find kernel platform usr/kernel usr/platform -type f -path '*/amd64/*' \
| while read amd64; do
i86=${amd64/amd64\//}
if [ -f "$i86" ]; then
echo "Removing $i86"
rm "$i86"
fi
done
)
devfsadm -r "${ROOT}"
cat <<VFSTAB > $ROOT/etc/vfstab
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
#
/devices - /devices devfs - no -
/proc - /proc proc - no -
ctfs - /system/contract ctfs - no -
objfs - /system/object objfs - no -
sharefs - /etc/dfs/sharetab sharefs - no -
fd - /dev/fd fd - no -
swap - /tmp tmpfs - yes -
/devices/ramdisk:a - / ufs 1 no rw,nologging
VFSTAB
echo 'export LD_NOVERSION=1' >> $ROOT/etc/profile
echo "dyson-${DIST}-live" > "${ROOT}/etc/nodename"
touch "${ROOT}/etc/hostname.e1000g0"
touch "${ROOT}/etc/dhcp.e1000g0"
echo '127.0.0.1 localhost loghost' > "${ROOT}/etc/inet/hosts"
# Hack to know root password:
sed -i '/^root/d' $ROOT/etc/shadow
grep root /etc/shadow >> $ROOT/etc/shadow
echo 'User: root, password: root' >> "${ROOT}/etc/issue"
# Script to find and mount usr.lzma:
sed "s/USR_IMG/$USR_IMG/" "find-usr" > "${ROOT}/lib/svc/method/find-usr"
chmod +x "${ROOT}/lib/svc/method/find-usr"
sed -i '/readvfstab "\/usr"/i /lib/svc/method/find-usr >/dev/msglog 2>&1' \
"${ROOT}/lib/svc/method/fs-root"
# WE DON"T NEED BOOTARCHIVE ON LIVECD.
# Thank you!
sed -i '/if \[ -f "${UPDATEFILE}" \]; then/ i exit $SMF_EXIT_OK' \
"${ROOT}/lib/svc/method/fs-usr"
dummy_prog='#!/sbin/sh
exit 0
'
echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive"
echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive-update"
echo "Importing manifests..."
rm "${ROOT}/lib/svc/manifest/system/early-manifest-import.xml"
# bash or ksh, please:
bash "${ROOT}/lib/svc/method/manifest-import" \
-f "${ROOT}/etc/svc/repository.db" \
-d "${ROOT}/lib/svc/manifest"
# Thank you! Bye-bye!
echo "$dummy_prog" > "${ROOT}/lib/svc/method/manifest-import"
mkdir -p "${BOOTARCH}"
mkdir -p "${BOOTARCH}/usr"
mkdir -p "${BOOTARCH}/cdrom"
( cd "${ROOT}"
# List here files or directories which
# should be *moved* to boot archive.
# Caution: files from /usr require
# special treating: see below.
tar --remove-files -c -f - \
boot/solaris/devicedb/master \
boot/solaris/bootenv.rc \
bin \
dev \
devices \
etc \
home \
kernel \
lib \
media \
mnt \
opt \
proc \
root \
run \
sbin \
srv \
system \
tmp \
var \
| tar xf - -C "${BOOTARCH}"
# same, but keep source
tar -c -f - \
platform \
usr/bin/cat \
usr/bin/dash \
usr/bin/ls \
usr/bin/sh \
usr/lib/fs \
usr/lib/devfsadm \
usr/sbin \
| tar xf - -C "${BOOTARCH}"
# We need only kernel itself for GRUB.
# BTW, kernel should be in boot archive as well (WTF?)
find platform -type f -a ! -name unix -delete
)
find "${BOOTARCH}" > bootarch.list
echo "Making boot archive..."
sync; sync
if false; then
genisoimage \
-o "${ROOT}/boot/boot_archive" \
-N -l -R -U \
-allow-multidot \
-quiet -no-iso-translate -cache-inodes -d -D \
-V "root" \
"${BOOTARCH}"
else
size=$(du -s -m "${BOOTARCH}" | cut -f1)
dd if=/dev/zero of="${ROOT}/boot/boot_archive" bs=1M count="$size"
lofidev=$(lofiadm -a "${ROOT}/boot/boot_archive")
rlofidev="${lofidev/lofi/rlofi}"
yes | newfs -m 0 "${rlofidev}"
mkdir -p "${ROOT}/boot/boot_archive.mount"
mount "${lofidev}" "${ROOT}/boot/boot_archive.mount"
mv "${BOOTARCH}"/* "${ROOT}/boot/boot_archive.mount"/
umount "${ROOT}/boot/boot_archive.mount"
lofiadm -d "${lofidev}"
rmdir "${BOOTARCH}"
rmdir "${ROOT}/boot/boot_archive.mount"
fi
gzip -9 -f "${ROOT}/boot/boot_archive"
echo "Making usr archive..."
# usr will be mounted from usr.lzma:
genisoimage \
-o "${ROOT}/${USR_IMG}" \
-N -l -R -U \
-allow-multidot \
-quiet -no-iso-translate -cache-inodes -d -D \
-V "usr" \
"${ROOT}/usr"
rm -rf "${ROOT}/usr"
lofiadm -C lzma "${ROOT}/${USR_IMG}"
echo "Configuring GRUB..."
cat <<GRUB > "${ROOT}/boot/grub/menu.lst"
default=0
timeout=3
splashimage=/boot/grub/splash.xpm.gz
foreground=ffffff
background=215ECA
title Hello!
kernel$ /platform/i86pc/kernel/amd64/unix -k -m verbose
module$ /boot/boot_archive.gz
GRUB
echo "Making final ${ISONAME}..."
genisoimage \
-o "${ISONAME}" \
-b boot/grub/stage2_eltorito \
-c .catalog \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-N -l -R -U \
-allow-multidot \
-no-iso-translate \
-cache-inodes \
-d -D \
-V "${ISONAME}" \
"${ROOT}"
ls -lh "${ISONAME}"
exit 0
|