Skip to content

Ubuntu 22.04/20.04 Automated Provisioning: Cloud-init & Subiquity ​

Unlike traditional CentOS Kickstart, modern Ubuntu Server (20.04+) utilizes the Autoinstall mechanism based on Cloud-init. This document details how to set up an automated provisioning server supporting both UEFI and Legacy boot modes.

1. Environment Preparation (Server Side) ​

Assume PXE Server IP is 192.168.243.128.

1.1 Install Basic Services ​

bash
apt update && apt install -y tftpd-hpa apache2 isc-dhcp-server syslinux pxelinux

1.2 Configure HTTP & TFTP ​

We use Apache2 to host the ISO image and Cloud-init configuration (user-data).

Configure Apache2 to serve TFTP directory:

bash
cat > /etc/apache2/conf-available/tftp.conf <<EOF
<Directory /var/lib/tftpboot>
        Options +FollowSymLinks +Indexes
        Require all granted
</Directory>
Alias /tftp /var/lib/tftpboot
EOF

# Enable and Reload
a2enconf tftp
systemctl reload apache2

Configure TFTP Service: Edit /etc/default/tftpd-hpa:

bash
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

Restart: systemctl restart tftpd-hpa

1.3 Prepare Kernel & Image ​

Mount the Ubuntu Server ISO and extract boot files.

bash
# 1. Mount ISO
mount -o loop ubuntu-22.04.4-live-server-amd64.iso /mnt

# 2. Copy Kernel (vmlinuz) and Initrd
cp /mnt/casper/vmlinuz /var/lib/tftpboot/
cp /mnt/casper/initrd /var/lib/tftpboot/

# 3. Copy full ISO to HTTP directory for client download
cp ubuntu-22.04.4-live-server-amd64.iso /var/lib/tftpboot/

1.4 Configure DHCP ​

Edit /etc/dhcp/dhcpd.conf:

nginx
subnet 192.168.243.0 netmask 255.255.255.0 {
  range 192.168.243.11 192.168.243.100;
  option routers 192.168.243.1;
  next-server 192.168.243.128; # PXE Server IP
  
  filename "pxelinux.0"; 
  # Note: For dual UEFI/Legacy support, use 'class' matching in DHCP config.
}

2. Prepare Autoinstall Config (User-Data) ​

This is the core of automation. You can reuse the /var/log/installer/autoinstall-user-data generated after a manual installation.

bash
cp /var/log/installer/autoinstall-user-data /var/lib/tftpboot/user-data

Key Modification: Set root partition size to -1 to use all available space.

yaml
# user-data snippet
storage:
  config:
    - type: partition
      id: partition-2
      size: -1  # Expand to fill disk

3. UEFI Boot Configuration ​

UEFI requires grubnetx64.efi.signed.

3.1 Get Bootloader ​

bash
wget http://archive.ubuntu.com/ubuntu/dists/focal/main/uefi/grub2-amd64/current/grubnetx64.efi.signed -O /var/lib/tftpboot/pxelinux.0

3.2 Configure GRUB Menu ​

Create /var/lib/tftpboot/grub/grub.cfg:

bash
default=autoinstall
timeout=30
menuentry "Ubuntu 22.04 Autoinstall (UEFI)" {
    set gfxpayload=keep
    # ds=nocloud-net;s=... specifies the directory containing user-data
    linux /vmlinuz ip=dhcp url=http://192.168.243.128/tftp/ubuntu-22.04.4-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.243.128/tftp/
    initrd /initrd
}

4. Legacy BIOS Boot Configuration ​

4.1 Prepare Syslinux Components ​

bash
# Copy Syslinux modules
cp /usr/lib/syslinux/modules/bios/{libcom32.c32,ldlinux.c32,libutil.c32,menu.c32,vesamenu.c32} /var/lib/tftpboot/
cp /usr/lib/PXELINUX/lpxelinux.0 /var/lib/tftpboot/

4.2 Configure Boot Menu ​

Create /var/lib/tftpboot/pxelinux.cfg/default:

bash
default vesamenu.c32
timeout 60
label autoinstall
  menu label ^Autoinstall Ubuntu 22.04 (Legacy)
  kernel /vmlinuz
  append initrd=/initrd ip=dhcp url=http://192.168.243.128/tftp/ubuntu-22.04.4-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.243.128/tftp/

5. Offline Package Acquisition ​

If the server has no internet access, download packages on a connected VM.

5.1 Download Only ​

bash
# Download package and dependencies
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances tftpd-hpa | grep "^\w")

5.2 Install Offline ​

Transfer .deb files to the offline server:

bash
dpkg -i *.deb

Summary ​

Automating Ubuntu installation relies on Cloud-init, which is more flexible but network-dependent (requires HTTP download of the full ISO) compared to Kickstart. Ensure your user-data YAML syntax is correct to avoid installation failures.

AI-HPC Organization · Contact: openaihpc@gmail.com