forked from theforeman/foreman-discovery-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
25-minimize.ks
99 lines (79 loc) · 3.51 KB
/
25-minimize.ks
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
# Minimize the image by dropping some unnecessary data like i18n or man pages
# vim: set ft=bash:sw=2:ts=2:et
#
# Some ideas from:
#
# https://github.com/weldr/lorax/blob/rhel7-branch/share/runtime-cleanup.tmpl
#
%post
# Ensure we don't have the same random seed on every image, which
# could be bad for security at a later point...
echo " * purge existing random seed to avoid identical seeds everywhere"
rm -f /var/lib/random-seed
echo " * disable sshd and purge existing SSH host keys"
rm -f /etc/ssh/ssh_host_*key{,.pub}
systemctl disable sshd.service
# This seems to cause 'reboot' resulting in a shutdown on certain platforms
# See https://tickets.puppetlabs.com/browse/RAZOR-100
echo " * remove intel mei modules"
rm -rf /lib/modules/*/kernel/drivers/misc/mei
# See https://bugzilla.redhat.com/show_bug.cgi?id=1335830
echo " * remove some video drivers to prevent kexec isues"
rm -rf /lib/modules/*/kernel/drivers/gpu/drm \
/lib/modules/*/kernel/drivers/video/fbdev \
/lib/firmware/{amdgpu,radeon}
echo " * remove unused drivers (sound, media, nls, fs, wifi)"
rm -rf /lib/modules/*/kernel/sound \
/lib/modules/*/kernel/drivers/{media,hwmon,watchdog,rtc,input/joystick,bluetooth,edac} \
/lib/modules/*/kernel/net/{atm,bluetooth,sched,sctp,rds,l2tp,decnet} \
/lib/modules/*/kernel/fs/{nls,ocfs2,ceph,nfsd,ubifs,nilfs2} \
/lib/modules/*/kernel/arch/x86/kvm
echo " * remove unused firmware (sound, wifi)"
rm -rf /usr/lib/firmware/*wifi* \
/usr/lib/firmware/v4l* \
/usr/lib/firmware/dvb* \
/usr/lib/firmware/{yamaha,korg,liquidio,emu,dsp56k,emi26} \
/usr/lib/firmware/{ath9k,ath10k}
echo " * dropping big and compressing small cracklib dict"
mv -f /usr/share/cracklib/cracklib_small.hwm /usr/share/cracklib/pw_dict.hwm
mv -f /usr/share/cracklib/cracklib_small.pwd /usr/share/cracklib/pw_dict.pwd
mv -f /usr/share/cracklib/cracklib_small.pwi /usr/share/cracklib/pw_dict.pwi
gzip -9 /usr/share/cracklib/pw_dict.pwd
# 100MB of locale archive is kind unnecessary; we only do en_US.utf8
# this will clear out everything we don't need; 100MB => 2.1MB.
echo " * minimizing locale-archive binary / memory size"
localedef --list-archive | grep -Eiv '(en_US|fdi)' | xargs localedef -v --delete-from-archive
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
/usr/sbin/build-locale-archive
echo " * purging all other locale data"
ls -d /usr/share/locale/* | grep -v fdi | xargs rm -rf
echo " * purging images"
rm -rf /usr/share/backgrounds/* /usr/share/kde4/* /usr/share/anaconda/pixmaps/rnotes/*
echo " * purging rubygems cache"
rm -rf /usr/share/gems/cache/*
echo " * truncating various logfiles"
for log in yum.log dracut.log lastlog yum.log; do
truncate -c -s 0 /var/log/${log}
done
echo " * removing /boot, since that lives on the ISO side"
rm -rf /boot*
echo " * removing trusted CA certificates"
truncate -s0 /usr/share/pki/ca-trust-source/ca-bundle.trust.crt
update-ca-trust
echo " * setting up hostname"
echo fdi > /etc/hostname
echo " * locking root account"
passwd -l root
echo " * store list of packages sorted by size"
rpm -qa --queryformat '%{SIZE} %{NAME} %{VERSION}%{RELEASE}\n' | sort -n -r > /usr/PACKAGES-LIST
echo " * cleaning up yum cache and removing rpm database"
yum clean all
rm -rf /var/lib/{yum,rpm}/*
# no more python loading after this step
echo " * removing python precompiled *.pyc files"
find /usr/lib64/python*/ /usr/lib/python*/ -name *py[co] -print0 | xargs -0 rm -f
%end
%post --nochroot
echo " * disquieting the boot process"
sed -i -e's/ rhgb//g' -e's/ quiet//g' $LIVE_ROOT/isolinux/isolinux.cfg
%end