From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Thomas Schmitt" Subject: Re: ISO installer image: GPT versus MBR partitions Date: Wed, 24 Apr 2019 12:34:16 +0200 Message-ID: <6546677712020146532@scdbackup.webframe.org> References: <20190424091323.uyuxd3ib7zfw2cut@pelzflorian.localdomain> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:37168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJFDq-0002ec-9j for guix-devel@gnu.org; Wed, 24 Apr 2019 06:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJFBy-0001OU-64 for guix-devel@gnu.org; Wed, 24 Apr 2019 06:31:55 -0400 In-Reply-To: <20190424091323.uyuxd3ib7zfw2cut@pelzflorian.localdomain> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: bug-xorriso@gnu.org Cc: guix-devel@gnu.org Hi, Florian Pelz wrote: > Sorry, I meant to quote this aspect: I wrote: > > > One can read trailing garbage not only from USB sticks but also from > > > most DVD types. Florian Pelz wrote: > > So=E2=80=A6 GPT is wrong for some optical media too? I wrote: > Not in this aspect. GPT partitions must not start at block 0. > So the overall ISO superblock is not mountable as partition and thus > free to claim the full image size as filesystem size. I already understood you correctly ... i think. :)) GPT partitioned ISO are not hampered from telling the full image size as size of the ISO 9660 filesystem. $ /sbin/gdisk -l guixsd-install-0.15.0.i686-linux.iso ... Number Start (sector) End (sector) Size Code Name 1 64 34107 16.6 MiB 0700 Gap0 2 34108 39867 2.8 MiB EF00 EFI boot partit= ion 3 39868 1815727 867.1 MiB AF00 HFSPLUS 4 1815728 1816327 300.0 KiB 0700 Gap1 $ expr $(/sbin/isosize guixsd-install-0.15.0.i686-linux.iso) / 512 1816376 The isosize is a bit larger than the end of partition 4, because after this partition comes the GPT backup. The isosize matches the image file size: $ expr $(ls -l guixsd-install-0.15.0.i686-linux.iso | awk '{print $5}') = / 512 1816376 But an MBR partition which begins by block 0 and is mountable as ISO 9660 filesystem keeps its ISO superblock from telling a size larger than the partition. So it cannot claim an appended partition 2 as part of its range= . $ export MKRESCUE_SED_MODE=3Dmbr_hfs $ grub-mkrescue --xorriso=3D./grub-mkrescue-sed.sh -o output.iso minimal= \ --iso_mbr_part_type 0x83 ... $ /sbin/fdisk -l output.iso ... Disklabel type: dos ... Device Boot Start End Sectors Size Id Type output.iso1 * 0 28371 28372 13.9M 83 Linux output.iso2 28372 34131 5760 2.8M ef EFI (FAT-12/16/32) $ expr $(/sbin/isosize output.iso) / 512 28372 This discrepancy of image file size and isosize is undesirable when the image file itself cannot say its size any more, because it is on USB stick or a DVD which delivers more bytes than were written as image. So i propose partition offset 16 to get the partition superblock away from being mountable by the base device. $ export MKRESCUE_SED_MODE=3Dmbr_hfs $ grub-mkrescue --xorriso=3D./grub-mkrescue-sed.sh -o output.iso minimal= \ -partition_offset 16 --iso_mbr_part_type 0x83 This yields $ /sbin/fdisk -l output.iso ... Disklabel type: dos ... Device Boot Start End Sectors Size Id Type output.iso1 * 64 28695 28632 14M 83 Linux output.iso2 28696 34455 5760 2.8M ef EFI (FAT-12/16/32) The ISO filesystem of the overall image then claims the image file size $ expr $(/sbin/isosize output.iso) / 512 34456 With the partition's ISO filesystem we only get the partition size: $ dd if=3Doutput.iso bs=3D512 skip=3D64 of=3Dpartition1.iso $ expr $(/sbin/isosize partition1.iso) / 512 28632 This is how it should be. The ISOs of Fedora, Debian, Ubuntu, and others are MBR partitioned and most of them have no partition offset 16. But despite that fact they can claim the full image size as ISO 9660 filesystem size. This is possible because partition 1 covers the whole image and partition = 2 is located inside partition 1. Strictly illegal in UEFI specs, unless the outer partition has MBR partition type 0x00 and thus does not exist for EFI and some partition editors. (I.e. this is a really dirty hack.) $ /sbin/fdisk -l debian-live-9.8.0-amd64-xfce.iso ... Disklabel type: dos ... Device Boot Start End Sectors Size Id Ty= pe debian-live-9.8.0-amd64-xfce.iso1 * 0 3811391 3811392 1.8G 0 Em= pty debian-live-9.8.0-amd64-xfce.iso2 1432 2263 832 416K ef EF= I (FAT-1 $ expr $(/sbin/isosize debian-live-9.8.0-amd64-xfce.iso) / 512 3811392 Old /sbin/gdisk only reports partition 2: $ /sbin/gdisk -l debian-live-9.8.0-amd64-xfce.iso ... Found valid MBR and GPT. Which do you want to use? ... Your answer: 1 ... Number Start (sector) End (sector) Size Code Name 2 1432 2263 416.0 KiB EF00 EFI System Have a nice day :) Thomas