JRehkemper.de

Create AlmaLinux Kickstart ISO

Requirements

First of all we need an Base-ISO Image of AlmaLinux.
It is also a good idea to create a separate directory where you can work on your kickstart file.

Additionaly, we will also need some packages.

sudo dnf install createrepo genisoimage isomd5sum syslinux

Creating a Basis

To access the files inside the Base-ISO we can mount it into an empty directory

sudo mkdir /mnt/almalinux
sudo mount -o loop AlmaLinux-9.4-x86_64-minimal.ios /mnt/almalinux

After that we will copy all the content of the ISO into our working directory.
We will modify it in the next steps and than generate a new ISO-Image based on the working directory

cp -rv /mnt/almalinux <your-working-dir>

After that you can unmount the ISO, since it is not needed any longer

sudo umount /mnt/almalinux

Creating the Kickstart File

Next step would be to ready the kickstart file.
You can either do this from scratch or use an existing one.
If you use the installer on the Base-ISO it will create a kickstart file under /root/. You can copy and modify it to spare yourself some work.

Mine for example is looking like this:

#version=RHEL9

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

# Add additional repositories
repo --name=epel --metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir

# Keyboard layouts
keyboard --xlayouts='de (nodeadkeys)'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --activate

# Use CDROM installation media
cdrom

# Install Packages
%packages
@^minimal-environment
curl
htop
ncdu
netcat
tar
tree
unzip
vim-enhanced
wget
bind-utils
%end

# Run the Setup Agent on first boot
firstboot --enable

# Generated using Blivet version 3.4.0
#ignoredisk --only-use=sda,vda
autopart
# Partition clearing information
clearpart --none --initlabel

timesource --ntp-server=fritz.box
# System timezone
timezone Europe/Berlin --utc

# Root password
rootpw --iscrypted <hash>
user --name=homeadmin --password=<hash> --iscrypted --gecos="Homeadmin" --groups="wheel"

%post --interpreter=/bin/bash
# Update packages
dnf update -y
%end

# reboot and eject the iso
reboot --eject

This file has to lie in the root of the filesystem to be found.

Creating an Custom ISO

Next we will create a custom ISO based on our kickstart file

#Therefor we need to initialize an rpm-repository in our almalinux-custom directory.
#bash #createrepo -dpo almalinux-custom #

To tell our system to use our Kickstart-file, we need to modify the grub-menu included in our iso.

vim almalinux-custom/almalinux/EFI/BOOT/grub.cfg

I will use a git diff to show the changes.

- set default="1"
+ set default="0"
|
| function load_video {
|   insmod efi_gop
|   insmod efi_uga
|   insmod video_bochs
|   insmod video_cirrus
|   insmod all_video
| }
|
| load_video
| set gfxpayload=keep
| insmod gzio
| insmod part_gpt
| insmod ext2
|
- set timeout=60
+ set timeout=0
| ### END /etc/grub.d/00_header ###
|
| search --no-floppy --set=root -l 'AlmaLinux-9-1-x86_64-dvd'
| 
| ### BEGIN /etc/grub.d/10_linux ###
| menuentry 'Install AlmaLinux 9.1' --class fedora --class gnu-linux --class gnu --class os {
-     linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd quiet
+     linuxefi /images/pxeboot/vmlinuz inst.test inst.ks=cdrom:/ks.cfg inst.stage2=hd:LABEL=Almalinux-9-1-x86_64-dvd
|     initrdefi /images/pxeboot/initrd.img
| }
- menuentry 'Test this media & install AlmaLinux 9.1' --class fedora --class gnu-linux --class gnu --class os {
-     linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd rd.live.check quiet
-     initrdefi /images/pxeboot/initrd.img
- }
| submenu 'Troubleshooting -->' {
|     menuentry 'Install AlmaLinux 9.1 in text mode' --class fedora --class gnu-linux --class gnu --class os {
|           linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd inst.text quiet
|         initrdefi /images/pxeboot/initrd.img
|     }
|     menuentry 'Rescue a AlmaLinux system' --class fedora --class gnu-linux --class gnu --class os {
|         linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd inst.rescue quiet
|         initrdefi /images/pxeboot/initrd.img
|     }
| }

Next we need to edit the boot-config for bios boot

sudo vim isolinux/isolinux.cfg
- timeout 600
+ timeout 0

| label linux
|   menu label ^Install AlmaLinux 9.1
|   kernel vmlinuz
+  append initrd=initrd.img inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd
+  append initrd=initrd.img inst.test inst.ks=cdrom:/ks.cfg inst.stage2=hd:LABEL=AlmaLinux-9-1-x86_64-dvd

Now we can build the ISO

mkisofs -o <output-path> -b isolinux/isolinux.bin -J -R -l -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -graft-points -V "AlmaLinux-9-1-x86_64-dvd" <your almalinux-custom dir>

After that we can make the iso bootable for USB-Drives

isohybrid --uefi /mnt/almalinux/<your-image>.iso

Last step would be to implant an MD5 Hash into the ISO

implantisomd5 /mnt/almalinux/<your-image>.iso

Now your iso is finished and you can try it out.

Troubleshooting

If you get the following error message

Kickstart file /run/installer/ks.cfg is missing.  

it is probably because of a syntax error in your kickstart file (eventhough the error message is missleading here).

You can check your kickstart file with a validator and it will probably hint you to what is wrong.

sudo dnf install pykickstart

ksvalidator -v RHEL9 ks.cfg
profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.