Automated Server Install Quickstart

Autoinstall Quick Start

The intent of this page is to provide simple instructions to perform an autoinstall in a VM on your machine.

This page assumes you are on the amd64 architecture. There is a version for s390x too.

Providing the autoinstall data over the network

This method is the one that generalizes most easily to doing an entirely network-based install, where a machine netboots and then is automatically installed.

Download the ISO

Go to the 20.04 ISO download page and download the latest Ubuntu 20.04 live-server ISO.

Mount the ISO

sudo mount -r ~/Downloads/ubuntu-20.04-live-server-amd64.iso /mnt

Write your autoinstall config

This means creating cloud-init config as follows:

mkdir -p ~/www
cd ~/www
cat > user-data << 'EOF'
#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ubuntu-server
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
    username: ubuntu
EOF
touch meta-data

The crypted password is just “ubuntu”.

Serve the cloud-init config over http

Leave this running in one terminal window:

cd ~/www
python3 -m http.server 3003

Create a target disk

truncate -s 10G image.img

Run the install!

kvm -no-reboot -m 1024 \
    -drive file=image.img,format=raw,cache=none,if=virtio \
    -cdrom ~/Downloads/ubuntu-20.04-live-server-amd64.iso \
    -kernel /mnt/casper/vmlinuz \
    -initrd /mnt/casper/initrd \
    -append 'autoinstall ds=nocloud-net;s=http://_gateway:3003/'

This will boot, download the config from the server set up in the previous step and run the install. The installer reboots at the end but the -no-reboot flag to kvm means that kvm will exit when this happens. It should take about 5 minutes.

Boot the installed system

kvm -no-reboot -m 1024 \
    -drive file=image.img,format=raw,cache=none,if=virtio

This will boot into the freshly installed system and you should be able to log in as ubuntu/ubuntu.

Using another volume to provide the autoinstall config

This is the method to use when you want to create media that you can just plug into a system to have it be installed.

Download the live-server ISO

Go to the 20.04 ISO download page and download the latest Ubuntu 20.04 live-server ISO.

Create your user-data & meta-data files

mkdir -p ~/cidata
cd ~/cidata
cat > user-data << 'EOF'
#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ubuntu-server
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
    username: ubuntu
EOF
touch meta-data

The crypted password is just “ubuntu”.

Create an ISO to use as a cloud-init data source

sudo apt install cloud-image-utils
cloud-localds ~/seed.iso user-data meta-data

Create a target disk

truncate -s 10G image.img

Run the install!

kvm -no-reboot -m 1024 \
    -drive file=image.img,format=raw,cache=none,if=virtio \
    -drive file=~/seed.iso,format=raw,cache=none,if=virtio \
    -cdrom ~/Downloads/ubuntu-20.04-live-server-amd64.iso

This will boot and run the install. Unless you interrupt boot to add ‘autoinstall’ to the kernel command line, the installer will prompt for confirmation before touching the disk.

The installer reboots at the end but the -no-reboot flag to kvm means that kvm will exit when this happens.

The whole process should take about 5 minutes.

Boot the installed system

kvm -no-reboot -m 1024 \
    -drive file=image.img,format=raw,cache=none,if=virtio

This will boot into the freshly installed system and you should be able to log in as ubuntu/ubuntu.

2 Likes

I am not sure if I understand that document properly. The second headline reads:

Providing the autoinstall data over the network

This method is the one that generalizes most easily to doing an entirely network based install, where a machine netboots and then is automatically installed.

What you are doing then is creating a virtual machine and providing an ISO as CD-ROM. This is NOT netbooting. This is booting from CD-ROM. Just retrieving the config file via HTTP is not what I would call “entirely network based”.

Did I get something wrong?

What I mean by “most easily generalizes” is that you can turn this into an entirely network based method. I agree it’s not netbooting, and it’s not claiming that it is (there is another document for that)

This command doesn’t quite work for me. I get the following error:

qemu: could not open kernel file '/mnt/casper/vmlinuz': No such file or directory

looks like you forgot the “mount the iso” step above …

1 Like

Regarding those shortened aliases s= and ds=, can we add some explanations to the effect of…

1 Like

This is a copy-paste error in the “Using another volume” section, since there is no network involved.

I’m trying the second method. I created seed.iso with cloud-localds containing a user-data and an empty meta-data. I start the install like this:

virt-install --name ubuntu --connect qemu:///system --virt-type kvm --memory 4096 --cpu host --network bridge=br0 --os-variant ubuntu19.04 --boot uefi --serial pty --console pty,target_type=virtio --disk device=cdrom,path=/tmp/seed.iso --cdrom /var/lib/libvirt/images/ubuntu-20.04.1-live-server-amd64.iso --disk size=10,path=/data/vms/ubuntu.sda

It boots the installer, but it doesn’t start autoinstalling. If I go to a shell in the installer, I can see the seed.iso cdrom device with lsblk and mount it, and see that user-data and meta-data are there. So, I’ve no idea why it’s not working as advertised.

Quite right, fixed.

Hmm. Can you look at /var/log/cloud-init* in the live session? cloud-init finds the seed.iso by running “blkid -tLABEL=cidata” so it would also be good to poke around to see what labels have been found (ls -l /dev/disk/by-label, that sort of thing).

Turns out the user-data file must start with #cloud-config, I had a different comment for the first line. Now I see that stated in the cloud-init docs. Might be good to point this out in the Ubuntu docs as well. Thanks.

The ISO download url 404’s now, needs updating to wget https://releases.ubuntu.com/20.04.1/ubuntu-20.04.1-live-server-amd64.iso

Apologies if this detail is in the docs and I missed it. I’m trying to do a network based install and pull in an autoinstall file; iPXE command is as follows:

initrd http://archive.ubuntu.com/ubuntu/dists/focal-updates/main/installer-amd64/current/legacy-images/netboot/ubuntu-installer/amd64/initrd.gz

kernel http://archive.ubuntu.com/ubuntu/dists/focal-updates/main/installer-amd64/current/legacy-images/netboot/ubuntu-installer/amd64/linux initrd=initrd.gz autoinstall net.ifnames=0 biosdevname=0 ip=dhcp ipv6.disable=1 ds=nocloud-net;s=http://192.168.1.187/

When the install happens, I don’t see any attempts for the installer to access 192.168.1.187 where my cloud-init file is hosted. How do I figure out what I’m doing wrong?

Thanks!

I found the issue. I had made the (obviously bad) assumption that the kernel/initrd bits for the ISO installer would be the same as the network installer. I switched to the bits from the ISO and now it all makes sense. I thought I could just ignore the specific instructions about mounting the iso to obtain the kernel/initrd and was wrong about that. :stuck_out_tongue:

What about embedding the cloud-init files directly into a modified ubuntu server iso, would that be possible? I have made some attempts but can not get that to work.
I would like to just hand out an ISO to my users so they can install a vm or physical machine and get all the configurations correct from start and have the machine connect to my puppet/foreman automatically.
We used to be able to do such a thing using the preseed method.

3 Likes

The live server iso link is currently out of date. It should be:

wget http://releases.ubuntu.com/20.04/ubuntu-20.04.1-live-server-amd64.iso

Hey! Thanks for pointing this out. I’ve updated the section about downloading the ISO to point to the page where folks can find it. Because every point release will change the URL I got rid of the hard-coded filename. Thanks again!

Thanks for the reply. Is there any additional documentation on unpacking and repacking the live-server iso with the cloud-init config and kernel options such that it can be copied to a usb key for nocloud situations? While I understand that many people use these configs on hypervisors and to provision bare metal servers in a netboot situation, my particular usage always starts with offline installs using a usb key (since that’s the worst case scenario for bootstrapping infrastructure).

Again, thanks for the reply!

2 Likes

@baetheus, you have the ISO repacked already and want to know how to get it to a USB drive? Or more detailed instructions on putting the config, setting the kernel options, and then repacking the drive?

I’m interested in unpacking and repacking the iso. After that I have no problem dd’ing it to a drive or mounting it with a hypervisor. However, I think those processes would also be useful, especially on a couple of operating systems (namely Windows, FreeBSD, Solaris and macOS in addition to Ubuntu like Joyent does).