在修改后的 iso 映像上启动

在修改后的 iso 映像上启动

我尝试修改 iso 文件,尤其是 debian 安装程序 (debian-11.4.0-i386-netinst.iso) ,然后启动它。以下代码提取 iso 文件的内容并重新创建一个新的 iso 文件:

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

然后,我将新的 iso 文件复制到 U 盘上:

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

然后,lsblk给出以下输出:

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

但我无法启动它。你知道为什么吗?

这里还有一些其他信息:

  • 首先,如果我使用原始映像创建 U 盘,我可以在 U 盘上启动:

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

之后,lsblk给我以下输出:

$ 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 

请注意,我们可以看到两个分区(我的新映像没有分区)

  • 其次,新镜像在 vmware 上运行良好。我真的不知道它不适用于标准机器。

你有什么主意吗?

答案1

可启动 USB 媒体创建工具 Rufus 的开发者写道SuperUser.SE 上这个很棒的答案它以一种可以理解的方式描述了导致您的问题的幕后复杂性。

使用genisoimage,您只能使 ISO 文件作为(真实或虚拟)CD/DVD 启动。

要将其作为类似 HDD 的设备启动(即写入 USB 记忆棒时),您需要在映像的最开始处有一个主启动记录,并且它需要包含有效的 MBR 分区表,因此映像也可以是有效地解释为硬盘映像。

根据为实现这一目标而开发的第一个工具,这有时被称为“等混合 ISO 映像”。在 Debian 11 上,xorriso能够创建此类映像文件。

使用xorriso -indev debian-11.4.0-i386-netinst.iso -report_el_torito cmd和/或xorriso -indev debian-11.4.0-i386-netinst.iso -boot_image any show_status,您可以xorriso检查原始映像并将其上的引导结构描述为您可以反馈给的选项xorriso。这是我得到的:

$ 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

$ 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
------------------------------------

大多数使生成的 ISO 映像在写入 USB 记忆棒时也可启动的“魔法”是在以 开头的长行中指定的-boot_image isolinux system_area=...

之后出现的任何内容都-boot_image any next与 UEFI 支持相关,并且根据您使用的引导选项genisoimage,您可能不关心这一点。

答案2

感谢@telcoM 您特别完整的回答。

我没有成功构建 Debian 的 EFI 可启动 AMD64 映像,该映像在任何情况下都可启动(在 DVD 或 USB 记忆棒上或......)。回到基础知识,我找到了相关说明 使用原始引导设备重新打包 Debian ISO

根据 2023 年的 ISO 调整内容,我能够编写并成功测试以下过程。

例如,我将修改 Debian 11.6 AMD64 稳定版 ISO。在安装以下 3 个 Debian 软件包后,我将在其目录中添加/firmware您可以在 Debian 计算机上找到的所有固件::/usr/lib/firmwarefirmware-linux firmware-linux-free firmware-linux-nonfree

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

仍然以示例为例,我将重新打包 ISO,将其复制到 USB 闪存盘上,并在传统 (MBR) 和 UEFI 模式下成功启动。该映像在刻录到 DVD 上时也可以工作。

建立根mkiso目录:

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

提取源ISO:

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

或者

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

添加文件/固件。我们想要将固件添加到 ISO 映像中:

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/

从源 ISO 中提取 xorriso 构建命令:

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

修改xorriso构建命令(删除-jidgo选项+相关校验和...):

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

通过从源 ISO 中提取前 432 个字节来生成 MBR:

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

构建新的 iso(将deb/和添加fw/firmware到 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

通过提取新创建的 ISO 进行验证:

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

验证固件是否存在于/home/nba/mkiso/deb2/firmware

ls /home/nba/mkiso/deb2/firmware

测试启动:使用xorriso -report_system_area源 ISO 和新 ISO 上的选项并进行比较:

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

验证您是否有线路:

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

和线路:

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

复制到 USB 闪存盘并尝试启动:

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

按键重启!

相关内容