forked from 2creatives/vagrant-centos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ks.cfg
234 lines (174 loc) · 6.37 KB
/
ks.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
install
cdrom
lang en_US.UTF-8
keyboard us
timezone --utc Etc/UTC
cmdline
network --device eth0 --bootproto dhcp
firewall --disabled
selinux --disabled
authconfig --enableshadow --passalgo=sha512
zerombr
bootloader --location=mbr --driveorder=sda --append="clocksource_failover=acpi_pm"
clearpart --all --initlabel --drives=sda,sdb
part / --ondisk sda --grow --size 2000 --asprimary --fstype=ext4
part swap --ondisk sdb --grow --size 100
firstboot --disabled
rootpw --plaintext vagrant
reboot
%packages --instLangs=en_US.utf8 --nobase
-efibootmgr
%post --log=/root/install-post.log
set -x
alias yum='yum --releasever=6.5'
echo %_install_langs en_US.utf8 >> /etc/rpm/macros
# No fsck at boot
sed -i -r 's/(defaults\s+)1 1/\10 0/' /etc/fstab
# Create vagrant user
groupadd vagrant
useradd vagrant -g vagrant -G wheel
echo "vagrant" | passwd --stdin vagrant
# Install vagrant keys
mkdir -p /home/vagrant/.ssh
cat <<EOM >/home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8Y\
Vr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdO\
KLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7Pt\
ixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmC\
P3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW\
yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
EOM
chown -R vagrant:vagrant /home/vagrant/.ssh
chmod -R u=rwX,go= /home/vagrant/.ssh
# Import key first so that yum doesn't complain later.
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# bzr, mercurial : source control
# kernel-devel : VirtualBox Guest Additions.
# man : tools are never consistent across platforms.
# nfs-utils : Vagrant's shared folders.
# yum-utils : package-cleanup command.
yum shell -y <<EOM
config exclude cscope ctags doxygen intltool systemtap
update
groupinstall "Development Tools"
install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
install bzr kernel-devel man mercurial nfs-utils yum-utils
install yum-plugin-versionlock
run
EOM
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
sed -i '/.*requiretty/d' /etc/sudoers
echo '%wheel ALL=NOPASSWD: ALL' >> /etc/sudoers
# Squash the delay on boot
sed -i '/splashimage/d;s_timeout.*$_timeout=0_;s/ rhgb quiet//g' \
/boot/grub/grub.conf
# Hotplug always tries to load this and it doesn't play well with
# VirtualBox. Always complains to upgrade BIOS.
echo 'blacklist i2c_piix4' >>/etc/modprobe.d/blacklist.conf
# Setup network devices.
rm /etc/udev/rules.d/70-persistent-net.rules
echo '#' >/etc/udev/rules.d/75-persistent-net-generator.rules
cat <<EOM >/etc/sysconfig/network
HOSTNAME=vagrant-centos65.vagrantup.com
NETWORKING=yes
EOM
cat <<EOM >/etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
DEVICE=eth0
DHCP_HOSTNAME=vagrant-centos65.vagrantup.com
IPV6INIT=yes
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
EOM
echo "options single-request-reopen" >>/etc/resolv.conf
cat <<EOM >>/etc/hosts
127.0.0.1 vagrant-centos65.vagrantup.com vagrant-centos65
::1 vagrant-centos65.vagrantup.com vagrant-centos65
EOM
sed -i -r 's/#(UseDNS).*/\1 no/' /etc/ssh/sshd_config
chkconfig --level 2345 auditd off
chkconfig --level 2345 crond off
chkconfig --level 345 netfs off
chkconfig --level 345 nfslock off
chkconfig --level 2345 rpcbind off
chkconfig --level 345 rpcgssd off
chkconfig --level 345 rpcidmapd off
chkconfig --level 2345 sshd off
# Delete language support.
rm -rf /usr/share/locale/*/LC_MESSAGES/
localedef --list-archive | \
grep -vE '^en_US.*' | \
xargs localedef --delete-from-archive
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
build-locale-archive
# After this cat reboot to that latest kernel, install Guest Additions
# and clean up the system so that it can be packed down.
# This section is weird as you need to escape $, `, \, etc.
cat <<EOM >/etc/rc.local
#!/bin/sh -x
touch /var/lock/subsys/local
alias yum='yum --releasever=6.5'
# If the kernel has been upgraded, remove old versions.
package-cleanup -y --oldkernel --count=1
# Don't upgrade the kernel files after this point.
# VirtualBox Guest Additions will break if it is upgraded.
yum versionlock kernel kernel-devel kernel-doc kernel-firmware kernel-headers
# VirtualBox Guest Additions
# The "Window System drivers" step will fail which is fine because we
# don't have Xorg
mount -o ro \`find /dev/disk/by-label | grep VBOXADDITIONS\` /mnt/
/mnt/VBoxLinuxAdditions.run
chkconfig vboxadd-x11 off
umount /mnt/
# kernel-devel : Installed for VirtualBox Guest Additions
yum shell -y <<EOF
remove kernel-devel
run
EOF
# Rebuild the initrd to include only what's needed.
dracut -f -H
yum clean all # Remove yum's cache files.
rpm --rebuilddb
EMAIL=root
# Send a summary of what happened in the installation.
FILES=\`ls /var/log/boot.log /root/install-post.log \\
/root/install.log /root/install.log.syslog\`
(echo -en "To: \${EMAIL}\\r\\n" ;
echo -en "Subject: CentOS Installation Summary\\r\\n\\r\\n" ;
echo -en "Full package list:\\r\\n\\r\\n" ;
rpm -qa | sort ;
for f in \${FILES}; do
echo -en "\\r\\n\\r\\n\$f:\\r\\n\\r\\n" ;
sed 's/^/ /' \$f && rm -f \$f ;
done ) | sendmail \${EMAIL}
sleep 10 # Give postfix a bit of time to send the email.
service postfix stop # Kill postfix so we can clear logs.
rm -f /var/log/dmesg.old /var/log/anaconda.ifcfg.log \\
/var/log/anaconda.log /var/log/anaconda.program.log \\
/var/log/anaconda.storage.log /var/log/anaconda.syslog \\
/var/log/anaconda.yum.log /root/anaconda-ks.cfg \\
/var/log/vboxadd-install.log /var/log/vbox-install-x11.log \\
/var/log/VBoxGuestAdditions.log /var/log/vboxadd-install-x11.log
echo -n | tee /var/log/dmesg /var/log/maillog /var/log/lastlog \\
/var/log/secure /var/log/yum.log >/var/log/cron
chkconfig --level 2345 auditd on
chkconfig --level 2345 crond on
chkconfig --level 345 netfs on
chkconfig --level 345 nfslock on
chkconfig --level 2345 rpcbind on
chkconfig --level 345 rpcgssd on
chkconfig --level 345 rpcidmapd on
chkconfig --level 2345 sshd on
rm -rf /tmp/* /tmp/.[^.]+
dd if=/dev/zero of=/tmp/clean bs=1M || rm -f /tmp/clean
swapuuid=\`blkid -o value -l -s UUID -t TYPE=swap\`
swappart=\`readlink -f /dev/disk/by-uuid/\$swapuuid\`
swapoff \$swappart
dd if=/dev/zero of=\$swappart bs=1M
mkswap -U \$swapuuid \$swappart
cat <<EOF >/etc/rc.local && poweroff
#!/bin/sh
touch /var/lock/subsys/local
EOF
EOM