Debian

在修改後的 iso 映像上啟動

  • July 17, 2022

我嘗試修改一個 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 上執行良好。我真的不知道它不適用於標準機器。

你有什麼主意嗎?

可啟動 USB 媒體創建工具 Rufus 的開發人員在 SuperUser.SE 上寫了這個很棒的答案,它以一種可以理解的方式描述了導致您的問題的幕後復雜性。

使用genisoimage,您只能將 ISO 文件作為(真實或虛擬)CD/DVD 引導。

要將其作為類似 HDD 的設備啟動(即寫入 U 盤時),您需要在映像的最開始有一個主引導記錄,並且它需要包含有效的 MBR 分區表,因此映像也可以有效地解釋為硬碟映像。

根據為實現這一目標而開發的第一個工具,這有時被稱為“isohybrid ISO 映像”。在 Debian 11xorriso上,能夠創建這樣的圖像文件。

使用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,您可能並不關心這一點。

引用自:https://unix.stackexchange.com/questions/710180