The Reason and the Pain #
At some point in your career, you’ve probably had to copy data from one computer to another, especially when working with infrastructure where you need to recreate a machine with the same configuration for easy replication or even customize an ISO to include some basic settings.
While there are many solutions available for the cloud, have you ever needed to configure physical machines that will be used as local servers for a client?
That’s why I’m here: to present a configuration I discovered recently.
What It Is #
Kickstart is a tool from Red Hat, designed to facilitate and automate the installation of an ISO on a machine. It’s a sophisticated method for teams to automate and deliver pre-configured machines.
Since this configuration is at the operating system level and is used during the ISO installation on the machine, it’s a simple and effective way to create customizable ISOs for machine installation.
How to Do It and Configure #
How can I use this?
Well, this feature is only available for Linux distributions based on Red Hat, such as RHEL 9, CentOS, and Rocky Linux (to my knowledge).
We’ll need two tools installed to follow this guide (these are tools that I believe are commonly used in Linux environments):
- mkisofs (to create an ISO image from a directory)
- pykickstart (to validate our Kickstart file and check for errors)
With these tools, simply download an ISO from the website of one of these distributions. For this guide, I’ll use Rocky Linux as an example.
After downloading the ISO, mount it on the system using the following command:
mkdir -p /mnt/disk
mount -o loop Rocky-9.4-x86_64-minimal.iso /mnt/disk
This command will mount the ISO file to the directory /mnt/disk.
Next, we need to copy the contents of the disk to a local directory, as we cannot modify the directory where the ISO is mounted since it is read-only.
mkdir -p /tmp/disk
cp -r /dev/sda /tmp/disk
After that, we should unmount the disk because we no longer need it since we already have a copy of its contents on our machine.
umount /mnt/disk
Now, we will create our Kickstart file in the directory with the copied files.
touch /tmp/disk/ks.cfg
You can edit the content with your favorite text editor. After editing the file, it’s a good practice to validate its content before proceeding with the next steps to avoid installation errors.
ksvalidator -v SHEL9 /tmp/disk/ks.cfg
Fix any errors found and ensure everything is correct. Now, we need to instruct the image to recognize this file as a Kickstart file and use it when formatting the machine with the customizable ISO.
sed -i '/^\s*append initrd=/ s/$/ inst.is=cdrom:\/kc.cfg/' /tmp/disk/isolinux/isolinux.cfg
Note that the file name does not have to be exactly as created here. If you used a different name, remember to update the command according to the name of the file you created.
After that, we need to create a bootable ISO with the files from our modified directory.
mkisofs -o Rocky-9.4-x86_64-custom.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "OEMDRV"
And that’s it! Just burn this new bootable ISO to a CD-ROM or USB drive and install it on a machine.
References #
- https://docs.centos.org/en-US/centos/install-guide/Kickstart2/#sect-kickstart-examples
- https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/automatically_installing_rhel/semi-automated-installations-making-kickstart-files-available-to-the-rhel-installer_rhel-installer
- https://bgstack15.ddns.net/blog/posts/2023/08/03/my-kickstart-for-rocky-linux-9-vms/
- https://thelinuxcode.com/run-kickstart-rocky-linux-9/
- https://docs.centos.org/en-US/8-docs/advanced-install/assembly_kickstart-script-file-format-reference/