0

I try to modify an iso file, especially a debian installer (debian-11.4.0-i386-netinst.iso) , and boot on it. The following code extract the content of an iso file and recreate a new iso file:

mkdir -p tmp_dir

bsdtar -C tmp_dir -xf debian-11.4.0-i386-netinst.iso

genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat \
            -no-emul-boot -boot-load-size 4 -boot-info-table \
            -o new_image.iso tmp_dir

Then, I copied the new iso file on my USB stick:

sudo dd if=new_image.iso of=/dev/sdg status=progress

Then, lsblk gives the following output:

$ lsblk /dev/sdg
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdg    8:96   1 29,4G  0 disk 

But I cannot boot on it. Do you know why?

Here some other information:

  • First, I can boot on the USB stick if I create it with the original image:

sudo dd if=debian-11.4.0-i386-netinst.iso of=/dev/sdg status=progress

After that, lsblk gives me the following output:

$ lsblk /dev/sdg
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdg      8:96   1 29,4G  0 disk 
├─sdg1   8:97   1  471M  0 part 
└─sdg2   8:98   1  1,9M  0 part 

Note that we can see two partitions (I have no partition with the new image)

  • Second, the new image works well on vmware. I don't really know it doesn't work with a standard machine.

Do you have any idea?

2 Answers 2

2

The developer of the bootable-USB-media creator tool Rufus has written this awesome answer on SuperUser.SE which describes the behind-the-scenes complexity that is causing your problems in a understandable way.

With genisoimage, you can only make the ISO file bootable as a (real or virtual) CD/DVD.

To boot it as a HDD-like device (i.e. when written to a USB stick), you need a Master Boot Record at the very beginning of the image, and it needs to include a valid MBR partition table, so the image can also be validly interpreted as a hard disk image.

This is sometimes known as an "isohybrid ISO image", according to the first tool that was developed to achieve that. On Debian 11, xorriso is capable of creating such image files.

With xorriso -indev debian-11.4.0-i386-netinst.iso -report_el_torito cmd and/or xorriso -indev debian-11.4.0-i386-netinst.iso -boot_image any show_status, you can have xorriso examine the original image and describe the boot structures on it as options you can feed back to xorriso. Here's what I got:

$ xorriso -indev debian-11.4.0-i386-netinst.iso -report_el_torito cmd
xorriso 1.5.2 : RockRidge filesystem manipulator, libburnia project.

xorriso : NOTE : Loading ISO image tree from LBA 0
xorriso : UPDATE :    1651 nodes read in 1 seconds
xorriso : NOTE : Detected El-Torito boot information which currently is set to be discarded
Drive current: -indev 'debian-11.4.0-i386-netinst.iso'
Media current: stdio file, overwriteable
Media status : is written , is appendable
Boot record  : El Torito , MBR isohybrid cyl-align-on GPT APM
Media summary: 1 session, 241152 data blocks,  471m data, 1781g free
Volume id    : 'Debian 11.4.0 i386 n'
-volid 'Debian 11.4.0 i386 n'
-volume_date uuid '2022070910381400'
-boot_image isolinux system_area=--interval:imported_iso:0s-15s:zero_mbrpt,zero_gpt,zero_apm:'debian-11.4.0-i386-netinst.iso'
-boot_image any partition_cyl_align=on
-boot_image any partition_offset=0
-boot_image any partition_hd_cyl=64
-boot_image any partition_sec_hd=32
-boot_image any mbr_force_bootable=on
-boot_image any apm_block_size=2048
-boot_image any iso_mbr_part_type=0x00
-boot_image any cat_path='/isolinux/boot.cat'
-boot_image isolinux bin_path='/isolinux/isolinux.bin'
-boot_image any platform_id=0x00
-boot_image any emul_type=no_emulation
-boot_image any load_size=2048
-boot_image any boot_info_table=on
-boot_image any next
-boot_image any efi_path='/boot/grub/efi.img'
-boot_image any platform_id=0xef
-boot_image any emul_type=no_emulation
-boot_image any load_size=2031616
-boot_image isolinux partition_entry=gpt_basdat
-boot_image isolinux partition_entry=apm_hfsplus

and

$ xorriso -indev debian-11.4.0-i386-netinst.iso -boot_image any show_status
xorriso 1.5.2 : RockRidge filesystem manipulator, libburnia project.

xorriso : NOTE : Loading ISO image tree from LBA 0
xorriso : UPDATE :    1651 nodes read in 1 seconds
xorriso : NOTE : Detected El-Torito boot information which currently is set to be discarded
Drive current: -indev 'debian-11.4.0-i386-netinst.iso'
Media current: stdio file, overwriteable
Media status : is written , is appendable
Boot record  : El Torito , MBR isohybrid cyl-align-on GPT APM
Media summary: 1 session, 241152 data blocks,  471m data, 1781g free
Volume id    : 'Debian 11.4.0 i386 n'
------------------------------------
Status of loaded boot image        :
------------------------------------
Boot record  : El Torito , MBR isohybrid cyl-align-on GPT APM
Boot catalog : '/isolinux/boot.cat'
Boot image   : '/isolinux/isolinux.bin' , boot_info_table=on
Boot image   : '/boot/grub/efi.img' , platform_id=0xEF 
------------------------------------
Boot image settings for next commit:
------------------------------------
-boot_image any discard
-boot_image any bin_path=''
-boot_image any emul_type=no_emulation
-boot_image any platform_id=0x00
-boot_image any boot_info_table=off
-boot_image grub grub2_boot_info=off
-boot_image any load_size=2048
-boot_image any sel_crit=0000000000000000000000000000000000000000
-boot_image any id_string=00000000000000000000000000000000000000000000000000000000
-boot_image isolinux partition_entry=off
-boot_image any appended_part_as=mbr
-boot_image any system_area=''
-boot_image any partition_offset=0
-boot_image any partition_sec_hd=0
-boot_image any partition_hd_cyl=0
-boot_image any partition_cyl_align=auto
-boot_image grub partition_table=off
-boot_image any mbr_force_bootable=off
-boot_image any appended_part_as=mbr
-boot_image any part_like_isohybrid=off
-boot_image any iso_mbr_part_type=default
-boot_image any gpt_disk_guid=random
-boot_image any chrp_boot_part=off
-boot_image any prep_boot_part=''
-boot_image any efi_boot_part=''
-boot_image any hfsplus_serial=0000000000000000
-boot_image any hfsplus_block_size=0
-boot_image any apm_block_size=0
------------------------------------

Most of the "magic" that makes the resulting ISO image bootable also when written on a USB stick is specified on the long line that starts with -boot_image isolinux system_area=....

Anything that comes after -boot_image any next is related to UEFI support, and based on the boot options you used with your genisoimage, you might not care about that.

1
  • In addition to the very nice and complete answer of telcoM, this answer led me to the tool isohybrid. After having generated the new image new_image.iso with genisoimage, I simply ran isohybrid new_image.iso Commented Jul 18, 2022 at 15:26
0

Thanks @telcoM for your particularly complete answer.

I didn't succeed in building an EFI bootable AMD64 image of Debian, bootable in every situation (on a DVD or on a USB stick or...). Going back to the fundamentals, I found instructions for Repacking a Debian ISO with its original boot equipment.

Adapting the contents to 2023's ISO, I was able to write and sucessfully test the following procedure.

For the example, I will modify Debian 11.6 AMD64 stable ISO. I will add in its /firmware directory all firmware you can find on a Debian computer in /usr/lib/firmware after installing the following 3 Debian packages: firmware-linux firmware-linux-free firmware-linux-nonfree:

sudo apt install firmware-linux firmware-linux-free firmware-linux-nonfree

And after still for the example, I will repack the ISO, copying it on a USB key and successfully boot in legacy (MBR) and in UEFI mode The image also work when burned on a DVD.

Make a root mkiso directory:

mkdir /home/nba/mkiso
cd /home/nba/mkiso
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-11.6.0-amd64-DVD-1.iso

Extract source ISO:

mkdir deb
sudo apt install xorriso
xorriso -osirrox on -indev deb11.6-nba-amd64.iso -extract / ./deb

or

sudo apt install bsdtar
bsdtar -C ./deb -xf debian-11.6.0-amd64-DVD-1.iso

Add files / firmware. We want to add firmware to the ISO image:

sudo apt install firmware-linux firmware-linux-free firmware-linux-nonfree

mkdir -p /home/nba/mkiso/fw
cp -rf /usr/lib/firmware /home/nba/mkiso/fw/

Extract xorriso build command from source ISO:

cat deb/.disk/mkisofs


xorriso -as mkisofs -r -checksum_algorithm_iso sha256,sha512 -V 'Debian 11.6.0 amd64 1' -o /srv/cdbuilder.debian.org/dst/deb-cd/out/3bullseyeamd64/debian-11.6.0-amd64-DVD-1.iso -checksum-list /srv/cdbuilder.debian.org/src/deb-cd/tmp/3bullseyeamd64/bullseye/checksum-check -jigdo-checksum-algorithm md5 -jigdo-force-checksum /pool/ -jigdo-min-file-size 1024 -jigdo-exclude 'README*' -jigdo-exclude /doc/ -jigdo-exclude /md5sum.txt -jigdo-exclude /.disk/ -jigdo-exclude /pics/ -jigdo-exclude 'Release*' -jigdo-exclude 'Packages*' -jigdo-exclude 'Sources*' -jigdo-jigdo /srv/cdbuilder.debian.org/dst/deb-cd/out/3bullseyeamd64/debian-11.6.0-amd64-DVD-1.jigdo -jigdo-template /srv/cdbuilder.debian.org/dst/deb-cd/out/3bullseyeamd64/debian-11.6.0-amd64-DVD-1.template -jigdo-map Debian=/srv/cdbuilder.debian.org/src/ftp/debian/ -jigdo-exclude boot1 -J -joliet-long -cache-inodes -isohybrid-mbr syslinux/usr/lib/ISOLINUX/isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus boot1 CD1

Modify xorriso build command (remove -jidgo options + related checksum...):

xorriso -as mkisofs -r -V 'deb11.6-nba-amd64' -o ./deb11.6-nba-amd64.iso -J -joliet-long -cache-inodes -isohybrid-mbr ./isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus deb fw

Generate MBR by extracting first 432 bytes from source ISO:

cd /home/nba/mkiso
dd if=debian-11.6.0-amd64-DVD-1.iso of=isohdpfx.bin bs=1 count=432 

Build new iso (adding deb/ and fw/firmware to the ISO):

xorriso -as mkisofs -r -V 'deb11.6-nba-amd64' -o ./deb11.6-nba-amd64.iso -J -joliet-long -cache-inodes -isohybrid-mbr ./isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus deb fw

Verify by extracting the newly created ISO:

mkdir /home/nba/mkiso/deb2
cd /home/nba/mkiso/
xorriso -osirrox on -indev deb11.6-nba-amd64.iso -extract / deb2

Verify firmware are present in /home/nba/mkiso/deb2/firmware:

ls /home/nba/mkiso/deb2/firmware

Test boot: use xorriso -report_system_area options on source ISO and on new ISO and compare:

xorriso -indev debian-11.6.0-amd64-DVD-1.iso -report_system_area as_mkisofs
xorriso -indev deb11.6-nba-amd64.iso -report_system_area as_mkisofs

Verify you have line:

-isohybrid-mbr --interval:local_fs:0s-15s:zero_mbrpt,zero_gpt,zero_apm:'deb11.6-nba-amd64.iso'

and lines:

-eltorito-alt-boot
-e '/boot/grub/efi.img'
-no-emul-boot

Copy to USB key and try to boot:

sudo dd if=deb11.6-nba-amd64.iso of=/dev/sda bs=256M status=progress

Reboot on key !

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .