Last active
June 8, 2017 13:35
-
-
Save aspring/d4b8815cc3608db4ee94 to your computer and use it in GitHub Desktop.
Centos-6-AMI-Kickstart.ks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This kickstart file is aimed towards creating a Centos 6.5 Amazon AMI | |
skipx | |
text | |
install | |
lang en_US.UTF-8 | |
keyboard us | |
timezone America/New_York | |
auth --useshadow --enablemd5 | |
authconfig --enableshadow --passalgo=sha512 | |
rootpw --iscrypted * | |
selinux --disabled | |
network --onboot yes --device eth0 --bootproto dhcp | |
firewall --enabled --service=ssh | |
# Hard Disk Configuration | |
bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto" | |
clearpart --all --initlabel | |
part / --fstype=ext4 --grow --size=200 | |
# Centos URL and Repos | |
url --url=http://mirror.centos.org/centos/6.5/os/x86_64/ | |
repo --name=epel --baseurl=http://mirrors.rit.edu/fedora/epel/6/x86_64/ | |
repo --name=updates --baseurl=http://mirror.centos.org/centos/6.5/updates/x86_64/ | |
# System services | |
services --disabled="avahi-daemon,iscsi,iscsid,firstboot,kdump" --enabled="network,sshd,rsyslog,tuned,acpid" | |
# We want to shutdown after completed | |
shutdown | |
# | |
# PACKAGES BLOCK | |
# | |
%packages --nobase | |
@Core | |
# Add EPEL | |
epel-release | |
# Package used by the provisioners | |
wget | |
openssh-clients | |
openssh-server | |
ntp | |
# Install these here so they match the version of the kernel we are running | |
kernel-devel | |
kernel-headers | |
# Bring in the cloud utils we need | |
cloud-init | |
# Various packers we want | |
e2fsprogs | |
# Various packages we do not want | |
-*-firmware | |
-NetworkManager | |
-b43-openfwwf | |
-biosdevname | |
-fprintd | |
-fprintd-pam | |
-gtk2 | |
-libfprint | |
-mcelog | |
-plymouth | |
-redhat-support-tool | |
-system-config-* | |
-wireless-tools | |
%end | |
# | |
# POST BLOCK | |
# | |
%post | |
# allow sudo powers to ec2-user | |
echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers | |
# lock root password | |
passwd -d root | |
passwd -l root | |
# Disable firstboot | |
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot | |
# set virtual-guest as default profile for tuned | |
echo "virtual-guest" > /etc/tune-profiles/active-profile | |
# prevent udev rules from remapping nics | |
touch /etc/udev/rules.d/75-persistent-net-generator.rules | |
# cloud-init is not able to expand the partition to match the new vdisk size, we need to work around it from the initramfs, before the filesystem gets mounted | |
# to accomplish this we need to generate a custom initrd | |
cat << EOF > 05-extend-rootpart.sh | |
#!/bin/sh | |
/bin/echo | |
/bin/echo RESIZING THE PARTITION | |
/bin/echo "d | |
n | |
p | |
1 | |
2048 | |
w | |
" | /sbin/fdisk -c -u /dev/xvda | |
/sbin/e2fsck -f /dev/xvda1 | |
/sbin/resize2fs /dev/xvda1 | |
EOF | |
chmod +x 05-extend-rootpart.sh | |
dracut --force --include 05-extend-rootpart.sh /mount --install 'echo fdisk e2fsck resize2fs' /boot/"initramfs-extend_rootpart-\$(ls /boot/|grep initramfs|sed s/initramfs-//g)" \$(ls /boot/|grep vmlinuz|sed s/vmlinuz-//g) | |
rm -f 05-extend-rootpart.sh | |
tail -4 /boot/grub/grub.conf | sed s/initramfs/initramfs-extend_rootpart/g| sed s/CentOS/ResizePartition/g | sed s/crashkernel=auto/crashkernel=0@0/g >> /boot/grub/grub.conf | |
# let's run the kernel & initramfs that expands the partition only once | |
echo "savedefault --default=1 --once" | grub --batch | |
# Fix some first boot issues | |
rpm --rebuilddb | |
touch /.autorelabel | |
# Fix hostname on boot | |
sed -i -e 's/\(preserve_hostname:\).*/\1 False/' /etc/cloud/cloud.cfg | |
sed -i '/HOSTNAME/d' /etc/sysconfig/network | |
rm /etc/hostname | |
# DHCP provides resolv.conf | |
echo "" > /etc/resolv.conf | |
# Use label for fstab, not UUID | |
e2label /dev/xvda1 "/" | |
sed -i -e 's?^UUID=.* / .*?LABEL=/ / ext4 defaults,relatime 1 1?' /etc/fstab | |
# PVGRUB uses hd0 not hd0,0, use label | |
sed -i -e 's/\(hd0\),0/\1/' -e 's?UUID=[^ ]*?LABEL=/?' -e 's/rhgb quiet//' /boot/grub/menu.lst | |
# Remove all mac address references | |
sed -i '/HWADDR/d' etc/sysconfig/network-scripts/ifcfg-eth0 | |
sed -i '/HOSTNAME/d' etc/sysconfig/network-scripts/ifcfg-eth0 | |
# SSH login key based only | |
sed -i -e 's/^\(PasswordAuthentication\) yes/\1 no/' /etc/ssh/sshd_config | |
# Clean up | |
yum clean all | |
rm -f /root/anaconda-ks.cfg | |
rm -f /root/install.log | |
rm -f /root/install.log.syslog | |
find /var/log -type f -delete | |
%end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
trying to use the resulted image and i get this...
root (hd0)
Filesystem type unknown, using whole disk
kernel /boot/vmlinuz-2.6.32-642.1.1.el6.x86_64 ro root=LABEL=/ rd_NO_LUKS rd_NO
_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto console=ttyS0,115200n8 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM
Error 17: Cannot mount selected partition
any idea? centos6.8
Cheers