Skip to content

Commit 16239cc

Browse files
committed
Support for 22.04
* Changed the default ubuntu release to 22.04 (jammy) * Added option --focal for 20.04 (focal) * Implemented extracting boot partitions from existing cd image * Changed xorriso call for image creation to conform to 22.04 layout Signed-off-by: Nis Wechselberg <[email protected]>
1 parent 2286503 commit 16239cc

File tree

1 file changed

+81
-17
lines changed

1 file changed

+81
-17
lines changed

ubuntu-autoinstall-generator.sh

100644100755
Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ function die() {
2727

2828
usage() {
2929
cat <<EOF
30-
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-a] [-e] [-u user-data-file] [-m meta-data-file] [-k] [-c] [-r] [-s source-iso-file] [-d destination-iso-file]
30+
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-a] [-e] [-u user-data-file] [-m meta-data-file] [-k] [--focal] [-c] [-r] [-s source-iso-file] [-d destination-iso-file]
3131
32-
💁 This script will create fully-automated Ubuntu 20.04 Focal Fossa installation media.
32+
💁 This script will create fully-automated Ubuntu Server installation media.
33+
By default, Ubuntu 22.04 images are created, but Ubuntu 20.04 is available as well.
3334
3435
Available options:
3536
@@ -49,9 +50,10 @@ Available options:
4950
downloaded and saved in ${script_dir}. The Ubuntu signing key will be downloaded and
5051
saved in a new keyring in ${script_dir}
5152
-c, --no-md5 Disable MD5 checksum on boot
53+
--focal Create installation media for Ubuntu 20.04 Focal Fossa
5254
-r, --use-release-iso Use the current release ISO instead of the daily ISO. The file will be used if it already
5355
exists.
54-
-s, --source Source ISO file. By default the latest daily ISO for Ubuntu 20.04 will be downloaded
56+
-s, --source Source ISO file. By default the latest daily ISO will be downloaded
5557
and saved as ${script_dir}/ubuntu-original-$today.iso
5658
That file will be used by default if it already exists.
5759
-d, --destination Destination ISO file. By default ${script_dir}/ubuntu-autoinstall-$today.iso will be
@@ -64,12 +66,13 @@ function parse_params() {
6466
# default values of variables set from params
6567
user_data_file=''
6668
meta_data_file=''
67-
download_url="https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current"
68-
download_iso="focal-live-server-amd64.iso"
69-
original_iso="ubuntu-original-$today.iso"
69+
focal=0
70+
download_url="https://cdimage.ubuntu.com/ubuntu-server/jammy/daily-live/current"
71+
download_iso="jammy-live-server-amd64.iso"
72+
original_iso="ubuntu-jammy-original-$today.iso"
7073
source_iso="${script_dir}/${original_iso}"
71-
destination_iso="${script_dir}/ubuntu-autoinstall-$today.iso"
72-
sha_suffix="${today}"
74+
destination_iso="${script_dir}/ubuntu-jammy-autoinstall-$today.iso"
75+
sha_suffix="-jammy-${today}"
7376
gpg_verify=1
7477
all_in_one=0
7578
use_hwe_kernel=0
@@ -80,6 +83,7 @@ function parse_params() {
8083
case "${1-}" in
8184
-h | --help) usage ;;
8285
-v | --verbose) set -x ;;
86+
--focal) focal=1 ;;
8387
-a | --all-in-one) all_in_one=1 ;;
8488
-e | --use-hwe-kernel) use_hwe_kernel=1 ;;
8589
-c | --no-md5) md5_checksum=0 ;;
@@ -120,10 +124,25 @@ function parse_params() {
120124
[[ ! -f "${source_iso}" ]] && die "💥 Source ISO file could not be found."
121125
fi
122126

127+
if [ ${focal} -eq 1 ]; then
128+
download_url="https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current"
129+
download_iso="focal-live-server-amd64.iso"
130+
original_iso="ubuntu-focal-original-$today.iso"
131+
source_iso="${script_dir}/${original_iso}"
132+
destination_iso="${script_dir}/ubuntu-focal-autoinstall-$today.iso"
133+
sha_suffix="-focal-${today}"
134+
135+
fi
136+
123137
if [ "${use_release_iso}" -eq 1 ]; then
124-
download_url="https://releases.ubuntu.com/focal"
125138
log "🔎 Checking for current release..."
126-
download_iso=$(curl -sSL "${download_url}" | grep -oP 'ubuntu-20\.04\.\d*-live-server-amd64\.iso' | head -n 1)
139+
if [ ${focal} -eq 1 ]; then
140+
download_url="https://releases.ubuntu.com/focal"
141+
download_iso=$(curl -sSL "${download_url}" | grep -oP 'ubuntu-20\.04\.\d*-live-server-amd64\.iso' | head -n 1)
142+
else
143+
download_url="https://releases.ubuntu.com/jammy"
144+
download_iso=$(curl -sSL "${download_url}" | grep -oP 'ubuntu-22\.04(\.\d*)?-live-server-amd64\.iso' | head -n 1)
145+
fi
127146
original_iso="${download_iso}"
128147
source_iso="${script_dir}/${download_iso}"
129148
current_release=$(echo "${download_iso}" | cut -f2 -d-)
@@ -154,11 +173,15 @@ log "🔎 Checking for required utilities..."
154173
[[ ! -x "$(command -v sed)" ]] && die "💥 sed is not installed. On Ubuntu, install the 'sed' package."
155174
[[ ! -x "$(command -v curl)" ]] && die "💥 curl is not installed. On Ubuntu, install the 'curl' package."
156175
[[ ! -x "$(command -v gpg)" ]] && die "💥 gpg is not installed. On Ubuntu, install the 'gpg' package."
157-
[[ ! -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]] && die "💥 isolinux is not installed. On Ubuntu, install the 'isolinux' package."
176+
if [ ${focal} -eq 1 ]; then
177+
[[ ! -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]] && die "💥 isolinux is not installed. On Ubuntu, install the 'isolinux' package."
178+
else
179+
[[ ! -x "$(command -v fdisk)" ]] && die "💥 fdisk is not installed. On Ubuntu, install the 'fdisk' package."
180+
fi
158181
log "👍 All required utilities are installed."
159182

160183
if [ ! -f "${source_iso}" ]; then
161-
log "🌎 Downloading ISO image for Ubuntu 20.04 Focal Fossa..."
184+
log "🌎 Downloading ISO image ..."
162185
curl -NsSL "${download_url}/${download_iso}" -o "${source_iso}"
163186
log "👍 Downloaded and saved to ${source_iso}"
164187
else
@@ -213,11 +236,22 @@ chmod -R u+w "$tmpdir"
213236
rm -rf "$tmpdir/"'[BOOT]'
214237
log "👍 Extracted to $tmpdir"
215238

239+
if [ ${focal} -eq 0 ]; then
240+
log "🔧 Extracting EFI images from image..."
241+
efi_start=$(fdisk -o Start,Type -l "${source_iso}" | grep -oP '\d+(?=\s+EFI-System)')
242+
efi_length=$(fdisk -o Sectors,Type -l "${source_iso}" | grep -oP '\d+(?=\s+EFI-System)')
243+
dd if=${source_iso} bs=512 skip=${efi_start} count=${efi_length} of=${source_iso}-efi.img
244+
dd if=${source_iso} bs=1 count=432 of=${source_iso}-hybrid.img
245+
log "👍 Extracted EFI images"
246+
fi
247+
216248
if [ ${use_hwe_kernel} -eq 1 ]; then
217249
if grep -q "hwe-vmlinuz" "$tmpdir/boot/grub/grub.cfg"; then
218250
log "☑️ Destination ISO will use HWE kernel."
219-
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/isolinux/txt.cfg"
220-
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/isolinux/txt.cfg"
251+
if [ ${focal} -eq 1 ]; then
252+
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/isolinux/txt.cfg"
253+
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/isolinux/txt.cfg"
254+
fi
221255
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/boot/grub/grub.cfg"
222256
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/boot/grub/grub.cfg"
223257
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/boot/grub/loopback.cfg"
@@ -228,7 +262,9 @@ if [ ${use_hwe_kernel} -eq 1 ]; then
228262
fi
229263

230264
log "🧩 Adding autoinstall parameter to kernel command line..."
231-
sed -i -e 's/---/ autoinstall ---/g' "$tmpdir/isolinux/txt.cfg"
265+
if [ ${focal} -eq 1 ]; then
266+
sed -i -e 's/---/ autoinstall ---/g' "$tmpdir/isolinux/txt.cfg"
267+
fi
232268
sed -i -e 's/---/ autoinstall ---/g' "$tmpdir/boot/grub/grub.cfg"
233269
sed -i -e 's/---/ autoinstall ---/g' "$tmpdir/boot/grub/loopback.cfg"
234270
log "👍 Added parameter to UEFI and BIOS kernel command lines."
@@ -242,7 +278,9 @@ if [ ${all_in_one} -eq 1 ]; then
242278
else
243279
touch "$tmpdir/nocloud/meta-data"
244280
fi
245-
sed -i -e 's,---, ds=nocloud;s=/cdrom/nocloud/ ---,g' "$tmpdir/isolinux/txt.cfg"
281+
if [ ${focal} -eq 1 ]; then
282+
sed -i -e 's,---, ds=nocloud;s=/cdrom/nocloud/ ---,g' "$tmpdir/isolinux/txt.cfg"
283+
fi
246284
sed -i -e 's,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' "$tmpdir/boot/grub/grub.cfg"
247285
sed -i -e 's,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' "$tmpdir/boot/grub/loopback.cfg"
248286
log "👍 Added data and configured kernel command line."
@@ -263,7 +301,33 @@ fi
263301

264302
log "📦 Repackaging extracted files into an ISO image..."
265303
cd "$tmpdir"
266-
xorriso -as mkisofs -r -V "ubuntu-autoinstall-$today" -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -boot-info-table -input-charset utf-8 -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -o "${destination_iso}" . &>/dev/null
304+
if [ ${focal} -eq 1 ]; then
305+
xorriso -as mkisofs -r \
306+
-V "ubuntu-auto-focal-$today" \
307+
-J \
308+
-b isolinux/isolinux.bin \
309+
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
310+
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -boot-info-table -input-charset utf-8 \
311+
-eltorito-alt-boot \
312+
-e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat \
313+
-o "${destination_iso}" \
314+
. #&>/dev/null
315+
else
316+
xorriso -as mkisofs -r \
317+
-V "ubuntu-auto-jammy-$today" \
318+
--grub2-mbr "${source_iso}-hybrid.img" \
319+
-partition_offset 16 --mbr-force-bootable \
320+
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b "${source_iso}-efi.img" \
321+
-appended_part_as_gpt \
322+
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
323+
-c '/boot.catalog' \
324+
-b '/boot/grub/i386-pc/eltorito.img' \
325+
-no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
326+
-eltorito-alt-boot -e '--interval:appended_partition_2:::' \
327+
-no-emul-boot \
328+
-o "${destination_iso}" \
329+
. #&>/dev/null
330+
fi
267331
cd "$OLDPWD"
268332
log "👍 Repackaged into ${destination_iso}"
269333

0 commit comments

Comments
 (0)