创建自定义 Ubuntu 22.04 live 服务器 iso

创建自定义 Ubuntu 22.04 live 服务器 iso

这是一个后续问题Ubuntu 22.04 构建 ISO(MBR 和 EFI)。不幸的是,我没有足够的声誉分数来对原作发表评论。

我也为安装目的创建了修改过的 iso 映像,但在本例中,我使用的是实时服务器 iso。我改编了非常有用的答案托马斯·施密特在上述 URL 中。在调整使用 22.04 服务器 iso 并刻录我的自定义 iso 后,我得到了一个可以工作的启动 USB 棒,但备份 GPT 表有问题。以下是它安装在我的笔记本电脑上时的 dmesg 摘录:

[3991990.397058] GPT:Primary header thinks Alt. header is not at the end of the disk.
[3991990.397063] GPT:2872323 != 30310399
[3991990.397066] GPT:Alternate GPT header not at the end of the disk.
[3991990.397067] GPT:2872323 != 30310399

从该 USB 启动时会出现类似的消息。在这种情况下,内核会发出抱怨并调整自身,并显示“备份 GPT 表已损坏,但主表似乎正常,因此将使用该表”之类的消息。但是我知道一定有一种方法可以调整 xorriso 来修复我不知道的辅助表。

当然,分区布局与桌面版 iso 不同。为了解释下面代码段中的数字,下面是该布局。

#/sbin/fdisk -l ubuntu-22.04-live-server-amd64.iso
Disk ubuntu-22.04-live-server-amd64.iso: 1.37 GiB, 1466714112 bytes, 2864676 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C84E0225-4BE7-447A-9FA1-EBF040BDC01F

Device                                Start     End Sectors  Size Type
ubuntu-22.04-live-server-amd64.iso1      64 2855515 2855452  1.4G Microsoft basic data
ubuntu-22.04-live-server-amd64.iso2 2855516 2864011    8496  4.2M EFI System
ubuntu-22.04-live-server-amd64.iso3 2864012 2864611     600  300K Microsoft basic data

根据 Thomas Schmitt 在桌面 iso 的回答中所写的内容,我编写了这个 bash 脚本:

#!/bin/bash

#output name of image
IMAGE=ubuntu22_04_custom.iso

OPWD=/home/[something]/ubuntu_22_04_isomaker/

cd $OPWD

#this is where the files for the custom iso are located
BUILD=$OPWD/iso_raw/

#this is a copy of the original iso as downloaded
BASE_IMAGE=$OPWD/baseiso/ubuntu-22.04-live-server-amd64.iso

#extract MBR / EFI
MBR_IMAGE=$OPWD/partitions/ubuntu_isohybrid_mbr.img
EFI_IMAGE=$OPWD/partitions/efi.img
BASE_IMAGE=$OPWD/baseiso/ubuntu-22.04-live-server-amd64.iso

dd if="$BASE_IMAGE" bs=1 count=432 of="$MBR_IMAGE"

dd if="$BASE_IMAGE" bs=512 skip=2855516 count=8496 of="$EFI_IMAGE"



# make the md5sum for the modified iso
cd $BUILD

rm -f md5sum.txt
find . -type f -not -name md5sum.txt -print0 | xargs -0 md5sum | tee md5sum.txt

cd $OPWD


# Finally pack up an ISO the new way
/usr/local/bin/xorriso -as mkisofs -r \
  -V 'Ubuntu 22.04' \
  -o "$IMAGE" \
  --grub2-mbr "$MBR_IMAGE" \
  -partition_offset 16 \
  --mbr-force-bootable \
  -append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b $EFI_IMAGE \
  -appended_part_as_gpt \
  -iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
  -c '/boot.catalog' \
  -b '/boot/grub/i386-pc/eltorito.img' \
    -no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
  -eltorito-alt-boot \
  -e '--interval:appended_partition_2:::' \
    -no-emul-boot \
  "$BUILD"

exit 0

记录显示,正在使用的 xorriso 版本是 1.5.4.pl02(昨天构建的)。

那么我该如何让 xorriso 正确写入辅助 GPT 表?

答案1

除非您的 USB 存储棒提供的容量与映像所需的大小完全相同,否则投诉是不可避免的。GPT 规范规定在存储设备的开头有一个主分区表,在其末尾有一个备份表。在 ISO 映像中,此表是它所属的位置。但复制到 USB 存储棒后,备份表后仍有未使用的块。

除非您想要向 USB 棒添加分区,否则此投诉不会造成任何损害。分区编辑器将发出类似的投诉,并应提供修复这种情况的建议。我在我的邮箱中发现了一份使用 sfdisk 2.33.1 进行实验的成功报告,该实验添加了一个名为“DATA”的分区,该分区占用了 USB 棒在 /dev/sdc 的所有未使用空间:


echo 'name=DATA' | sudo sfdisk -a /dev/sdc

这也挽救了备份 GPT 的情况。

使用 MBR 分区表代替 GPT 可以避免这个问题。但是,已知有些 EFI 实现不接受没有 GPT 气味的 USB 启动盘。旧的 Ubuntu ISO 布局就像一个背上绑着无效 GPT 的 jackalope。现代分区编辑器通常将其视为重大磁盘故障的不良结果。放错位置的备份 GPT 的情况对他们来说没那么令人愤怒。

如果您对 xorriso 还有疑问,请发送邮件至:

[电子邮件保护]

我不能保证我会在 askubuntu.com 上看到您的帖子或者它能允许我回答。

祝你今天过得愉快 :)

托马斯

相关内容