Skip to content

Instantly share code, notes, and snippets.

@feczkob
Last active April 11, 2024 08:54
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save feczkob/4ba876d7041dda4a104a3ca565ad6bc1 to your computer and use it in GitHub Desktop.
Save feczkob/4ba876d7041dda4a104a3ca565ad6bc1 to your computer and use it in GitHub Desktop.
How to create USB that automatically installs Ubuntu Server 20.04

Steps to create the bootable USB

  1. Create folder
mkdir autoinstall-ISO
cd autoinstall-ISO
  1. Download ubuntu-autoinstall-generator
wget https://raw.githubusercontent.com/covertsh/ubuntu-autoinstall-generator/main/ubuntu-autoinstall-generator.sh
  1. Add execute permission
chmod +x ubuntu-autoinstall-generator.sh
  1. Create folder for files that are going to be baked in to the ISO
mkdir server
  1. Create user-data and meta-data files in the server directory (user-data is included as an attachement)
touch server/meta-data

Generate your password hash (replace PASSWORD with your password)

openssl passwd -6 -stdin <<< PASSWORD

Replace the passord hash in user-data. More information about the cloud-init config can be found here.

  1. Create ISO image ubuntu-20.04-autoinstall.iso
sudo ./ubuntu-autoinstall-generator.sh -a -k -u server/user-data -m server/meta-data -d ubuntu-20.04-autoinstall.iso
  1. Plug in your USB device that is going to be turned into bootable USB, discover it with lsblk → assume that the device has the name of sdX
  2. Create a bootable USB using the dd command, don't forget to replace sdX with the actual name of your USB device
    ⚠️ This action erases all data from the USB device
sudo dd if=ubuntu-20.04-autoinstall.iso of=/dev/sdX bs=1024k status=progress && sync
  1. Plug in the USB into the machine where Ubuntu Server 20.04 will be installed
  2. Turn on the machine
    ⚠️ This action installs Ubuntu Server 20.04 on the target machine and can not be reverted

Test the ISO

  1. Download VirtualBox
  2. Create new machine with at least 5 GB disk space (Create a virtual hard disk now), the Hard disk file type may be HDD (Parallels Hard Disk)
  3. Right click on the newly created machine → Settings → Storage → Click on the empty → Set the source as the newly created ISO with the blue CD icon on the right
  4. Click on Start and wait

Access the machine

  1. Wait 5-10 mins after pressing the power button
  2. Use nmap to identify the machine: port 22 will be open if ssh-server was installed (ssh section of the user-data file)
  3. SSH into the device
ssh ubuntu@<IP of the device>

Useful links

#cloud-config
autoinstall:
version: 1
identity:
hostname: ubuntu-server
password: $6$iAB8EhpFltgyVCE/$CUGLVkOKAw7ILpJMr4gQxz9WpEPTSNjzjRFRT1oXsgdYAia5XwfQrDj/YeqgH3DX0Gx09MvXnsYtmEQTfU3Pk0
username: ubuntu
keyboard:
layout: en
toggle: null
variant: ''
locale: en_EN.UTF-8
ssh:
allow-pw: true
install-server: true
packages:
- build-essential
- network-manager
@blundell
Copy link

Not runnable from macOS due to the use of isolinux :-(
(managed to brew install everything else)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment