yum install -y wget yum install -y rsync yum install -y isomd5sum yum install -y pykickstart yum install -y genisoimage
Also we will be using the GUI Kickstart Configurator. This can be installed through CentOS App Store simply do a search for “Kickstart” and it should pop up. Install it and wait with starting it up.
If the above does not work i.e the Kickstart Configurator is notlisted install it with yum like this.
yum install system-config-kickstart
In CentOS there is a bug in the Kickstart Configurator which prevents you from adding and selecting software packages, this is fixed like this.
vi /usr/share/system-config-kickstart/packages.py
Find Thes Lines: “Located around line 164”
repoorder = ["fedora", "rawhide", "development"] else: repoorder = ["rawhide", "development", "fedora"]
And Add “base” to the last line so that it looks like this.
repoorder = ["fedora", "rawhide", "development"] else: repoorder = ["rawhide", "development", "fedora", "base"]
Save the file and we are ready to proceed.
Create a kickstart file using the Kickstart Configurator we just installed and save the file as ks.cfg
Be sure to check whether the kickstart file is valid by running the following command.
ksvalidator ks.cfg
Next we have to modify a CentOS image to use the kickstart file. You have a few options here I will show 2 of those.
Now we need to create an ISO than will contain CentOS as well as a kickstart file pointin to either local media or an nfs server.
This guide shows 2 methods.
Mount CentOS through the VMware menu, change username to the username logged in to CentOS.
mkdir -p /media/dvd mount --bind /run/media/username/CentOS\ 7\ x86_64 /media/dvd/ /media/dvd
Create a working directory and copy the CentOS is to that directory.
mkdir -p /home/username/centosnew/dvd rsync -av /media/dvd/ /home/username/centosnew/dvd/ umount /media/dvd
mkdir -p /home/username/iso cd /home/username/iso wget http://mirror.fysik.dtu.dk/linux/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1908.iso file -sL CentOS-7-x86_64-DVD-1908.iso
Next we mount the iso and copy it to our working directory.
mkdir -p /home/username/centosnew/dvd mkdir -p /media/dvd mount -o loop /home/username/iso/CentOS-7-x86_64-DVD-1908.iso /media/dvd rsync -av /media/dvd/ /home/username/centosnew/dvd/ umount /media/dvd
If the kickstart file is working move it to the new Iso.
cp location/of/kickstartfile/ks.cfg /home/username/centosnew/dvd/ks.cfg
vi /home/username/centosnew/dvd/isolinux/isolinux.cfg
Find these lines.
label check menu label Test this ^media & install CentOS 7 menu default kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
And remove the following line.
menu default
So that it looks like this (you could also remove all lines if you like).
label check menu label Test this ^media & install CentOS 7 kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
Next find this line.
label linux
And above that add your own menu, could be something like this.
label mycentos menu label ^MyCentOS CentOS 7 menu default kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 inst.ks=cdrom:/dev/cdrom:/ks.cfg
Note: If you rather would like nfs add something like this instead. Replace xxx.xxx.xxx.xxx with the ip of the NFS server and nfsshare with the real nfsshare name.
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 inst.ks=nfs:xxx.xxx.xxx.xxx:/nfsshare/ks.cfg
cd /home/username/centosnew/dvd genisoimage -o ../centos-7-custom.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -v -T -V 'CentOS 7 x86_64' .
Note: Please remember to add the last . from the line above it's part of the command line.
Now a new checksum for the iso we just build.
implantisomd5 /home/username/centosnew/centos-7-custom.iso
Check if the new iso is bootable
file -sL /home/username/centosnew/centos-7-custom.iso
Right Now you may be in need to copy your own file selection and or script from the media to the final installation during install I do it like this.
First create a directory “here called postinstall” holding your files and or scripts. This directory needs to be in in the root of the dvd i.e. here /home/username/centosnew/dvd/
mkdir /home/username/centosnew/dvd/postinstall
In that newly created directory put all your files and folders you will need present after installation.
Now in order for this to work and because of how Anaconda unmounts the cdrom/dvd during install we need to add a few things to the kickstart file. place this before all the other %post commands as order is important.
%post --nochroot --log=/mnt/sysimage/root/ks.post01.log mkdir -p /tmp/files mount /dev/sr0 /tmp/files cp -af /tmp/files/postinstall /mnt/sysimage/ umount /dev/sr0 cd /mnt/sysimage/ %end
Next you can manipulate i.e run or install scripts and programs from the normal %post entries. Let's say you have the epel repo rpm in the postinstall folder. You would install it like this.
# Add Epel Repo Start cd /postinstall rpm -ivh epel-release-latest-7.noarch.rpm # Add Epel Repo Stop %end
Copy the ks.config file like described above and do the whole create iso thing again.
Right good to go you can now start up your new installations from the new iso we just created.
Sample Kickstart Configuration File(s) Sample Kickstart File Using Ext4 - Sample Kickstart File Using LVM