-
Notifications
You must be signed in to change notification settings - Fork 1
Process
This is a basic breakdown of the process involed:
- Install required packages
- Make work directories
- Get ISO
- Mount base ISO as loopback device so contents can be copied
- Copy contents of ISO to a RW location so we can work with them
- Mount squashfs and copy giles into it
- Create a chroot script and execute it
- Uncompress ISO into directory and create autoinstall shell
- Create ISO autoinstall files
- Create ISO grub file menu that calls autoinstall file(s)
- Create ISO file
sudo apt install -y p7zip-full wget xorriso
mkdir -p ./isomount ./isonew/squashfs ./isonew/cd ./isonew/custom
wget https://releases.ubuntu.com/22.04.1/ubuntu-22.04.1-live-server-amd64.iso -O ./ubuntu-iso/ubuntu-22.04.1-live-server-amd64.iso
sudo mount -o loop ./ubuntu-22.04.1-live-server-amd64.iso ./isomount
rsync --exclude=/casper/ubuntu-server-minimal.squashfs -av ./isomount/ ./isonew/cd
rsync -av ./isomount/ ./isonew/cd
sudo mount -t squashfs -o loop ./isomount/casper/ubuntu-server-minimal.squashfs ./isonew/squashfs/
sudo rsync -av ./isonew/squashfs/ ./isonew/custom
sudo cp /etc/resolv.conf /etc/hosts ./isonew/custom/etc/
sudo cp /etc/apt/sources.list ./isonew/custom/etc/apt/
Create chroot script:
cat <<EOF > ./ubuntu-iso/isonew/custom/tmp/modify_chroot.sh
#!/usr/bin/bash
mount -t proc none /proc/
mount -t sysfs none /sys/
mount -t devpts none /dev/pts
export HOME=/root
sudo apt update
sudo apt install -y --download-only zfsutils-linux grub-efi zfs-initramfs net-tools curl wget
sudo apt install -y zfsutils-linux grub-efi zfs-initramfs net-tools curl wget
umount /proc/
umount /sys/
umount /dev/pts/
exit
EOF
This script install the required ZFS and other packages into the squashfs filewsystem. It also also downloads a copy of the packages so we can copy this into ISO we create, so they can be installed as part of the installation method without requiring network.
Execute chroot script:
sudo chmod +x ./ubuntu-iso/isonew/custom/tmp/modify_chroot.sh
sudo chroot ./ubuntu-iso/isonew/custom /tmp/modify_chroot.sh
Uncompress ISO and move BOOT files to where they will be used by ISO creation process:
7z -y x ./ubuntu-iso/ubuntu-22.04.1-live-server-amd64.iso -o./ubuntu-iso/source-files
mv ./source-files/\[BOOT\] ./BOOT
Creat directories for autoinstall configs:
mkdir -p ./source-files/autoinstall/configs/sda
mkdir -p ./source-files/autoinstall/packages
touch ./source-files/autoinstall/configs/sda/meta-data
Copy packages we downloaded as part of chroot process so they can be included on the ISO:
cp ./isonew/custom/var/cache/apt/archives/*.deb source-files/autoinstall/packages/
This example uses /dev/sda as a ZFS root device. The documentation for this process is hard to find, so the example is a simple unmirrored device, as this works. A mirror could be done as a post script or after install.
An example of getting a password crypt:
export PASSWORD_CRYPT=$(echo P455w0rD |mkpasswd --method=SHA-512 --stdin)
Create a user-data file:
cat <<EOF > ./source-files/autoinstall/configs/sda/user-data
#cloud-config
autoinstall:
apt:
preferences:
- package: "*"
pin: "release a=jammy-security"
pin-priority: 200
disable_components: []
geoip: true
preserve_sources_list: false
primary:
- arches:
- amd64
- i386
uri: http://archive.ubuntu.com/ubuntu
- arches:
- default
uri: http://ports.ubuntu.com/ubuntu-ports
package_update: false
package_upgrade: false
drivers:
install: false
user-data:
timezone: Australia/Melbourne
identity:
hostname: ubuntu
password: "$PASSWORD_CRYPT"
realname: Ubuntu
username: ubuntu
kernel:
package: linux-generic
keyboard:
layout: us
locale: en_US.UTF-8
network:
ethernets:
ens33:
critical: true
dhcp-identifier: mac
dhcp4: true
version: 2
ssh:
allow-pw: true
authorized-keys: []
install-server: true
storage:
config:
- ptable: gpt
path: /dev/sda
wipe: superblock-recursive
preserve: false
name: ''
grub_device: true
type: disk
id: disk1
- device: disk1
size: 1127219200
wipe: superblock-recursive
flag: boot
number: 1
preserve: false
grub_device: true
type: partition
ptable: gpt
id: disk1p1
- fstype: fat32
volume: disk1p1
preserve: false
type: format
id: disk1p1fs1
- path: /boot/efi
device: disk1p1fs1
type: mount
id: mount-2
- device: disk1
size: -1
wipe: superblock-recursive
flag: root
number: 2
preserve: false
grub_device: false
type: partition
id: disk1p2
- id: disk1p2fs1
type: format
fstype: zfsroot
volume: disk1p2
preserve: false
- id: disk1p2f1_rootpool
mountpoint: /
pool: rpool
type: zpool
device: disk1p2fs1
preserve: false
vdevs:
- disk1p2fs1
- id: disk1_rootpool_container
pool: disk1p2f1_rootpool
preserve: false
properties:
canmount: "off"
mountpoint: "none"
type: zfs
volume: /ROOT
- id: disk1_rootpool_rootfs
pool: disk1p2f1_rootpool
preserve: false
properties:
canmount: noauto
mountpoint: /
type: zfs
volume: /ROOT/zfsroot
- path: /
device: disk1p2fs1
type: mount
id: mount-disk1p2
swap:
swap: 0
early-commands:
- "sudo dpkg --auto-deconfigure --force-depends -i /cdrom/autoinstall/packages/*.deb"
version: 1
EOF
Greate grub file:
cat <<EOF > ./source-files/boot/grub/grub.cfg
set timeout=10
loadfont unicode
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry "Autoinstall Ubuntu Server - Physical" {
set gfxpayload=keep
linux /casper/vmlinuz quiet autoinstall ds=nocloud\;s=/cdrom/autoinstall/configs/sda/ ---
initrd /casper/initrd
}
menuentry "Try or Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz quiet ---
initrd /casper/initrd
}
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
EOF
Get required partition information from existing ISO:
export APPEND_PARTITION=$(xorriso -indev ubuntu-22.04.1-live-server-amd64.iso -report_el_torito as_mkisofs |grep append_partition |tail -1 |awk '{print $3}' 2>&1)
export ISO_MBR_PART_TYPE=$(xorriso -indev ubuntu-22.04.1-live-server-amd64.iso -report_el_torito as_mkisofs |grep iso_mbr_part_type |tail -1 |awk '{print $2}' 2>&1)
Create ISO:
xorriso -as mkisofs -r -V 'Ubuntu-Server 22.04.1 LTS arm64' -o ../ubuntu-22.04-autoinstall-arm64.iso --grub2-mbr \
../BOOT/Boot-NoEmul.img -partition_offset 16 --mbr-force-bootable -append_partition 2 $APPEND_PARTITION ../BOOT/Boot-NoEmul.img \
-appended_part_as_gpt -iso_mbr_part_type $ISO_MBR_PART_TYPE -c '/boot/boot.cat' -e '--interval:appended_partition_2:::' -no-emul-boot