Mount | Modify | Edit | Repack | Create UEFI ISO with Kickstart File inside

Sep 11, 2016 Bash, Linux

Mount Modify Edit Re-pack Create UEFI ISO including Kickstart file
Linux installation process can be simplified by means of Kickstart Installation method, used in Linux distributions like: Red Hat, Debian, Fedora, CentOS, Ubuntu. This method utilizes so called Kickstart File, which describes the configuration, required setup and post installation tasks for Kickstart Linux installation.

Kickstart File can be placed in the remote repository, accesible via NFS, HTTP, FTP, etc…, or can be included in ISO image, which is pretty convenient, especially when we don’t want to or don’t have a possibility to create network repository to store a Kickstart File.

In this tutorial we will download original CentOS 7.2 / RHEL 7.2 ISO image, mount it in the Linux file system, modify it by adding Kickstart File (ks.cfg) and re-pack it to create custom UEFI bootable RHEL 7.2 ISO image using mkisofs command.

Note: the below procedure describes creating custom UEFI ISO image, so the image won’t boot in Legacy BIOS.


1. Mount ISO image read-only in Linux file system

[root@tuxfixer ~]# mkdir /mnt/rhel72_image
[root@tuxfixer ~]# mount -o loop /tmp/rhel-server-7.2-x86_64-dvd.iso /mnt/rhel72_image/
mount: /dev/loop0 is write-protected, mounting read-only
[root@tuxfixer ~]# df -hT | grep /dev/loop0
/dev/loop0     iso9660   3.8G  3.8G     0 100% /mnt/rhel72_image

Note: the ISO image can’t be mounted read-write, so we are mounting it read-only and next we will copy the content to the new working directory.

2. Copy ISO contents to the new working directory

Since the ISO image is mounted read-only, we need to copy the content to new directory in order to be able to edit it’s files.

[root@tuxfixer ~]# cp -aR /mnt/rhel72_image/ /mnt/custom_rhel72_image/
[root@tuxfixer ~]# ls -al /mnt/custom_rhel72_image/
total 384
dr-xr-xr-x. 10 root root   4096 Oct 30  2015 .
drwxr-xr-x.  6 root root     80 Sep 12 15:42 ..
dr-xr-xr-x.  4 root root     52 Oct 30  2015 addons
-r--r--r--.  1 root root     56 Oct 30  2015 .discinfo
dr-xr-xr-x.  3 root root     17 Oct 30  2015 EFI
-r--r--r--.  1 root root   8266 Apr  4  2014 EULA
-r--r--r--.  1 root root  18092 Mar  6  2012 GPL
dr-xr-xr-x.  3 root root     54 Oct 30  2015 images
dr-xr-xr-x.  2 root root   4096 Oct 30  2015 isolinux
dr-xr-xr-x.  2 root root     41 Oct 30  2015 LiveOS
-r--r--r--.  1 root root    114 Oct 30  2015 media.repo
dr-xr-xr-x.  2 root root 241664 Oct 30  2015 Packages
dr-xr-xr-x. 24 root root   4096 Oct 30  2015 release-notes
dr-xr-xr-x.  2 root root   4096 Oct 30  2015 repodata
-r--r--r--.  1 root root   3375 Oct 23  2015 RPM-GPG-KEY-redhat-beta
-r--r--r--.  1 root root   3211 Oct 23  2015 RPM-GPG-KEY-redhat-release
-r--r--r--.  1 root root   1568 Oct 30  2015 TRANS.TBL
-r--r--r--.  1 root root   2176 Oct 30  2015 .treeinfo

Note: make sure the hidden files (.discinfo, .treeinfo) were copied too

3. Place kickstart file in the ISO working directory

Now let’s prepare kickstart file and place it in main working directory (/mnt/custom_rhel72_image/). Below the example kickstart file (ks.cfg) used in our tutorial:

[root@tuxfixer ~]# cat /mnt/custom_rhel72_image/ks.cfg
lang en_US
keyboard us
timezone America/New_York --isUtc
rootpw $1$XzuKC4kZ$bmhF7BKD8ytLdK9IaZvKB2 --iscrypted
#platform x86, AMD64, or Intel EM64T
bootloader --location=mbr --append="rhgb quiet crashkernel=auto"
clearpart --all --initlabel
auth --passalgo=sha512 --useshadow
selinux --enforcing
firewall --enabled --ssh
firstboot --disable


4. Modify GRUB config file for UEFI BOOT

Modify original main menu entry in /mnt/custom_rhel72_image/EFI/BOOT/grub.cfg file:

menuentry 'Install Red Hat Enterprise Linux 7.2' --class fedora --class gnu-linux --class gnu --class os {
        linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=RHEL-7.2\x20Server.x86_64 quiet
        initrdefi /images/pxeboot/initrd.img

…to look like below:

menuentry 'Red Hat Enterprise Linux 7.2 Custom Kickstart Installation' --class fedora --class gnu-linux --class gnu --class os {
        linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=RHEL-7.2\x20Server.x86_64 quiet inst.ks=cdrom:/ks.cfg
        initrdefi /images/pxeboot/initrd.img

5. Create custom Red Hat 7.2 UEFI ISO image

Now create UEFI ISO image using mkisofs command with parameters:

[root@tuxfixer ~]# mkisofs -o /tmp/rhel_7.2_uefi_custom.iso -b isolinux/isolinux.bin -J -R -l -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -graft-points -V "RHEL-7.2 Server.x86_64" /mnt/custom_rhel72_image/

6. Post-process ISO image with isohybrid

Post-process an ISO 9660 image generated with mkisofs to allow hybrid booting as a CD-ROM or as a hard disk:

[root@tuxfixer ~]# isohybrid --uefi /tmp/rhel_7.2_uefi_custom.iso
isohybrid: Warning: more than 1024 cylinders: 3954
isohybrid: Not all BIOSes will be able to boot this device

7. Burn UEFI ISO image

Burn created UEFI ISO image on DVD or mount it directly in server’s iLO and boot from it:

Mount / Modify / Edit / Repack / Create UEFI ISO with Kickstart File inside

10 thoughts on “Mount | Modify | Edit | Repack | Create UEFI ISO with Kickstart File inside”
  1. This iѕ rᥱally attention-grabbing, Ⲩou’re an overly
    skilled blogger. I have joined үour rsss feed aand ⅼоoқ forward to in thе
    hunt for extra of yоur excellent post. Additionally, І’νe shared ʏour site іn my social networks

  2. Hi Grzegorz,
    Very good article. I would like to boot single ISO image in Legacy mode and UEFI mode. is it doable? if yes could you send me the full command


  3. Thank you for the great article. But by doing this, the GUI Installer will start and then i get the mesage “Error setting up base repository”. When i use the “Verfy” Button in the “Installation source selection screen” he tells me, that “this media is not good to install from”.

  4. I tried the above steps that you provided and created an iso and mounted it on a Dell R740 server as a virtual media and it never recognizes the kickstart script. But it boots to the default installation gui. Can you please let me know if the above script only works for HP.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.