Eric Radman : a Journal

Automated Ubuntu Installation

Although Ubuntu is a derivative of Debian, it doesn't follow the same convetions for an automated install.

x86_64 hardware and hypervisors usually don't provide a means of picking a one-time boot device. To force a reinstall wipe the first part of the disk.

# reinstall
# use with caution!
dd if=/dev/zero of=/dev/sda bs=1M count=100
reboot

BIOS PXE Boot

The initial ramdisk and kernel can be taken from the install ISO

mkdir -p /tftpboot/ubuntu22
cp casper/{vmlinuz,initrd} /tftpboot/ubuntu22/
# /tftpboot/pxelinux.cfg/01-00-0c-29-f9-6d-4e
DEFAULT menu.c32
PROMPT 0
TIMEOUT 10
MENU TITLE PXE Menu
LABEL Install Ubuntu 22 Server
  KERNEL ubuntu22/vmlinuz
  APPEND initrd=ubuntu22/initrd ip=dhcp cloud-config-url=/dev/null url=http://192.168.2.20/ubuntu-22.04.1-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.2.20/ubuntu-srv/

Setting cloud-config-url is not required, but avoids a redundant fetch of the install image.

iPXE Loader

If the machine is booting with UEFI and iPXE the configuration is similar

#!ipxe
set base-url http://192.168.2.20/pub
kernel /ubuntu20/vmlinuz initrd=initrd ip=dhcp cloud-config-url=/dev/null url=http://192.168.2.20/ubuntu-20.04.5-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.2.20/ubuntu-srv/
initrd /ubuntu20/initrd
boot

Server Config

Create two empty files

touch /var/www/htdocs/meta-data
touch /var/www/htdocs/vendor-data

As well as a file called user-data

#cloud-config
autoinstall:
  identity:
    hostname: ubuntu-srv
    password: $crypted_pass
    username: ubuntu
  keyboard:
    layout: en
  locale: en_US.UTF-8
  proxy: http://192.168.2.1:3128
  ssh:
    allow-pw: false
    authorized-keys: ['ssh-ed25519 ...']
    install-server: true
  packages:
    - tmux
  user-data:
    timezone: America/New_York
  late-commands:
    - 'echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/ubuntu-nopw'
    - chmod 440 /target/etc/sudoers.d/ubuntu-nopw
  version: 1

Minimal Workstation

Since we're booting from the server ISO it is very useful to set up a forward HTTP proxy for caching packages.

#cloud-config
autoinstall:
  identity:
    hostname: ubuntu-wks
    password: $crypted_pass
    username: ubuntu
  keyboard:
    layout: en
  locale: en_US.UTF-8
  proxy: http://192.168.0.1:3128
  ssh:
    allow-pw: false
    authorized-keys: ['ssh-ed25519 ...']
    install-server: true
  packages:
    - gnome-session
    - gnome-terminal
    - gnome-shell-extensions
    - adwaita-icon-theme-full
    - nautilus
  late-commands:
    - 'echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/ubuntu-nopw'
    - chmod 440 /target/etc/sudoers.d/ubuntu-nopw
  version: 1

Some other useful utilities and post-install customizations:

apt -y install gnome-tweaks gnome-shell-extension-desktop-icons-ng
gsettings set org.gnome.desktop.background picture-uri ''
gsettings set org.gnome.desktop.background primary-color 'rgb(66, 81, 100)'
gsettings set org.gnome.desktop.background show-desktop-icons true
gnome-extensions-app

Oddly the install on Ubuntu 20 may only use half of the free space. Expand the root volume using

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

References