-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild_iso.sh
More file actions
executable file
·94 lines (77 loc) · 2.78 KB
/
build_iso.sh
File metadata and controls
executable file
·94 lines (77 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env -S bash -exo pipefail
{ export PS4='+( ${BASH_SOURCE}:${LINENO} ): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; } 2>/dev/null
dnf install -y squashfs-tools xorriso yq mtools dosfstools
mkdir -p \
/work \
/work/iso-root \
/work/iso-root/boot/grub2 \
/work/iso-root/images/pxeboot \
/work/iso-root/LiveOS
cd /work || exit 1
# Create the squashfs image of the container image
mksquashfs /rootfs /work/iso-root/LiveOS/squashfs.img -all-root -noappend -e sysroot -e ostree -comp zstd -Xcompression-level 19
iso_config_file=/rootfs/usr/lib/bootc-image-builder/iso.yaml
if [[ ! -f $iso_config_file ]]; then
echo >&2 "ERROR: Missing /usr/lib/bootc-image-builder/iso.yaml file"
exit 1
fi
iso_label=$(yq '.label' <$iso_config_file)
# Copy initrd and kernel
cp -av /rootfs/usr/lib/modules/*/initramfs.img /work/iso-root/images/pxeboot/initrd.img
cp -av /rootfs/usr/lib/modules/*/vmlinuz /work/iso-root/images/pxeboot/vmlinuz
# Copy GRUB modules
for grub_arch in i386-pc arm64-efi; do
[ -f "/rootfs/usr/lib/grub/$grub_arch" ] || continue
echo >&2 "Found $grub_arch files, copying to /work/iso-root/boot/grub2/$grub_arch ..."
cp -avT /rootfs/usr/lib/grub/$grub_arch /work/iso-root/boot/grub2/$grub_arch
done
# Copy efi dir
cp -avT /rootfs/boot/efi/EFI /work/EFI
# Generate grub.cfg
{ grub_cfg="$(</dev/stdin)"; } <<EOF
set timeout=$(yq '.grub2.timeout // 10' <$iso_config_file)
set default="$(yq '.grub2.default // 0' <$iso_config_file)"
set menu_auto_hide=false
function load_video {
insmod all_video
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod chain
search --no-floppy --set=root -l '$iso_label'
EOF
for i in $(yq '.grub2.entries | keys | .[]' <"$iso_config_file"); do
entry_name=$(yq ".grub2.entries[$i].name" <"$iso_config_file")
entry_linux=$(yq ".grub2.entries[$i].linux" <"$iso_config_file")
entry_initrd=$(yq ".grub2.entries[$i].initrd" <"$iso_config_file")
{ grub_cfg+=$'\n'"$(</dev/stdin)"; } <<EOF
menuentry '$entry_name' {
linux $entry_linux
initrd $entry_initrd
}
EOF
done
for dir in /work/EFI/* /work/iso-root/boot/grub2; do
echo "$grub_cfg" >"$dir/grub.cfg"
done
# For some reason, fedora also copies EFI into /boot/EFI (?), probably because of hardcoded prefix in grub/shim
cp -avT /work/EFI /work/iso-root/EFI
# Generate uefi.img
pushd /work || exit 1
truncate -s 100M /work/uefi.img
mkfs.fat -F32 /work/uefi.img
mcopy -v -i /work/uefi.img -s /work/EFI ::
xorriso -as mkisofs \
-R \
-V "$iso_label" \
-partition_offset 16 \
-appended_part_as_gpt \
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ./uefi.img \
-iso_mbr_part_type EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 \
-e --interval:appended_partition_2:all:: \
-no-emul-boot \
-iso-level 3 \
-o "/output/$iso_label.iso" \
iso-root