@@ -27,9 +27,10 @@ function die() {
27
27
28
28
usage () {
29
29
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]
31
31
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.
33
34
34
35
Available options:
35
36
@@ -49,9 +50,10 @@ Available options:
49
50
downloaded and saved in ${script_dir} . The Ubuntu signing key will be downloaded and
50
51
saved in a new keyring in ${script_dir}
51
52
-c, --no-md5 Disable MD5 checksum on boot
53
+ --focal Create installation media for Ubuntu 20.04 Focal Fossa
52
54
-r, --use-release-iso Use the current release ISO instead of the daily ISO. The file will be used if it already
53
55
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
55
57
and saved as ${script_dir} /ubuntu-original-$today .iso
56
58
That file will be used by default if it already exists.
57
59
-d, --destination Destination ISO file. By default ${script_dir} /ubuntu-autoinstall-$today .iso will be
@@ -64,12 +66,13 @@ function parse_params() {
64
66
# default values of variables set from params
65
67
user_data_file=' '
66
68
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"
70
73
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} "
73
76
gpg_verify=1
74
77
all_in_one=0
75
78
use_hwe_kernel=0
@@ -80,6 +83,7 @@ function parse_params() {
80
83
case " ${1-} " in
81
84
-h | --help) usage ;;
82
85
-v | --verbose) set -x ;;
86
+ --focal) focal=1 ;;
83
87
-a | --all-in-one) all_in_one=1 ;;
84
88
-e | --use-hwe-kernel) use_hwe_kernel=1 ;;
85
89
-c | --no-md5) md5_checksum=0 ;;
@@ -120,10 +124,25 @@ function parse_params() {
120
124
[[ ! -f " ${source_iso} " ]] && die " 💥 Source ISO file could not be found."
121
125
fi
122
126
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
+
123
137
if [ " ${use_release_iso} " -eq 1 ]; then
124
- download_url=" https://releases.ubuntu.com/focal"
125
138
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
127
146
original_iso=" ${download_iso} "
128
147
source_iso=" ${script_dir} /${download_iso} "
129
148
current_release=$( echo " ${download_iso} " | cut -f2 -d-)
@@ -154,11 +173,15 @@ log "🔎 Checking for required utilities..."
154
173
[[ ! -x " $( command -v sed) " ]] && die " 💥 sed is not installed. On Ubuntu, install the 'sed' package."
155
174
[[ ! -x " $( command -v curl) " ]] && die " 💥 curl is not installed. On Ubuntu, install the 'curl' package."
156
175
[[ ! -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
158
181
log " 👍 All required utilities are installed."
159
182
160
183
if [ ! -f " ${source_iso} " ]; then
161
- log " 🌎 Downloading ISO image for Ubuntu 20.04 Focal Fossa ..."
184
+ log " 🌎 Downloading ISO image ..."
162
185
curl -NsSL " ${download_url} /${download_iso} " -o " ${source_iso} "
163
186
log " 👍 Downloaded and saved to ${source_iso} "
164
187
else
@@ -213,11 +236,22 @@ chmod -R u+w "$tmpdir"
213
236
rm -rf " $tmpdir /" ' [BOOT]'
214
237
log " 👍 Extracted to $tmpdir "
215
238
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
+
216
248
if [ ${use_hwe_kernel} -eq 1 ]; then
217
249
if grep -q " hwe-vmlinuz" " $tmpdir /boot/grub/grub.cfg" ; then
218
250
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
221
255
sed -i -e ' s|/casper/vmlinuz|/casper/hwe-vmlinuz|g' " $tmpdir /boot/grub/grub.cfg"
222
256
sed -i -e ' s|/casper/initrd|/casper/hwe-initrd|g' " $tmpdir /boot/grub/grub.cfg"
223
257
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
228
262
fi
229
263
230
264
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
232
268
sed -i -e ' s/---/ autoinstall ---/g' " $tmpdir /boot/grub/grub.cfg"
233
269
sed -i -e ' s/---/ autoinstall ---/g' " $tmpdir /boot/grub/loopback.cfg"
234
270
log " 👍 Added parameter to UEFI and BIOS kernel command lines."
@@ -242,7 +278,9 @@ if [ ${all_in_one} -eq 1 ]; then
242
278
else
243
279
touch " $tmpdir /nocloud/meta-data"
244
280
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
246
284
sed -i -e ' s,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' " $tmpdir /boot/grub/grub.cfg"
247
285
sed -i -e ' s,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' " $tmpdir /boot/grub/loopback.cfg"
248
286
log " 👍 Added data and configured kernel command line."
263
301
264
302
log " 📦 Repackaging extracted files into an ISO image..."
265
303
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
267
331
cd " $OLDPWD "
268
332
log " 👍 Repackaged into ${destination_iso} "
269
333
0 commit comments