Skip to content

Instantly share code, notes, and snippets.

@pyKun
Last active February 10, 2022 18:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyKun/5562778 to your computer and use it in GitHub Desktop.
Save pyKun/5562778 to your computer and use it in GitHub Desktop.
Worked kickstart file for a standard centos
# centos_minimal_livecd.ks
# Created by AndrewSerk
part / --size 8192 --fstype ext4
lang en_US.UTF-8
keyboard us
timezone US/Eastern
auth --useshadow --enablemd5
selinux --disabled
firewall --disabled
# Root password
#rootpw --iscrypted
repo --name=a-live --baseurl=http://www.nanotechnologies.qc.ca/propos/linux/centos-live/$basearch/live
repo --name=a-base --baseurl=http://mirrors.163.com/centos/6.4/os/x86_64/
repo --name=updates --baseurl=http://mirrors.163.com/centos/6.4/updates/x86_64/
#repo --name=centos --baseurl=http://mirrors.centos.com/ustack/RPMS/x86_64/
%packages
bash
kernel
syslinux
passwd
policycoreutils
chkconfig
authconfig
rootfiles
comps-extras
xkeyboard-config
system-config-firewall-base
# livecd bits to set up the livecd and be able to install
anaconda
device-mapper-multipath
isomd5sum
wget
%end
########################################################################
#
# LiveCD post install in chroot
#
########################################################################
%post
#***********************************************************************
# Create LiveCD configuration file and LiveCD functions
#***********************************************************************
cat > /etc/livesys.conf << 'EOF_livesysconf'
#--------------------------------------------------------------------
# Configuration file for LiveCD
#--------------------------------------------------------------------
# Services which are off (not running) on the LiveCD
SERVICES_OFF="mdmonitor setroubleshoot auditd crond atd readahead_early \
readahead_later kdump microcode_ctl openct pcscd postfix \
yum-updatesd"
# Services which should be on, but are not on per default
SERVICES_ON=""
EOF_livesysconf
cat > /etc/init.d/livesys.functions << 'EOF_livesysfunctions'
#--------------------------------------------------------------------
# livesys functions
#--------------------------------------------------------------------
# egrep_o is a replacement for "egrep -o". It prints only the last matching text
egrep_o() {
cat | egrep "$1" | sed -r "s/.*($1).*/\\1/"
}
# boot parameter
cmdline_parameter() {
CMDLINE=/proc/cmdline
cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1(\$|=|[[:space:]]+)" | egrep_o "$1"
}
# boot parameter value
cmdline_value()
{
CMDLINE=/proc/cmdline
cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1=([^[:space:]]+)" | egrep_o "=.*" | cut -b 2- | tail -n 1
}
exists() {
which $1 >/dev/null 2>&1 || return
$*
}
EOF_livesysfunctions
#***********************************************************************
# Create /root/post-install
# Must change "$" to "\$" and "`" to "\`" to avoid shell quoting
#***********************************************************************
cat > /root/post-install << EOF_post
#!/bin/bash
#***********************************************************************
# Create the livesys init script - /etc/rc.d/init.d/livesys
#***********************************************************************
echo "Creating the livesys init script - livesys"
cat > /etc/rc.d/init.d/livesys << EOF_initscript
#!/bin/bash
#
# live: Init script for live image
#
# chkconfig: 345 00 99
# description: Init script for live image.
. /etc/init.d/functions
. /etc/livesys.conf
. /etc/init.d/livesys.functions
# exit if not running from LiveCD
if [ ! "\\\$( cmdline_parameter liveimg )" ] || [ "\\\$1" != "start" ]; then
exit 0
fi
[ -e /.liveimg-configured ] && configdone=1
touch /.liveimg-configured
### read boot parameters out of /proc/cmdline
# hostname
hostname=\\\$( cmdline_value hostname )
# afs cell
CELL=\\\$( cmdline_value cell )
# services to turn on / off
SERVICEON=\\\$( cmdline_value serviceon )
SERVICEOFF=\\\$( cmdline_value serviceoff )
# cups server
CUPS=\\\$( cmdline_value cups )
# password
PW=\\\$( cmdline_value pw )
[ ! \\\$PW ] && PW=\\\$( cmdline_value passwd )
### mount live image
if [ -b \\\`readlink -f /dev/live\\\` ]; then
mkdir -p /mnt/live
mount -o ro /dev/live /mnt/live 2>/dev/null || mount /dev/live /mnt/live
fi
livedir=\\\$( cmdline_value live_dir )
[ ! "\\\$livedir" ] && livedir="LiveOS"
### enable swaps unless requested otherwise
swaps=\\\`blkid -t TYPE=swap -o device\\\`
if [ ! "\\\$( cmdline_parameter noswap )" ] && [ -n "\\\$swaps" ] ; then
for s in \\\$swaps ; do
action "Enabling swap partition \\\$s" swapon \\\$s
done
fi
if [ ! "\\\$( cmdline_parameter noswap )" ] && [ -f /mnt/live/\\\${livedir}/swap.img ] ; then
action "Enabling swap file" swapon /mnt/live/\\\${livedir}/swap.img
fi
### make it so that we don't do writing to the overlay for things which
### are just tmpdirs/caches
mount -t tmpfs -o mode=0755 varcacheyum /var/cache/yum
mount -t tmpfs tmp /tmp
mount -t tmpfs vartmp /var/tmp
[ -x /sbin/restorecon ] && /sbin/restorecon /var/cache/yum /tmp /var/tmp >/dev/null 2>&1
### set afs cell if given by boot parameter
if [ "\\\$CELL" ]; then
[ -e /usr/vice/etc/ThisCell ] && echo \\\$CELL > /usr/vice/etc/ThisCell
fi
### set cups server
if [ "\\\$CUPS" ]; then
if [ -e /etc/cups/client.conf ]; then
sed -i "s|.*ServerName .*|ServerName \\\$CUPS|" /etc/cups/client.conf
grep -q ServerName /etc/cups/client.conf || echo "ServerName \\\$CUPS" >> /etc/cups/client.conf
fi
fi
### set the LiveCD hostname
[ ! "\\\$hostname" ] && hostname="livecd.localdomain"
sed -i -e "s|HOSTNAME=.*|HOSTNAME=\\\$hostname|g" /etc/sysconfig/network
/bin/hostname \\\$hostname
#-----------------------------------------------------------------------
# EXIT here if LiveCD has already been configured
# happens if you start the LiveCD with persistent changes
#-----------------------------------------------------------------------
[ "\\\$configdone" ] && exit 0
### turn off services, which are not useful on LiveCD, to preserve resources
if [ "\\\$SERVICES_OFF" ]; then
for service in \\\$SERVICES_OFF ; do
[ -f /etc/init.d/\\\$service ] && chkconfig \\\$service off 2>/dev/null
done
fi
### turn on services, which are off by default
if [ "\\\$SERVICES_ON" ]; then
for service in \\\$SERVICES_ON ; do
[ -f /etc/init.d/\\\$service ] && chkconfig \\\$service ofn 2>/dev/null
done
fi
### services off, from command line parameter (turn it off once again)
if [ "\\\$SERVICEOFF" ]; then
for service in \\\$( echo "\\\$SERVICEOFF" | tr ':' ' ' ); do
[ -f /etc/init.d/\\\$service ] && chkconfig \\\$service off 2>/dev/null
done
fi
# services on, from command line parameter (turn it ofn once again)
if [ "\\\$SERVICEON" ]; then
for service in \\\$( echo "\\\$SERVICEON" | tr ':' ' ' ); do
[ -f /etc/init.d/\\\$service ] && chkconfig \\\$service on 2>/dev/null
done
fi
### fix various bugs and issues
# unmute sound card
exists alsaunmute 0 2> /dev/null
# turn off firstboot for livecd boots
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot
# start afs with option -memcache (gets a kernel panic on some system - do not use it for the moment)
# [ -e /etc/sysconfig/afs ] && sed -i "s|^OPTIONS=.*|OPTIONS=\"-memcache\"|" /etc/sysconfig/afs
# Stopgap fix for RH #217966; should be fixed in HAL instead
touch /media/.hal-mtab
### set root password to no password (remove these lines if using "rootpw --iscrypted" )
if [ "\\\$PW" ]; then
echo \\\$PW | passwd --stdin root >/dev/null
fi
### start system-config-firewall with su
# (bugfix: system-config-firewall does not work when root has no password)
sed -i "s|^Exec=.*|Exec=su - -c /usr/bin/system-config-firewall|" /usr/share/applications/system-config-firewall.desktop
sed -i "s|^Terminal=.*|Terminal=true|" /usr/share/applications/system-config-firewall.desktop
### don't use prelink on a running live image
sed -i 's/PRELINKING=yes/PRELINKING=no/' /etc/sysconfig/prelink &>/dev/null
###-----------------------------------------------------------------------
# detecting disk partitions and logical volumes (disabled by default)
# use boot parameter automount to enable it
###-----------------------------------------------------------------------
# mount disk partitions if 'automount' is given as a boot option
if [ "\\\$( cmdline_parameter automount )" ]; then
MOUNTOPTION="rw"
HARD_DISKS=\\\`egrep "[sh]d.\\\$" /proc/partitions | tr -s ' ' | sed 's/^ *//' | cut -d' ' -f4\\\`
echo "Mounting hard disk partitions... "
for DISK in \\\$HARD_DISKS; do
# Get the device and system info from fdisk (but only for fat and linux partitions).
FDISK_INFO=\\\`fdisk -l /dev/\\\$DISK | tr [A-Z] [a-z] | egrep "fat|linux" | egrep -v "swap|extended|lvm" | sed 's/*//' | tr -s ' ' | tr ' ' ':' | cut -d':' -f1,6-\\\`
for FDISK_ENTRY in \\\$FDISK_INFO; do
PARTITION=\\\`echo \\\$FDISK_ENTRY | cut -d':' -f1\\\`
MOUNTPOINT="/mnt/disc/\\\${PARTITION##/dev/}"
mkdir -p \\\$MOUNTPOINT
MOUNTED=FALSE
# get the partition type
case \\\`echo \\\$FDISK_ENTRY | cut -d':' -f2-\\\` in
*fat*)
FSTYPES="vfat"
EXTRAOPTIONS=",uid=500";;
*)
FSTYPES="ext4 ext3 ext2"
EXTRAOPTIONS="";;
esac
# try to mount the partition
for FSTYPE in \\\$FSTYPES; do
if mount -o "\\\${MOUNTOPTION}\\\${EXTRAOPTIONS}" -t \\\$FSTYPE \\\$PARTITION \\\$MOUNTPOINT &>/dev/null; then
echo "\\\$PARTITION \\\$MOUNTPOINT \\\$FSTYPE noauto,\\\${MOUNTOPTION}\\\${EXTRAOPTIONS} 0 0" >> /etc/fstab
echo -n "\\\$PARTITION "
MOUNTED=TRUE
CreateDesktopIconHD
fi
done
[ \\\$MOUNTED = "FALSE" ] && rmdir \\\$MOUNTPOINT
done
done
echo
fi
# mount logical volumes if 'automount' is given as a boot option
if [ "\\\$( cmdline_parameter automount )" ]; then
MOUNTOPTION="rw"
FSTYPES="ext4 ext3 ext2"
echo "Scanning for logical volumes..."
if ! lvm vgscan 2>&1 | grep "No volume groups"; then
echo "Activating logical volumes ..."
modprobe dm_mod >/dev/null
lvm vgchange -ay
LOGICAL_VOLUMES=\\\`lvm lvdisplay -c | sed "s/^ *//" | cut -d: -f1\\\`
if [ ! -z "\\\$LOGICAL_VOLUMES" ]; then
echo "Making device nodes ..."
lvm vgmknodes
echo -n "Mounting logical volumes ... "
for VOLUME_NAME in \\\$LOGICAL_VOLUMES; do
VG_NAME=\\\`echo \\\$VOLUME_NAME | cut -d/ -f3\\\`
LV_NAME=\\\`echo \\\$VOLUME_NAME | cut -d/ -f4\\\`
MOUNTPOINT="/mnt/lvm/\\\${VG_NAME}-\\\${LV_NAME}"
mkdir -p \\\$MOUNTPOINT
MOUNTED=FALSE
for FSTYPE in \\\$FSTYPES; do
if mount -o \\\$MOUNTOPTION -t \\\$FSTYPE \\\$VOLUME_NAME \\\$MOUNTPOINT &>/dev/null; then
echo "\\\$VOLUME_NAME \\\$MOUNTPOINT \\\$FSTYPE defaults,\\\${MOUNTOPTION} 0 0" >> /etc/fstab
echo -n "\\\$VOLUME_NAME "
MOUNTED=TRUE
CreateDesktopIconLVM
break
fi
done
[ \\\$MOUNTED = FALSE ] && rmdir \\\$MOUNTPOINT
done
echo
else
echo "No logical volumes found"
fi
fi
fi
EOF_initscript
#***********************************************************************
# End of livesys script
#***********************************************************************
#***********************************************************************
# Create the livesys init script - /etc/rc.d/init.d/livesys-late
#***********************************************************************
echo "Creating the livesys init script - livesys-late"
cat > /etc/rc.d/init.d/livesys-late << EOF_lateinitscript
#!/bin/bash
#
# live: Late init script for live image
#
# chkconfig: 345 99 01
# description: Late init script for live image.
. /etc/init.d/functions
. /etc/livesys.conf
. /etc/init.d/livesys.functions
# exit if not running from LiveCD
if [ ! "\\\$( cmdline_parameter liveimg )" ] || [ "\\\$1" != "start" ]; then
exit 0
fi
touch /.liveimg-late-configured
# read boot parameters out of /proc/cmdline
ks=\\\$( cmdline_value ks )
xdriver=\\\$( cmdline_value xdriver )
kb=\\\$( cmdline_value kb )
# if liveinst or textinst is given, start anaconda
if [ "\\\$( cmdline_parameter liveinst )" ]; then
plymouth --quit
/usr/sbin/liveinst \\\$ks
/sbin/reboot
fi
if [ "\\\$( cmdline_parameter textinst )" ] ; then
plymouth --quit
/usr/sbin/liveinst --text \\\$ks
/sbin/reboot
fi
EOF_lateinitscript
#***********************************************************************
# End of livesys-late script
#***********************************************************************
#***********************************************************************
# Create /sbin/halt.local
#***********************************************************************
echo "Creating /sbin/halt.local"
cat > /sbin/halt.local << EOF_haltlocal
#!/bin/bash
#
# Ejects LiveCD/DVD, if boot parameter eject is given
#
. /etc/init.d/functions
. /etc/livesys.conf
. /etc/init.d/livesys.functions
# exit if not running from LiveCD
if [ ! "\\\$( cmdline_parameter liveimg )" ]; then
exit 0
fi
if [ "\\\$( cmdline_parameter eject )" ]; then
echo "Eject CD/DVD ..."
/usr/sbin/eject -p -m \\\$(readlink -f /dev/live) >/dev/null 2>&1
fi
EOF_haltlocal
#***********************************************************************
# End of /sbin/halt.local script
#***********************************************************************
chmod 755 /sbin/halt.local
#***********************************************************************
# Configure the LiveCD
# Everything configured here will survive LiveCD install to harddisk !
#***********************************************************************
echo "Configure the LiveCD"
chmod 755 /etc/rc.d/init.d/livesys
/sbin/restorecon /etc/rc.d/init.d/livesys
/sbin/chkconfig --add livesys
chmod 755 /etc/rc.d/init.d/livesys-late
/sbin/restorecon /etc/rc.d/init.d/livesys-late
/sbin/chkconfig --add livesys-late
# go ahead and pre-make the man -k cache (#455968)
/usr/sbin/makewhatis -w
# save a little bit of space at least...
rm -f /var/lib/rpm/__db*
rm -f /boot/initrd*
rm -f /boot/initramfs*
# make sure there aren't core files lying around
rm -f /core*
# convince readahead not to collect
rm -f /.readahead_collect
touch /var/lib/readahead/early.sorted
# workaround clock syncing on shutdown that we don't want (#297421)
sed -i -e 's/hwclock/no-such-hwclock/g' /etc/rc.d/init.d/halt
# import RPM GPG keys
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Security-6
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-atrpms
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-fabian
# clean up yum
yum clean all
# workaround avahi segfault (#279301)
touch /etc/resolv.conf
/sbin/restorecon /etc/resolv.conf
# create locate db
/etc/cron.daily/mlocate.cron
# list kernel just for debugging
rpm -q kernel
EOF_post
# run post-install script
/bin/bash -x /root/post-install 2>&1 | tee /root/post-install.log
# ustack: install MegaCli
echo 'nameserver 114.114.114.114' >> /etc/resolv.conf
rpm -ivh http://mirrors.ustack.com/ustack/RPMS/x86_64/Lib_Utils-1.00-08.noarch.rpm
rpm -ivh http://mirrors.ustack.com/ustack/RPMS/x86_64/MegaCli-8.01.06-1.i386.rpm
wget http://mirrors.ustack.com/ustack/RPMS/x86_64/pymega -P /usr/bin
#wget http://mirrors.ustack.com/ustack/RPMS/x86_64/pylsi -P /usr/bin
wget http://mirrors.ustack.com/ustack/RPMS/x86_64/ustack_check -P /usr/bin
chmod +x /usr/bin/pymega
#chmod +x /usr/bin/pylsi
chmod +x /usr/bin/ustack_check
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /usr/bin/MegaCli
echo 'sleep 30' >> /etc/rc.local
echo 'ustack_check &> /tmp/ustack_check.log' >> /etc/rc.local
%end
########################################################################
#
# LiveCD post no chroot install
#
########################################################################
%post --nochroot
for rhgbfile in EFI/boot/isolinux.cfg EFI/boot/grub.conf isolinux/isolinux.cfg EFI/boot/boot.conf
do
echo "# uglifying $LIVE_ROOT/$rhgbfile"
echo "# uglifying $LIVE_ROOT/$rhgbfile" >> $LIVE_ROOT/$rhgbfile
sed -i -e's/ rhgb//g' -e's/ quiet//g' -e's/ rd_NO_DM/ 3/g' $LIVE_ROOT/$rhgbfile
echo "# uglified $LIVE_ROOT/$rhgbfile" >> $LIVE_ROOT/$rhgbfile
done
#***********************************************************************
# Create /root/postnochroot-install
# Must change "$" to "\$" and "`" to "\`" to avoid shell quoting
#***********************************************************************
cat > /root/postnochroot-install << EOF_postnochroot
#!/bin/bash
# Copy licensing information
cp $INSTALL_ROOT/usr/share/doc/*-release-*/GPL $LIVE_ROOT/GPL
# customize boot menu entries
grep -B4 'menu default' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/default.txt
grep -B3 'xdriver=vesa nomodeset' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/basicvideo.txt
grep -A3 'label check0' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/check.txt
grep -A2 'label memtest' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/memtest.txt
grep -A2 'label local' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/localboot.txt
sed "s/label linux0/label linuxtext0/" \$LIVE_ROOT/isolinux/default.txt > \$LIVE_ROOT/isolinux/textboot.txt
sed -i "s/Boot/Boot (Text Mode)/" \$LIVE_ROOT/isolinux/textboot.txt
sed -i "s/liveimg/liveimg 3/" \$LIVE_ROOT/isolinux/textboot.txt
sed -i "/menu default/d" \$LIVE_ROOT/isolinux/textboot.txt
sed "s/label linux0/label install0/" \$LIVE_ROOT/isolinux/default.txt > \$LIVE_ROOT/isolinux/install.txt
sed -i "s/Boot/Install/" \$LIVE_ROOT/isolinux/install.txt
sed -i "s/liveimg/liveimg liveinst noswap/" \$LIVE_ROOT/isolinux/install.txt
sed -i "s/ quiet / /" \$LIVE_ROOT/isolinux/install.txt
sed -i "s/ rhgb / /" \$LIVE_ROOT/isolinux/install.txt
sed -i "/menu default/d" \$LIVE_ROOT/isolinux/install.txt
sed "s/label linux0/label textinstall0/" \$LIVE_ROOT/isolinux/default.txt > \$LIVE_ROOT/isolinux/textinstall.txt
sed -i "s/Boot/Install (Text Mode)/" \$LIVE_ROOT/isolinux/textinstall.txt
sed -i "s/liveimg/liveimg textinst noswap/" \$LIVE_ROOT/isolinux/textinstall.txt
sed -i "s/ quiet / /" \$LIVE_ROOT/isolinux/textinstall.txt
sed -i "s/ rhgb / /" \$LIVE_ROOT/isolinux/textinstall.txt
sed -i "/menu default/d" \$LIVE_ROOT/isolinux/textinstall.txt
cat \$LIVE_ROOT/isolinux/default.txt \$LIVE_ROOT/isolinux/basicvideo.txt \$LIVE_ROOT/isolinux/check.txt \$LIVE_ROOT/isolinux/memtest.txt \$LIVE_ROOT/isolinux/localboot.txt > \$LIVE_ROOT/isolinux/current.txt
diff \$LIVE_ROOT/isolinux/isolinux.cfg \$LIVE_ROOT/isolinux/current.txt | sed '/^[0-9][0-9]*/d; s/^. //; /^---$/d' > \$LIVE_ROOT/isolinux/cleaned.txt
cat \$LIVE_ROOT/isolinux/cleaned.txt \
\$LIVE_ROOT/isolinux/default.txt \
\$LIVE_ROOT/isolinux/textboot.txt \
\$LIVE_ROOT/isolinux/basicvideo.txt \
\$LIVE_ROOT/isolinux/check.txt \
\$LIVE_ROOT/isolinux/install.txt \
\$LIVE_ROOT/isolinux/textinstall.txt \
\$LIVE_ROOT/isolinux/memtest.txt \
\$LIVE_ROOT/isolinux/localboot.txt > \$LIVE_ROOT/isolinux/isolinux.cfg
rm -f \$LIVE_ROOT/isolinux/*.txt
EOF_postnochroot
# run postnochroot-install script
/bin/bash -x /root/postnochroot-install 2>&1 | tee /root/postnochroot-install.log
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment