2022-10-18 17:20:26 +00:00
The intent of this page is to provide simple instructions to perform an autoinstall in a VM on your machine.
2023-10-18 20:17:28 +00:00
This page assumes that you are willing to install the latest Ubuntu release available (23.10 at the time of writing). For other releases, you would need to substitute the name of the ISO image but the instructions should otherwise remain the same.
2022-10-24 16:51:40 +00:00
2023-10-18 20:17:28 +00:00
This page also assumes you are on the amd64 architecture. There is a [version for s390x ](/t/automated-server-install-schema/16616 ) too.
2022-10-18 17:20:26 +00:00
## Providing the autoinstall data over the network
2023-10-18 20:17:28 +00:00
This method is the one that generalises most easily to doing an entirely network-based install, where a machine netboots and is then automatically installed.
2022-10-18 17:20:26 +00:00
### Download the ISO
2023-10-18 20:17:28 +00:00
Go to the [23.10 ISO download page ](https://releases.ubuntu.com/23.10/ ) and download the latest Ubuntu 23.10 live-server ISO.
2022-10-18 17:20:26 +00:00
### Mount the ISO
2023-10-18 20:17:28 +00:00
```bash
sudo mount -r ~/Downloads/ubuntu-23.10-live-server-amd64.iso /mnt
```
2022-10-18 17:20:26 +00:00
### Write your autoinstall config
This means creating cloud-init config as follows:
2023-10-18 20:17:28 +00:00
```bash
mkdir -p ~/www
2022-10-18 17:20:26 +00:00
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
2023-10-18 20:17:28 +00:00
touch meta-data
```
2022-10-18 17:20:26 +00:00
The crypted password is just "ubuntu".
2023-10-18 20:17:28 +00:00
### Serve the cloud-init config over HTTP
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
Leave this running in a new terminal window:
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
```bash
cd ~/www
python3 -m http.server 3003
```
2022-10-18 17:20:26 +00:00
### Create a target disk
2023-10-18 20:17:28 +00:00
```bash
truncate -s 10G image.img
```
2022-10-18 17:20:26 +00:00
### Run the install!
2023-10-18 20:17:28 +00:00
```bash
kvm -no-reboot -m 2048 \
2022-10-18 17:20:26 +00:00
-drive file=image.img,format=raw,cache=none,if=virtio \
2022-10-24 16:51:40 +00:00
-cdrom ~/Downloads/ubuntu-22.10-live-server-amd64.iso \
2022-10-18 17:20:26 +00:00
-kernel /mnt/casper/vmlinuz \
-initrd /mnt/casper/initrd \
2023-10-18 20:17:28 +00:00
-append 'autoinstall ds=nocloud-net;s=http://_gateway:3003/'
```
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
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.
2022-10-18 17:20:26 +00:00
### Boot the installed system
2023-10-18 20:17:28 +00:00
```bash
kvm -no-reboot -m 2048 \
-drive file=image.img,format=raw,cache=none,if=virtio
```
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
This will boot into the freshly installed system and you should be able to log in as `ubuntu` /`ubuntu`.
2022-10-18 17:20:26 +00:00
## 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
2023-10-18 20:17:28 +00:00
Go to the [23.10 ISO download page ](https://releases.ubuntu.com/23.10/ ) and download the latest Ubuntu 23.10 live-server ISO.
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
### Create your `user-data` and `meta-data` files
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
```bash
mkdir -p ~/cidata
2022-10-18 17:20:26 +00:00
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
2023-10-18 20:17:28 +00:00
touch meta-data
```
2022-10-18 17:20:26 +00:00
The crypted password is just "ubuntu".
### Create an ISO to use as a cloud-init data source
2023-10-18 20:17:28 +00:00
```bash
sudo apt install cloud-image-utils
cloud-localds ~/seed.iso user-data meta-data
```
2022-10-18 17:20:26 +00:00
### Create a target disk
2023-10-18 20:17:28 +00:00
```bash
truncate -s 10G image.img
```
2022-10-18 17:20:26 +00:00
### Run the install!
2023-10-18 20:17:28 +00:00
```bash
kvm -no-reboot -m 2048 \
2022-10-18 17:20:26 +00:00
-drive file=image.img,format=raw,cache=none,if=virtio \
-drive file=~/seed.iso,format=raw,cache=none,if=virtio \
2023-10-18 20:17:28 +00:00
-cdrom ~/Downloads/ubuntu-22.10-live-server-amd64.iso
```
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
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.
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
The installer reboots at the end but the `-no-reboot` flag to `kvm` means that `kvm` will exit when this happens.
2022-10-18 17:20:26 +00:00
The whole process should take about 5 minutes.
### Boot the installed system
2023-10-18 20:17:28 +00:00
```bash
kvm -no-reboot -m 2048 \
-drive file=image.img,format=raw,cache=none,if=virtio
```
2022-10-18 17:20:26 +00:00
2023-10-18 20:17:28 +00:00
This will boot into the freshly installed system and you should be able to log in as `ubuntu` /`ubuntu`.