3

I am trying to create a UEFI bootable CD ISO with a squashed filesystem from a virtual machine, which I provisioned with the stuff I need.

To explain:

  1. I use packer and a kickstart file to install CentOS 7
  2. I use a packer provision script to compile some binary stuff that I need on the image
  3. I followed the instructions from here to create a squashed filesystem image after everything I need is in the OS:
mkdir -p /mnt/squashfs /squashfs
mount -o bind / /mnt/squashfs

mksquashfs /mnt/squashfs /squashfs/filesystem.squashfs -comp gzip -no-exports -xattrs -noappend -no-recovery -e /mnt/squashfs/squashfs/filesystem.squashfs find /boot -name 'vmlinuz-' -type f -exec cp {} /squashfs/vmlinuz ; find /boot -name 'init' -type f -exec cp {} /squashfs/initrd.img ;

  1. After that I took some scripts from here to build an ISO:
yum -y install xorriso dosfstools grub2-efi-modules mtools

mkdir -p /iso /iso_src/ /iso_src/live find /boot -name 'vmlinuz-' -type f -exec cp {} /iso_src/vmlinuz ; find /boot -name 'init' -type f -exec cp {} /iso_src/initrd.img ; cp /squashfs/filesystem.squashfs /iso_src/live/ touch /iso_src/LINUX_CUSTOM

cat <<'EOF' >grub.cfg

search --set=root --file /LINUX_CUSTOM

insmod all_video

set default="0" set timeout=30

menuentry "Custom Linux" { linux /vmlinuz boot=live toram=filesystem.squashfs quiet nomodeset initrd /initrd.img } EOF

grub2-mkstandalone
--format=x86_64-efi
--output=bootx64.efi
--locales=""
--fonts=""
"boot/grub/grub.cfg=grub.cfg"

(dd if=/dev/zero of=efiboot.img bs=1M count=10 &&
mkfs.vfat efiboot.img &&
mmd -i efiboot.img efi efi/boot &&
mcopy -i efiboot.img ./bootx64.efi ::efi/boot/ )

xorriso
-as mkisofs
-iso-level 3
-full-iso9660-filenames
-volid "LINUX_CUSTOM"
-eltorito-alt-boot
-e EFI/efiboot.img
-no-emul-boot
-append_partition 2 0xef efiboot.img
-output "/iso/image.iso"
-graft-points
"/iso_src"
/EFI/efiboot.img=efiboot.img

Now I am trying to boot that ISO in VirtualBox with UEFI enabled, but it fails with

Failed to switch root: Specified switch root path '/sysroot' does not seem to be an OS tree

So as far as I understand my squashfs has not been mounted? I am kind of new to this, so I have a partial understanding of all of the steps, and it feels like I am missing something, since the only thing that tells grub that instead of the machine from which I made the image from (where there was an actual block device) now I need my filesystem to come from a squashfs file is the toram thing.

Can anyone provide pointers/examples on how to solve this an make this system boot? I read a lot about dracut but could not understand how to use it in this scenario? Or is this simply a grub configuration file issue?

Update

After some Googling, I switched to dracut, now in my provision script i use dracut to generate initrd like this:

dracut -a dmsquash-live -N -m "kernel-modules base" --filesystems "squashfs" /dracut/initrd.dracut.img

and use the following grub boot entry (the initrd.img here is the initrd.dracut.img created previously):

menuentry "Custom Linux" {
    linux /vmlinuz root=live:/dev/sr0 rd.live.debug=1
    initrd /initrd.img
}

this seems to get futher but fails with Warning: /dev/mapper/live-rw does not exist

Update 2

It seems that CentOS 7 comes with an older dracut that only supports the Live CD mode (see The filesystem structure is traditionally expected to be: under Booting live images, which my structure did not conform to). So I started over with CentOS 8, a newer dracut, which can handle the structure I have and now my only issue when booting is having the /etc/fstab from the original machine, which I hope Google will help me solve:D

Update 3

Simply ignoring /etc/fstab along /dev and /proc` when making the squashfs did the trick - the final ISO successfully boots in UEFI mode.

0 Answers0