I am trying to write a script that will unpack and repack a FreeBSD ISO such that I can then do an installation with it. The goal is an unattended installation.
I've got the following script written but it doesn't work. While the original ISO will boot in VirtualBox under UEFI mode, the newly created ISO won't.
#!/bin/sh
inst_cfg="$1"
src_iso="$2"
dst_iso="$3"
iso_mnt=$(mktemp -d /tmp/freebsd-mnt-XXXXXX)
iso_wrk=$(mktemp -d /tmp/freebsd-wrk-XXXXXX)
vol_id=$(isoinfo -d -i "${src_iso}" | sed -n -e 's/^Volume id: \(.*\)$/\1/p')
md_name=$(mdconfig -a -t vnode -f "${src_iso}")
mount -t cd9660 "/dev/${md_name}" "${iso_mnt}"
cp -a -v "${iso_mnt}/" "${iso_wrk}"
cp "${inst_cfg}" "${iso_wrk}/etc/installerconfig"
mkisofs -J -R -no-emul-boot -V "${vol_id}" -b boot/cdboot -o "${dst_iso}" "${iso_wrk}"
umount "${iso_mnt}" # cd9660
mdconfig -d -u "${md_name}"
rm -rf "${iso_mnt}"
rm -rf "${iso_wrk}"
The created filesystem looks good. I've diff'ed the files of the original and custom ISOs and the only differences are the installerconfig
file added and boot.catalog
(which I understand mkisofs
adds, but why? Could this be the problem?)
I've tried various combinations of options to mkisofs
, including -R -U
, -L -D -R
, -J -R
, but nothing makes a difference.
Additionally, the FreeBSD Handbook interestingly has the following commentary:
So, if /tmp/myboot holds a bootable FreeBSD system with the boot image
in /tmp/myboot/boot/cdboot, this command would produce
/tmp/bootable.iso:
mkisofs -R -no-emul-boot -b boot/cdboot -o /tmp/bootable.iso /tmp/myboot
This does not produce an ISO that boots under VirtualBox in UEFI mode.
Does anyone have an idea what's wrong?
Best Answer
The problem is not in the filesystem content but in the boot records and partitions:
Both, the BIOS boot image and the EFI System Partition are not files in the ISO but rather unnamed block areas.
If you don't go the way of appending a session by fixed growisofs or by
then you need to extract those areas
(El Torito gives LBAs in blocks of 2048 but sizes in blocks of 512. 4 * 420 = 1680. The BIOS image size of 1204 blocks of 2048 bytes is estimated by the lowest filesystem object LBA that's above 420. Possibly it is smaller but any oversize should not harm.)
Then there is the MBR code for BIOS booting from USB stick:
If you do not plan to boot by BIOS, then bios_boot.img and mbr_code.img are not needed.
Building a new ISO from unpacked and mainpulated tree $HOME/files_for_iso and the extracted image files
This will yield no GPT but rather an MBR partition table with two partitions of type 0x83 for the ISO filesystem and 0xef for the EFI System Partition.
(Whether BIOS boots from USB stick would have to be tested. Many MBRs need info patched in to find the next stage of boot programs.)