如何使用 Linux shell 脚本自定义 Webconverger 的 ISO 映像?

How can I customise an ISO image of Webconverger with a Linux shell script?

我想写一个简单的 shell 脚本,下载 Webconverger 的最新 ISO 映像并更改 /boot/live.cfg 中 grub 的引导参数。

这就是我到目前为止所做的:

#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso

# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger

mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/

sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger

# 3. Change the file in the development folder. 
chmod -R 777 devfolder/

rm devfolder/boot/live.cfg
echo \
"DEFAULT de

label de
    menu label Start
    kernel /live/vmlinuz
    append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://www.google.de/" \
> devfolder/boot/live.cfg

# 4. Create a new ISO image
mkisofs -o new.iso -l devfolder
rm -r devfolder/

生成的 ISO 无法启动。 我假设问题的原因是,我必须 运行 具有 root 权限的整个脚本和 我需要一个更复杂的 mkisofs 命令。

有人知道如何使用 shell 脚本为 Webconverger 生成正确的 ISO 映像吗?或者整个过程是否有替代方法?类似于 ISO Master 但用于命令行?


更新

我已将代码片段替换为实际的 shell 脚本。所以更容易测试。这是命令行输出(没有 wget 部分):

mount: /dev/loop0 is write-protected, mounting read-only
sending incremental file list
./
boot/
boot/boot.bin
boot/boot.cat
boot/live.cfg
boot/syslinux/
boot/syslinux/ldlinux.c32
boot/syslinux/libcom32.c32
boot/syslinux/libutil.c32
boot/syslinux/splash.png
boot/syslinux/syslinux.cfg
boot/syslinux/vesainfo.c32
boot/syslinux/vesamenu.c32
live/
live/initrd.img
live/vmlinuz
live/filesystem.git/
live/filesystem.git/HEAD
live/filesystem.git/config
live/filesystem.git/description
live/filesystem.git/packed-refs
live/filesystem.git/shallow
live/filesystem.git/branches/
live/filesystem.git/hooks/
live/filesystem.git/hooks/applypatch-msg.sample
live/filesystem.git/hooks/commit-msg.sample
live/filesystem.git/hooks/post-update.sample
live/filesystem.git/hooks/pre-applypatch.sample
live/filesystem.git/hooks/pre-commit.sample
live/filesystem.git/hooks/pre-push.sample
live/filesystem.git/hooks/pre-rebase.sample
live/filesystem.git/hooks/pre-receive.sample
live/filesystem.git/hooks/prepare-commit-msg.sample
live/filesystem.git/hooks/update.sample
live/filesystem.git/info/
live/filesystem.git/info/exclude
live/filesystem.git/objects/
live/filesystem.git/objects/info/
live/filesystem.git/objects/pack/
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.idx
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.pack
live/filesystem.git/refs/
live/filesystem.git/refs/heads/
live/filesystem.git/refs/heads/master
live/filesystem.git/refs/remotes/
live/filesystem.git/refs/remotes/origin/
live/filesystem.git/refs/remotes/origin/HEAD
live/filesystem.git/refs/tags/
live/filesystem.git/refs/tags/initial-revision

sent 598,528,659 bytes  received 726 bytes  239,411,754.00 bytes/sec
total size is 598,380,033  speedup is 1.00
I: -input-charset not specified, using utf-8 (detected in locale settings)
  1.71% done, estimate finish Tue Jul 10 20:12:54 2018
  3.42% done, estimate finish Tue Jul 10 20:12:54 2018
  5.13% done, estimate finish Tue Jul 10 20:13:13 2018
  6.84% done, estimate finish Tue Jul 10 20:13:08 2018
  8.55% done, estimate finish Tue Jul 10 20:13:05 2018
 10.26% done, estimate finish Tue Jul 10 20:13:03 2018
 11.97% done, estimate finish Tue Jul 10 20:13:02 2018
 13.68% done, estimate finish Tue Jul 10 20:13:01 2018
 15.39% done, estimate finish Tue Jul 10 20:13:00 2018
 17.10% done, estimate finish Tue Jul 10 20:12:59 2018
 18.81% done, estimate finish Tue Jul 10 20:12:59 2018
 20.52% done, estimate finish Tue Jul 10 20:12:58 2018
 22.23% done, estimate finish Tue Jul 10 20:12:58 2018
 23.94% done, estimate finish Tue Jul 10 20:12:58 2018
 25.65% done, estimate finish Tue Jul 10 20:12:57 2018
 27.36% done, estimate finish Tue Jul 10 20:12:57 2018
 29.07% done, estimate finish Tue Jul 10 20:12:57 2018
 30.78% done, estimate finish Tue Jul 10 20:12:57 2018
 32.49% done, estimate finish Tue Jul 10 20:12:57 2018
 34.20% done, estimate finish Tue Jul 10 20:12:56 2018
 35.91% done, estimate finish Tue Jul 10 20:12:56 2018
 37.62% done, estimate finish Tue Jul 10 20:12:56 2018
 39.33% done, estimate finish Tue Jul 10 20:12:56 2018
 41.04% done, estimate finish Tue Jul 10 20:12:56 2018
 42.75% done, estimate finish Tue Jul 10 20:12:56 2018
 44.46% done, estimate finish Tue Jul 10 20:12:56 2018
 46.17% done, estimate finish Tue Jul 10 20:12:56 2018
 47.88% done, estimate finish Tue Jul 10 20:12:56 2018
 49.59% done, estimate finish Tue Jul 10 20:12:56 2018
 51.30% done, estimate finish Tue Jul 10 20:12:55 2018
 53.02% done, estimate finish Tue Jul 10 20:12:55 2018
 54.72% done, estimate finish Tue Jul 10 20:12:55 2018
 56.44% done, estimate finish Tue Jul 10 20:12:55 2018
 58.14% done, estimate finish Tue Jul 10 20:12:55 2018
 59.86% done, estimate finish Tue Jul 10 20:12:55 2018
 61.56% done, estimate finish Tue Jul 10 20:12:55 2018
 63.28% done, estimate finish Tue Jul 10 20:12:55 2018
 64.98% done, estimate finish Tue Jul 10 20:12:55 2018
 66.70% done, estimate finish Tue Jul 10 20:12:55 2018
 68.40% done, estimate finish Tue Jul 10 20:12:55 2018
 70.12% done, estimate finish Tue Jul 10 20:12:55 2018
 71.82% done, estimate finish Tue Jul 10 20:12:55 2018
 73.54% done, estimate finish Tue Jul 10 20:12:55 2018
 75.24% done, estimate finish Tue Jul 10 20:12:55 2018
 76.96% done, estimate finish Tue Jul 10 20:12:55 2018
 78.66% done, estimate finish Tue Jul 10 20:12:55 2018
 80.38% done, estimate finish Tue Jul 10 20:12:55 2018
 82.08% done, estimate finish Tue Jul 10 20:12:55 2018
 83.80% done, estimate finish Tue Jul 10 20:12:55 2018
 85.50% done, estimate finish Tue Jul 10 20:12:55 2018
 87.22% done, estimate finish Tue Jul 10 20:12:55 2018
 88.92% done, estimate finish Tue Jul 10 20:12:55 2018
 90.64% done, estimate finish Tue Jul 10 20:12:55 2018
 92.34% done, estimate finish Tue Jul 10 20:12:55 2018
 94.06% done, estimate finish Tue Jul 10 20:12:55 2018
 95.76% done, estimate finish Tue Jul 10 20:12:55 2018
 97.48% done, estimate finish Tue Jul 10 20:12:55 2018
 99.18% done, estimate finish Tue Jul 10 20:12:55 2018
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 30720
Path table size(bytes): 222
Max brk space used 2b000
292387 extents written (571 MB)

这是我在 VirtualBox 中得到的: Click here!

您想要做的是生成一张 El Torito 可引导 CD,其第一个字节为 MBR

mkisofs(8) 需要一些特殊选项来创建 "El Torito" 可启动 CD:

mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder

解释:

-r -J: Enable Joliet and Rock Ridge meta data.
-l: Allow long filenames.
-V: Set volume ID. Optional.
-b: Specify the "El Torito" boot image.
-c: Specify the "El Torito" boot catalog.
-no-emul-boot: Specify that this is an "El Torito" bootable CD.
-boot-load-size: number of 512 bytes sector to load (4 is what usually works)
-boot-info-table: modify the original boot image appending the Boot Info Table

然后,如果您只想 dd USB 驱动器上的文件,您需要将 MBR 写入 ISO:

isohybrid new.iso

所以问题的完整答案是:

#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso

# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger

mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/

sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger

# 3. Change the file in the development folder. 
echo \
"DEFAULT de

label de
    menu label Start
    kernel /live/vmlinuz
    append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://duckduckgo.com nobrand" \
| sudo tee devfolder/boot/live.cfg

# 4. Create a new ISO image
sudo mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder
sudo isohybrid new.iso
sudo rm -r devfolder/

出于某种原因,dd 不适用于 Webconverger 图像。即使是未触及的 latest.iso 也无法创建可启动的 USB 闪存驱动器。所以我用了Win32DiskImager.