Trying to create a UEFI USB boot stick

General support questions
VirtualLinux
Posts: 2
Joined: 2018/05/15 20:43:59

Trying to create a UEFI USB boot stick

Postby VirtualLinux » 2018/05/15 20:57:04

I started with the CentOS 7.5 Minimal ISO and copied to a directory.

I modified EFI/BOOT/grub.cfg to have only 1 menu entry to automatically kick off a kickstart when it boots.

I then generated an ISO using the command:


/usr/bin/xorriso -as mkisofs \
-o ${ISOLOC}/CentOS.iso \
-volid "OEMDRV" \
-isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \
-c isolinux/boot.cat \
-b isolinux/isolinux.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot \
-e images/efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
.

If I mount the ISO as the CDROM drive of a VMware VM, it boots and works perfectly.

If I write the ISO to a USB boot drive, I'm still getting the CentOS default grub.cfg from the CentOS distribution, instead of mine. If I mount the ISO, I can see the correct grub.cfg file.

Where in the heck is the USB flash drive getting it's grub.cfg from? I've searched all over and can't find any other file that looks like the default grub.cfg.

If I attempt to continue on from the flash drive, I get an error that /images/pxeboot/vmlinuz doesn't exist.

What the heck am I doing wrong?

VirtualLinux
Posts: 2
Joined: 2018/05/15 20:43:59

Re: Trying to create a UEFI USB boot stick

Postby VirtualLinux » 2018/05/15 21:22:48

So a little more digging...after writing the resulting .iso to a flash drive, I see there are two partitions.

The first partition has everything I would expect.

The second, small partition only has an EFI/BOOT folder with the typical contents, included a grub.cfg which is the default grub.cfg that I'm seeing.

How is xorriso creating this second EFI partition with contents it should know nothing about?

Why isn't it using the contents from my staging directory?

scdbackup
Posts: 11
Joined: 2016/01/01 07:54:07

Re: Trying to create a UEFI USB boot stick

Postby scdbackup » 2018/05/16 07:14:48

Hi,

the following is a copy of the answer to a mail i got today, probably from
the starter of this thread. It is very similar to the text here, except
minor details.


> I started with the CentOS 7.5 Minimal ISO and copied to a directory.
>
> I modified EFI/BOOT/grub.cfg to have only 1 menu entry to automatically kick
> off a kickstart when it boots.

But you did not modify the GRUB stuff in the EFI System Partition.


> I then generated an ISO using the command:

The xorriso command looks ok.


> If I mount the ISO as the CDROM drive of a VMware VM, it boots and works
> perfectly, even using EFI booting.

Probably the EFI firmware (OVMF ?) used the BIOS boot path.
This should be recognizable by ISOLINUX being the bootloader, not GRUB.


> If I write the ISO to a USB boot drive, I'm still getting the CentOS default
> grub.cfg from the CentOS distribution, instead of mine.

In this case your firmware probably booted via the EFI System Partition.


> So after a little more digging...after writing the resulting .iso to a flash
> drive, I see there are two partitions.

Yep. That's the layout of Matthew J. Garrett (without Apple specific stuff).
See
http://mjg59.dreamwidth.org/11285.html

The first partition covers the whole ISO filesystem. It is caused by
option -isohybrid-mbr but gets partition type 0x00 because of the
second partition sitting inside the first one. (UEFI forbids that, but
also says that a partition of type 0x00 is to be ignored by EFI
implementations.)

The second partition marks the EFI System Partition, which is actuall a
a FAT filesystem image file in the ISO that has the path
/images/efiboot.img

(Do not get confused by some partition editors talking of GPT. There is
GPT data, but the GPT is not announced by the MBR.)


> The second, small partition only has an EFI/BOOT folder with the typical
> contents, included a grub.cfg which is the default grub.cfg that I'm seeing.

You will have to modify this FAT filesystem in order to get your changes
into effect.

This can either be done by
  • mounting the extracted file ./images/efiboot.img
  • or mounting the partition as read-write filesystem
  • or mounting the ISO image (e.g. as /mnt/iso) and then mounting the file
    /mnt/iso/images/efiboot.img as read-write filesystem (e.g. as /mnt/fat)

Then you can either
  • copy all files out of the FAT filesystem, modify them, and pack up a new
    FAT filesystem image, which you put into the ISO as /images/efiboot.img.
  • modify the files in the mounted FAT filesystem (there is not much free
    space in there:
    Filesystem 1K-blocks Used Available Use% Mounted on
    ...
    /dev/loop1 8950 8736 214 98% /mnt/fat
    )

> How is xorriso creating this second EFI partition with contents it should
> know nothing about?

It was Fedora/RedHat/CentOS who created efiboot.img.

xorriso only puts it into the ISO (in your case because it's in ".") and
then marks it as EFI System Partition and second El Torito boot image
because of these options:
    -eltorito-alt-boot \
    -e images/efiboot.img \
    -no-emul-boot \
    -isohybrid-gpt-basdat \
You could ask the developers who pack up the original ISOs for the original
procedure of creating efiboot.img.


> If it matters, I am using a RHEL 7.4 system to build the CentOS ISO.

This should not matter. Only the xorriso version would. But if it takes
all your options without error, then it is young enough.


Have a nice day :)

Thomas