-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-ytl-image
executable file
·96 lines (73 loc) · 2.82 KB
/
build-ytl-image
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
95
96
#!/bin/sh
set -e
# This script will download a Ubuntu installation ISO image
# and modify it so that it will boot by default to an autoinstall
# mode and download our install configuration.
# Configurable settings:
# location of the original Ubuntu installation ISO image
DOWNLOAD_URL=https://releases.ubuntu.com/jammy/ubuntu-22.04.5-live-server-amd64.iso
# location where the clients should download the installation configuration
# (exported for the benefit of mangle-image below)
# "_gateway" can be used for testing
export AUTOINSTALL_URL=https://digabi.github.io/ytl-linux/autoinstall-config-22/
# Label on the modified ISO image
ISO_LABEL="YTL Ubuntu Install CD"
# Filename of the resulting image
RESULT_IMAGE=ytl-install-22.iso
#########################################
# Step 0: Check some prerequisites
#########################################
for prog in wget bsdtar xorriso; do
if ! which $prog >/dev/null 2>&1; then
echo "Missing $prog, cannot continue" 1>&2
exit 1
fi
done
#########################################
# Step 1: Download the original ISO image
#########################################
IMAGE=ubuntu.iso
if [ ! -e $IMAGE ]; then
wget -O $IMAGE $DOWNLOAD_URL
fi
#########################################
# Step 2: Extract the image to a work directory
#########################################
WORKDIR=$(mktemp -d)
bsdtar xf $IMAGE -C "$WORKDIR"
chmod -R u+w "$WORKDIR"
#########################################
# Step 3: Call an external script to modify the work directory
#########################################
./mangle-image "$WORKDIR"
#########################################
# Step 4: Repack the image
#########################################
# based on
# https://help.ubuntu.com/community/InstallCDCustomization#Building_the_ISO_image
MBR_FILE=$(mktemp).mbr
EFI_FILE=$(mktemp).efi
dd if="$IMAGE" bs=1 count=446 of="$MBR_FILE"
# Extract EFI partition image
skip=$(/sbin/fdisk -l "$IMAGE" | fgrep '.iso2 ' | awk '{print $2}')
size=$(/sbin/fdisk -l "$IMAGE" | fgrep '.iso2 ' | awk '{print $4}')
dd if="$IMAGE" bs=512 skip="$skip" count="$size" of="$EFI_FILE"
xorriso -as mkisofs -r -V "$ISO_LABEL" \
-iso-level 3 \
-partition_offset 16 \
--grub2-mbr "$MBR_FILE" \
--mbr-force-bootable \
-append_partition 2 0xEF "$EFI_FILE" \
-appended_part_as_gpt \
-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:all::' \
-no-emul-boot \
-o "$RESULT_IMAGE" \
"$WORKDIR"
#########################################
# Step 5: Clean up
#########################################
rm -rf "$WORKDIR" "$MBR_FILE" "$EFI_FILE"