-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathks.tpl.cfg
307 lines (247 loc) · 7.9 KB
/
ks.tpl.cfg
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
#version=DEVEL
# System authorization information
authselect --enableshadow --passalgo=sha512
# Non-interactive mode
cmdline
# Reboot After install
reboot
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=@@DISK_DEVS@@
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='jp'
# System language
lang en_US.UTF-8
# SELinux
selinux --disabled
# Do not configure the X Window System
skipx
# System services
services --enabled="chronyd,docker"
# System timezone
timesource --ntp-disable
# Group
group --name=docker
%include /tmp/ks.media.cfg
# Partition clearing information
clearpart --all --initlabel --drives=@@DISK_DEVS@@
# Create partitions
part /boot/efi --fstype="efi" --ondisk=@@MAIN_DISK@@ --size=200 --fsoptions="umask=0077,shortname=winnt"
part / --fstype="ext4" --ondisk=@@MAIN_DISK@@ --size=2048 --mkfsoptions="-U 64eb4db5-3385-46a5-a3d5-c48197a53555"
part /persist --fstype="ext4" --ondisk=@@MAIN_DISK@@ --size=200 --mkfsoptions="-U ff9691f9-7c97-4411-8f44-12685ee4a003" --fsoptions="defaults,x-initrd.mount"
part /root2 --fstype="ext4" --ondisk=@@MAIN_DISK@@ --size=2048 --mkfsoptions="-U d2ada949-7fff-4257-91e9-793b25b0df02"
part /var/log --fstype="ext4" --ondisk=@@MAIN_DISK@@ --size=@@PARTSIZE_LOG@@ --mkfsoptions="-U ff9691f9-7c97-4411-8f44-12685ee4a006" --fsoptions="defaults,x-initrd.mount,x-systemd.before=symlink-removable.service"
part btrfs.10 --fstype="btrfs" --ondisk=@@MAIN_DISK@@ --size=@@PARTSIZE_DOCKER@@ --fsoptions="x-systemd.wanted-by=remote-fs.target,x-systemd.wanted-by=docker.service,x-systemd.before=docker.service"
part btrfs.12 --fstype="btrfs" --ondisk=@@MAIN_DISK@@ --size=@@PARTSIZE_CACHE@@ --fsoptions="x-systemd.wanted-by=remote-fs.target"
part btrfs.14 --fstype="btrfs" --ondisk=@@MAIN_DISK@@ --size=@@PARTSIZE_OPT@@ --fsoptions="defaults,nofail,x-initrd.mount"
btrfs none --label=var_lib_docker btrfs.10
btrfs none --label=var_cache btrfs.12
btrfs none --label=opt btrfs.14
btrfs /var/lib/docker --subvol --name=var_lib_docker LABEL=var_lib_docker
btrfs /var/cache --subvol --name=var_cache LABEL=var_cache
btrfs /opt --subvol --name=opt LABEL=opt
@@KS.ROOT.CFG@@
%pre --log=/mnt/sysimage/root/ks-pre.log
echo > /dev/ttyS0 || true
echo "tmpfsroot-fedora: starting" > /dev/ttyS0 || true
if [ -b /dev/cdrom ]
then
# CDROM install
echo "cdrom" > /tmp/ks.media.cfg
else
# iPXE install
echo "url --url http://172.16.250.1/iso" > /tmp/ks.media.cfg
fi
@@KS.PRE.CFG@@
%end
%pre-install --erroronfail --log=/mnt/sysimage/root/ks-pre-install.log
# Error in pre-install section doesn't trigger %onerror script.
# Manually catch error and output error log to serial port.
set +e
(
set -eu
if [ ! -b /dev/cdrom ]
then
# Make anaconda to use /root2 as rpm download directory
mount -v --bind /mnt/sysimage/root2 /var/tmp
dd if=/dev/zero of=/mnt/sysimage/dummy bs=1k count=10k # Consume rootfs capacity to make root2 choosen
fi
# Make specified UID/GID static
mkdir -vp /tmp/setup
if [ -b /dev/cdrom ]
then
mkdir -v /mnt/cdrom
mount -v /dev/cdrom /mnt/cdrom
repo=/mnt/cdrom/
cp -v /mnt/cdrom/etc-passwd /mnt/cdrom/etc-group /tmp/setup/
else
repo=http://172.16.250.1/iso/
curl http://172.16.250.1/iso/etc-passwd -o /tmp/setup/etc-passwd
curl http://172.16.250.1/iso/etc-group -o /tmp/setup/etc-group
fi
(
# Extract base passwd/group from setup-*.rpm
. /etc/os-release
dnf install \
-y \
--nogpgcheck \
--installroot=/tmp/setup \
--releasever=${VERSION_ID} \
--repofrompath=installer,${repo} \
--repo=installer \
setup
)
cat /tmp/setup/etc-passwd >> /tmp/setup/etc/passwd
cat /tmp/setup/etc-group >> /tmp/setup/etc/group
mkdir -vp /mnt/sysimage/etc
chmod -v 755 /mnt/sysimage/etc
cp -v /tmp/setup/etc/passwd /tmp/setup/etc/group /mnt/sysimage/etc/
chmod -v 544 /mnt/sysimage/etc/passwd /mnt/sysimage/etc/group
rm -vrf /tmp/setup
if [ -b /dev/cdrom ]
then
umount -v /dev/cdrom
fi
@@KS.PRE-INSTALL.CFG@@
)
exit_code=$?
if [ ${exit_code} -ne 0 ]
then
echo "tmpfsroot-fedora: failed" > /dev/ttyS0 || true
exit ${exit_code}
fi
%end
%packages --exclude-weakdeps --excludedocs --inst-langs=en
@^custom-environment
%end
%addon com_redhat_kdump --disable --reserve-mb='128'
%end
# Start post install script without chroot
%post --nochroot --log=/mnt/sysimage/root/ks-post-nochroot.log
set -eu
touch /mnt/sysimage/root/ks-post-nochroot.fail
@@KS.POST-NOCHROOT.CFG@@
rm -v /mnt/sysimage/root/ks-post-nochroot.fail
%end
# Start post install script with chroot
%post --log=/root/ks-post.log
set -eu
if [ -f /root/ks-post-nochroot.fail ]
then
echo "nochroot post install script failed"
false
fi
# Install busybox to add missing commands
/usr/sbin/busybox --install -s
mkdir -vp /tmp/installer
cd /tmp/installer
if [ -b /dev/cdrom ]
then
mkdir -v /mnt/cdrom
mount -v /dev/cdrom /mnt/cdrom
tar vxzf /mnt/cdrom/custom-files.tar.gz
umount -v /mnt/cdrom
rm -vrf /mnt/cdrom
else
rm -vf /dummy
curl -O http://172.16.250.1/iso/custom-files.tar.gz
tar vxzf custom-files.tar.gz
fi
cp -vr root/* /
touch /persist/PROVISIONING
sed -i '/\/persist/s/defaults/defaults,ro/g' /etc/fstab
sed -i '/\/var\/lib\/docker/s/^UUID=\S\+\s\+/LABEL=var_lib_docker /g' /etc/fstab
sed -i '/\/var\/cache/s/^UUID=\S\+\s\+/LABEL=var_cache /g' /etc/fstab
sed -i '/\/opt/s/^UUID=\S\+\s\+/LABEL=opt /g' /etc/fstab
@@KS.POST.CFG@@
# Custom scripts
if [ -d hooks.d ]
then
for script in hooks.d/*.sh
do
${script}
done
fi
# Generate initramfs with tmpfsroot
kernel_version=$(rpm -qa | grep kernel-[0-9] | sed -e 's/kernel-//')
sed -i -e 's/^\(GRUB_CMDLINE_LINUX\)=\"\(.*\)\"/\1="\2 tmpfsroot.size=2G"/' /etc/default/grub
echo "GRUB_DISK_UUID0=64eb4db5-3385-46a5-a3d5-c48197a53555" >> /etc/default/grub
echo "GRUB_DISK_UUID1=d2ada949-7fff-4257-91e9-793b25b0df02" >> /etc/default/grub
grub2-mkconfig > /boot/efi/EFI/fedora/grub.cfg
test ! -h /boot/grub2/grubenv \
&& mv /boot/grub2/grubenv /boot/efi/EFI/fedora/
dracut -v --xz --no-hostonly --force /boot/initramfs-${kernel_version}.img ${kernel_version}
ln -vs /boot/initramfs-${kernel_version}.img /boot/initramfs.img
ln -vs /boot/vmlinuz-${kernel_version} /boot/vmlinuz
# Remove entries from fstab
for mnt in \
\\/root2 \
\\/boot\\/efi
do
sed -i "/${mnt}/d" /etc/fstab
done
# Remove unused mount points
for mnt in \
"/root2"
do
for dir in $(eval ls -1d ${mnt})
do
umount -v ${dir}
rm -vrf ${dir}
done
done
# Remove packages not required runtime
rpm -e --nodeps \
grub2-tools \
pkgconf
# Reduce data size
(cd /usr/share/locale && rm -vrf $(ls -1 | grep -v "^en_US$"))
rm -vrf \
/usr/share/licenses \
/usr/share/man \
/usr/share/doc
# Remove pycache
rm -vr $(find / -name __pycache__)
# Remove build-id data
rm -vr /usr/lib/.build-id
(
# Remove shared objects which are not referenced from any executable and library
mkdir -vp /tmp/lib-cleanup
cd /tmp/lib-cleanup
for i in $(seq 10)
do
(
find /usr -executable -exec file {} \; | grep ': ELF' | cut -d: -f1
find /usr -name '*.so*'
) | xargs -n1 ldd 2> /dev/null \
| sed -n 's/.*\s\(\S*\.so\S*\).*/\1/p' \
| sort | uniq > referenced
(
cat referenced
cat referenced | grep '^/' | xargs -n1 realpath
) | xargs -n1 basename | sort | uniq > refs
find /usr/lib64 -name '*.so.*' -type f | grep '\.so\(\.[0-9]\+\)*$' | sort | uniq > libs.non-ref
cat refs | xargs -n1 -P1 -I{} sed '/\/{}/d' -i libs.non-ref
if [ $(cat libs.non-ref | wc -w) -eq 0 ]
then
break
fi
echo removing $(cat libs.non-ref)
rm -v $(cat libs.non-ref)
done
# Remove broken symlinks
find /usr/lib64 -name '*.so*' -type l ! -exec test {} \; -delete
rm -vrf /tmp/lib-cleanup
)
ldconfig
journalctl --update-catalog
cd
rm -vrf /tmp/installer
echo > /dev/ttyS0 || true
echo "tmpfsroot-fedora: succeeded" > /dev/ttyS0 || true
%end
# Output error to serial console
%onerror
echo > /dev/ttyS0 || true
echo "tmpfsroot-fedora: failed" > /dev/ttyS0 || true
%end