Subject: bug#33639: ISO installer image is broken on i686

From: "Thomas Schmitt" <[email-masked]>
Date: Mon, 15 Apr 2019 19:55:07 +0200

Hi,

Florian Pelz wrote:
> Well this is strange.  I got fine ISO images each time (fine with no
> complaints from xorriso or fdisk and bootable in QEMU without errors),
> but after dd’ing them to different USB flash drives each time I get
> kernel output when inserting the flash drive:
> [   10.025223] GPT:Primary header thinks Alt. header is not at the end of
> the disk.

The alternative/backup header is a property of GPT which makes it
rather unsuitable for disk images. xorriso puts it correctly into the
last 512-byte block of the image. But when copied to a storage device,
it should move up to the last block of the device.
Even worse, the main GPT header at 512-byte LBA 1 needs to learn the
new address.

So i would rather advise to use a MBR partition table. Wonderfully dumb
and open ended.

I see from
  http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/build/vm.scm#n462
that program grub-mkrescue is in control of xorrisofs boot options.
Vladimir Serbinenko decided for GPT with no mountable ISO partition.

The libisoburn repo and tarball have a wrapper script by which other
boot layouts can be derived from the options which grub-mkrescue hands
over to xorrisofs:

  https://dev.lovelyhq.com/libburnia/libisoburn/raw/master/frontend/grub-mkrescue-sed.sh

To get MBR instead of GPT do:

  export MKRESCUE_SED_MODE=mbr_only
  export MKRESCUE_SED_PROTECTIVE=""

and maybe

  export MKRESCUE_SED_XORRISO=/...path/to/the/xorriso/binary/if/exotic...

Then start grub-mkrescue with the wrapper in the role of "xorriso":

  grub-mkrescue --xorriso=...path/to/grub-mkrescue-sed.sh \
                -partition_offset 16 \
                -iso_mbr_part_type 0x83 \
                \
                ...all.other.usual.arguments...

The mode "mbr_only" will move the EFI partition image out of the ISO
filesystem and rather append it after the ISO's end.

The option
  -partition_offset 16
costs the space of a second superblock and directory tree. But it brings
as benefits:
- More normal partition layout with partition 1 starting at block 64
  rather than at block 0.
- Nevertheless the partition 1 is mountable and shows the ISO content.
- The base device is mountable as the the same ISO too.
  (The ISO superblock of the base device also serves on CD or DVD.)
- Th base device superblock claims not only the ISO in partition 1 but
  also the EFI partition 2. So "/sbin/isosize" will tell the size of the
  image file, not only of the ISO filesystem.

Option
  -iso_mbr_part_type 0x83
chooses for partition 1 the MBR partitions type "Linux". (This is
purely ornamental. Nobody cares. But it looks good in partition editors.)

The partition layout of above wrapper run's output ISO will look like:

  $ /sbin/fdisk -l output.iso
  Disk output.iso: 16.5 MiB, 17338368 bytes, 33864 sectors
  Units: sectors of 1 * 512 = 512 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disklabel type: dos
  Disk identifier: 0x00000000

  Device      Boot Start   End Sectors  Size Id Type
  output.iso1 *       64 28103   28040 13.7M 83 Linux
  output.iso2      28104 33863    5760  2.8M ef EFI (FAT-12/16/32)

  $ expr $(/sbin/isosize output.iso) / 512
  33864

Have a nice day :)

Thomas