Bug 270393

Summary: hybrid ISO images report broken partition table
Product: Base System Reporter: Ed Maste <emaste>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: grahamperrin
Priority: --- Keywords: install, standards
Version: CURRENT   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203531

Description Ed Maste freebsd_committer freebsd_triage 2023-03-22 01:00:29 UTC
# mdconfig -a -f images/FreeBSD-13.2-RC3-amd64-disc1.iso 
md2
# gpart show md2 iso9660/13_2_RC3_AMD64_CD

=>      3  2100567  md2  GPT  (1.0G) [CORRUPT]
        3       26    1  freebsd-boot  (13K)
       29       51       - free -  (26K)
       80     4096    2  efi  (2.0M)
     4176  2096394       - free -  (1.0G)

=>      3  2100567  iso9660/13_2_RC3_AMD64_CD  GPT  (1.0G) [CORRUPT]
        3       26                          1  freebsd-boot  (13K)
       29       51                             - free -  (26K)
       80     4096                          2  efi  (2.0M)
     4176  2096394                             - free -  (1.0G)
Comment 1 Ed Maste freebsd_committer freebsd_triage 2023-03-22 14:42:38 UTC
They hybrid ISOs are created by copying the first 32K from a GPT image into the output image, overwriting the iso9660 system area:

   113          # Create a GPT image containing the partitions we need for hybrid boot.
   114          hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX)
   115          if [ "$(uname -s)" = "Linux" ]; then
   116                  imgsize=`stat -c %s "$NAME"`
   117          else
   118                  imgsize=`stat -f %z "$NAME"`
   119          fi
   120          $MKIMG -s gpt \
   121              --capacity $imgsize \
   122              -b "$BASEBITSDIR/boot/pmbr" \
   123              -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
   124              $espparam \
   125              -o $hybridfilename
   126
   127          # Drop the PMBR, GPT, and boot code into the System Area of the ISO.
   128          dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc
   129          rm -f $hybridfilename

This completely ignores the secondary GPT. We need to copy it as well, enlarging the original ISO image if necessary.