Skip to content

Instantly share code, notes, and snippets.

@c0mpiler
Last active June 7, 2020 19:13
Show Gist options
  • Save c0mpiler/ca6e400140da1cae519f to your computer and use it in GitHub Desktop.
Save c0mpiler/ca6e400140da1cae519f to your computer and use it in GitHub Desktop.
Kickstart centos7 installation
# CentOS 7.0 kickstart for XenServer
# branch: develop
##########################################
# Install, not upgrade
install
# Install from a friendly mirror and add updates
url --url http://mirror.rackspace.com/CentOS/7.0.1406/os/x86_64/
repo --name=centos-updates --mirrorlist=http://mirrorlist.centos.org/?release=7.0.1406&arch=x86_64&repo=updates
# Language and keyboard setup
lang en_US.UTF-8
keyboard us
# Configure networking without IPv6, firewall off
# for STATIC IP: uncomment and configure
network --onboot=yes --device=eth0 --bootproto=static --ip=192.168.81.199 --netmask=255.255.255.0 --gateway=192.168.81.1 --nameserver=192.168.81.1 --noipv6 --hostname=manager
# for DHCP:
#network --bootproto=dhcp --device=eth0 --onboot=on
firewall --enabled --ssh
# Set timezone
timezone America/Los_Angeles
# Authentication
rootpw --lock
# if you want to preset the root password in a public kickstart file, use SHA512crypt e.g.
# rootpw --iscrypted $6$9dC4m770Q1o$FCOvPxuqc1B22HM21M5WuUfhkiQntzMuAV7MY0qfVcvhwNQ2L86PcnDWfjDd12IFxWtRiTuvO/niB0Q3Xpf2I.
user --name=harsha --password=Asdfqwerty --plaintext --gecos="CentOS User" --shell=/bin/bash --groups=user,wheel, root
# if you want to preset the user password in a public kickstart file, use SHA512crypt e.g.
# user --name=centos --password=$6$9dC4m770Q1o$FCOvPxuqc1B22HM21M5WuUfhkiQntzMuAV7MY0qfVcvhwNQ2L86PcnDWfjDd12IFxWtRiTuvO/niB0Q3Xpf2I. --iscrypted --gecos="CentOS User" --shell=/bin/bash --groups=user,wheel
authconfig --enableshadow --passalgo=sha512
# SELinux enabled
selinux --enforcing
# Disable anything graphical
skipx
text
eula --agreed
# Setup the disk
zerombr
clearpart --all --drives=xvda
part /boot --fstype=ext3 --size=500 --asprimary
part / --fstype=ext4 --grow --size=1024 --asprimary
bootloader --timeout=5 --driveorder=xvda --append="console=hvc0"
# Shutdown when the kickstart is done
halt
# Minimal package set
%packages --excludedocs
@base
@network-file-system-client
deltarpm
yum-plugin-fastestmirror
dracut-config-generic
-dracut-config-rescue
-plymouth
-fprintd-pam
-wireless-tools
-NetworkManager
-NetworkManager-tui
-*-firmware
%end
%post --log=/root/ks-post.log
echo -n "Network fixes"
# initscripts don't like this file to be missing.
cat > /etc/sysconfig/network << EOF
NETWORKING=yes
NOZEROCONF=yes
EOF
echo -n "."
# For cloud images, 'eth0' _is_ the predictable device name, since
# we don't want to be tied to specific virtual (!) hardware
rm -f /etc/udev/rules.d/70*
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
echo -n "."
# simple eth0 config, again not hard-coded to the build hardware
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE="eth0"
BOOTPROTO="static"
ONBOOT="yes"
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
IPADDR="192.168.81.199"
NETMASK="255.255.255.0"
GATEWAY="192.168.81.1"
EOF
echo -n "."
# generic localhost names
cat > /etc/hosts << EOF
127.0.0.1 localhost
127.0.1.1 manager
192.168.81.100 puppet
192.168.81.101 ubuntu01
192.168.81.102 ubuntu02
192.168.81.103 ubuntu03
192.168.81.104 ubuntu04
192.168.81.105 ubuntu05
192.168.81.106 ubuntu06
192.168.81.107 ubuntu07
192.168.81.108 ubuntu08
192.168.81.109 ubuntu09
192.168.81.110 ubuntu10
192.168.81.111 ubuntu11
192.168.81.112 ubuntu12
192.168.81.113 ubuntu13
192.168.81.114 ubuntu14
192.168.81.115 ubuntu15
192.168.81.116 ubuntu16
192.168.81.117 ubuntu17
192.168.81.118 ubuntu18
192.168.81.119 ubuntu19
192.168.81.120 ubuntu20
192.168.81.121 ubuntu21
192.168.81.122 ubuntu22
192.168.81.123 ubuntu23
192.168.81.124 ubuntu24
192.168.81.125 ubuntu25
192.168.81.126 ubuntu26
192.168.81.127 ubuntu27
192.168.81.128 ubuntu28
192.168.81.129 ubuntu29
192.168.81.130 ubuntu30
192.168.81.131 ubuntu31
192.168.81.132 ubuntu32
192.168.81.133 ubuntu33
192.168.81.134 ubuntu34
192.168.81.135 ubuntu35
192.168.81.136 ubuntu36
192.168.81.137 ubuntu37
192.168.81.138 ubuntu38
192.168.81.139 ubuntu39
192.168.81.140 ubuntu40
192.168.81.141 ubuntu41
192.168.81.142 ubuntu42
192.168.81.143 ubuntu43
192.168.81.144 ubuntu44
192.168.81.145 ubuntu45
192.168.81.146 ubuntu46
192.168.81.147 ubuntu47
192.168.81.148 ubuntu48
192.168.81.149 ubuntu49
192.168.81.150 ubuntu50
192.168.81.151 node0
192.168.81.152 node1
192.168.81.153 node2
192.168.81.154 node3
192.168.81.155 node4
192.168.81.199 manager
EOF
echo -n "."
# since NetworkManager is disabled, need to enable normal networking
chkconfig network on
echo .
# utility script
echo -n "Utility scripts"
echo "== Utility scripts ==" >> /root/ks-post.debug.log
wget -O /opt/domu-hostname.sh https://github.com/frederickding/xenserver-kickstart/raw/develop/opt/domu-hostname.sh 2>> /root/ks-post.debug.log
chmod +x /opt/domu-hostname.sh
echo .
# remove unnecessary packages
echo -n "Removing unnecessary packages"
echo "== Removing unnecessary packages ==" >> /root/ks-post.debug.log
yum -C -y remove linux-firmware >> /root/ks-post.debug.log 2&>1
echo .
# generalization
echo -n "Generalizing"
rm -f /etc/ssh/ssh_host_*
echo .
# fix boot for older pygrub/XenServer
# you should comment out this entire section if on XenServer Creedence/Xen 4.4
echo -n "Fixing boot"
echo "== GRUB fixes ==" >> /root/ks-post.debug.log
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
cp /etc/default/grub /etc/default/grub.bak
cp --no-preserve=mode /etc/grub.d/00_header /etc/grub.d/00_header.bak
sed -i 's/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/' /etc/default/grub
sed -i 's/default="\\${next_entry}"/default="0"/' /etc/grub.d/00_header
echo -n "."
cp --no-preserve=mode /etc/grub.d/10_linux /etc/grub.d/10_linux.bak
sed -i 's/${sixteenbit}//' /etc/grub.d/10_linux
echo -n "."
grub2-mkconfig -o /boot/grub2/grub.cfg >> /root/ks-post.debug.log 2&>1
echo .
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment