Web lists-archives.com

Re: Setting a USB for multi usages




Hi,

MENGUAL Jean-Philippe wrote:
> My purpose is having a USB stick splitted in 2 parts:
> 1. MBR + partitions: a Debian installer from an ISO
> 2. A blank partition to install data or whatver
>
> While I know to "burn" an iso on a key via dd, how can I do to have a clean
> installer but using key for other usages?

Put the ISO onto the stick, completely deface its pseudo-GPT,
and use program fdisk to add one or more partitions.

The partition situation in a Debian ISO for x86 is not as nice
as it should/could be:

  $ /sbin/fdisk -lu debian-9.3.0-amd64-netinst.iso
  ...
  Device                          Boot Start    End Sectors  Size Id Type
  debian-9.3.0-amd64-netinst.iso1 *        0 593919  593920  290M  0 Empty
  debian-9.3.0-amd64-netinst.iso2       3760   4591     832  416K ef EFI (FAT-12/1

Note the EFI partition 2 of type 0xef sitting inside partition 1 which
is of type 0x00.
Nevertheless fdisk will add partition 3 and 4 if you ask it to do so.


There are the data of a GPT, but it is not properly announced by a
protective MBR partition of type 0xee. The GPT shows the same overlapping
partitions, which are explicitely forbidden by the GPT specs.
Thus my advise to remove the GPT header block:

  dd if=/dev/zero bs=512 seek=1 count=1 conv=notrunc of=/dev/sdX

where /dev/sdX is the device file of your USB stick.
(Option conv=notrunc is just for the case your of= target is an .iso file
 and not a disk device file.)


On a USB stick, the GPT backup header will probably not be recognized
because it will be misplaced. But an overly smart partition editor might
still find it and propose to replace your MBR partition table by that
GPT.

To kill the backup GPT header, you need to compute the last 512-byte
block number n of the ISO (in case of the 9.3.0 ISO n is 593919):

  n=$(expr $(ls -l debian-9.3.0-amd64-netinst.iso | awk '{print $5}') / 512 - 1)

and zeroize that block:

  dd if=/dev/zero bs=512 seek=$n count=1 conv=notrunc of=/dev/sdX

After this, programs like gdisk will not try to overwrite the MBR
partition table by the GPT.


Have a nice day :)

Thomas