Red Hat 7.4: How to inject kickstart file into USB media for UEFI-only system

kickstartrheluefi

I am trying to build an installation image (to be transferred to USB media) for Red Hat Linux 7.4 with a custom kickstart file, and the corresponding ks= argument added to grub, but and can't figure out how to do it.

Here are the approaches I have tried:

dd if=rhel-server-7.4-x86_64-dvd.iso of=/dev/sdb

This builds the a bootable USB stick, but of course without the kickstart file.

Next, I copied the content of the ISO to a temporary file, added my ks.cfg and modified the grub configuration, and then used genisoimage to rebuild a new image.

genisoimage \
  -untranslated-filenames \
  -rational-rock \
  -v \
  -translation-table \
  -input-charset "default" \
  -J \
  -joliet-long \
  $VOLLABELARGS 
  -b isolinux/isolinux.bin \
  -c isolinux/boot.cat \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  -eltorito-alt-boot \
  -efi-boot images/efiboot.img \
  -no-emul-boot \
  -o $THISDIR/$VOLLABEL.iso \

This is based on Red Hat's own instructions for RHEL 6 – I am, of course, using RHEL 7. This works for BIOS booting, but when I try it on the UEFI system, the resulting image is rejected as "not compatible".

The resulting image is also noticeably larger than the original RHEL ISO.

Examining it with xorriso shows that it is also substantially different from the original. isohybrid helps some, but not enough to make the image bootable.

The output of xorriso -report on Red Hat's ISO:

xorriso -indev rhel-server-7.4-x86_64-dvd.iso -report_el_torito cmd
-volid 'RHEL-7.4 Server.x86_64'
-volume_date uuid '2017071101014600'
-boot_image isolinux system_area=--interval:imported_iso:0s-15s:zero_mbrpt,zero_gpt:'rhel-server-7.4-x86_64-boot.iso'
-boot_image any partition_cyl_align=on
-boot_image any partition_offset=0
-boot_image any partition_hd_cyl=64
-boot_image any partition_sec_hd=32
-boot_image any iso_mbr_part_type=0x00
-boot_image any cat_path='/isolinux/boot.cat'
-boot_image isolinux bin_path='/isolinux/isolinux.bin'
-boot_image any platform_id=0x00
-boot_image any emul_type=no_emulation
-boot_image any load_size=2048
-boot_image any boot_info_table=on
-boot_image any next
-boot_image any efi_path='/images/efiboot.img'
-boot_image any platform_id=0xef
-boot_image any emul_type=no_emulation
-boot_image any load_size=9211904
-boot_image isolinux partition_entry=gpt_basdat

And the output of xorriso on my image:

xorriso -indev myimage.iso -report_el_torito cmd
-volid '"MYIMAGE"'
-volume_date uuid '2018011923504500'
-boot_image isolinux system_area=--interval:imported_iso:0s-15s:zero_mbrpt:'MYIMAGE.iso'
-boot_image any partition_cyl_align=on
-boot_image any partition_offset=0
-boot_image any partition_hd_cyl=64
-boot_image any partition_sec_hd=32
-boot_image any iso_mbr_part_type=0x17
-boot_image any cat_path='/isolinux/boot.cat'
-boot_image isolinux bin_path='/isolinux/isolinux.bin'
-boot_image any platform_id=0x00
-boot_image any emul_type=no_emulation
-boot_image any load_size=2048
-boot_image any boot_info_table=on
-boot_image any next
-boot_image any efi_path='/images/efiboot.img'
-boot_image any platform_id=0xef
-boot_image any emul_type=no_emulation
-boot_image any load_size=9211904

Comparing these two, Red Hat has a few GPT-related entries that my image is missing.

Other approaches I have looked at but am not even sure if I'm going off in the wrong direction with those.

  • Using lorax/livemedia-creator. I find the instructions quite confusing. It appears to be used to build a live image, but I can't figure out how to invoke Anaconda.

  • Format the USB stick as a standard three-partition hard drive. I can't figure out how to make this bootable, though.

What is the best/easiest way to accomplish what I want?

My requirements:

  • Must be Linux command line; I want to script this process.
  • Should generate an image file, I don't want to write directly to my USB script if I can avoid it.
  • Should be able to run as non-root user.

The image file does not need to support CD/DVD booting.

Best Answer

There's a simpler approach now that would likely work well with both RHEL/CentOS and Fedora ISOs -- since it's part of the lorax project that RHEL and Fedora uses to build its ISOs in the first place, mkksiso. I've only tested it on Fedora 32 though.

There's a bug I discovered when testing it; if the source ISO is bootable on both UEFI and Macs, the new ISO is only bootable on Macs and on legacy BIOS systems. Fixed in this PR but it's not released yet, but mkksiso is a simple Python script that you can just download separately if the rest of lorax is installed.

Injecting a kickstart is now as simple as:

sudo dnf install lorax
wget -cN https://raw.githubusercontent.com/weldr/lorax/master/src/sbin/mkksiso
chmod +x mkksiso
sudo ./mkksiso -V MyNewVolumeID path/to/kickstart path/to/orig.iso path/to/

see e.g. https://github.com/michel-slm/luks-kickstarts/blob/master/rebuild.sh

Related Question