published: 11th of September 2023
In a previous post I showed you how to build a VyOS Qemu image. In this post, I will show you how to import the image as a template into Proxmox and deploy a VM from the template using cloud-init to provide initial configuration parameters.
The following software versions were used in this post.
This post assumes that you already have the qemu image on the Proxmox host in the /tmp/ directory.
We will import the qemu image into Proxmox and convert it to a template so we can build other VMs from it.
First we need to create a new VM.
qm create 9063 \
--name vyos-14-1-202309070021-cloud-init --numa 0 --ostype l26 \
--cpu cputype=host --cores 2 --sockets 1 \
--memory 2048 \
--net0 virtio,bridge=vmbr0,tag=100
Now, import the VyOS vyos-1.4-rolling-202309070021-cloud-init-10G-qemu.qcow2 disk into a local disk store. In this case I will import it to the local-lvm store.
qm importdisk 9063 /tmp/vyos-1.4-rolling-202309070021-cloud-init-10G-qemu.qcow2 local-lvm
Assign the imported disk to the VM.
qm set 9063 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9063-disk-0
Set the imported disk as the boot disk.
qm set 9063 --boot c --bootdisk scsi0
Add a serial console port, so we can connect to the VM via serial console if need be.
qm set 9063 --serial0 socket --vga serial0
Enable the qemu guest agent, so we get more visibility into the VM from the Proxmox console.
qm set 9063 --agent enabled=1
Create a cloud-init drive.
qm set 9063 --ide2 local-lvm:cloudinit
Convert the VM to a template. The template will be named vyos-14-1-202309070021-cloud-init which is the same as the original VM.
qm template 9063
Now that we have a VyOS VM template, let create a VM from it.
Clone the template to a new VM named vyos-test
qm clone 9063 888 \
--name vyos-test \
--full \
--storage local-lvm
Now we will use cloud-init apply a base configuration.
Create a file named user-data with the following contents. The user-data file allows you to apply vyos set commands.
#cloud-config
vyos_config_commands:
- set system host-name 'vyos-test'
- delete interfaces ethernet eth0 address 'dhcp'
- set system login user 'admin'
- set system login user admin authentication public-keys admin@win10 key 'AAAAB31234567890='
- set system login user admin authentication public-keys admin@win10 type 'ssh-rsa'
- set interfaces ethernet eth0 address '192.168.1.241/24'
- set interfaces ethernet eth0 description 'MGMT'
- set protocols static route 0.0.0.0/0 next-hop 192.168.1.1
Create a file named network-config with the following contents. The network-config file allows you to configure the eth0 interface outside of the vyos config.
version: 2
ethernets:
eth0:
dhcp4: false
dhcp6: false
Create an empty file named meta-data. The file is empty, but it is required.
touch meta-data
Use the mkisofs command to create an ISO named cidata which contains the 3 cloud-init files we created previously.
mkisofs -joliet -rock -volid "cidata" -output seed.iso \
meta-data user-data network-config
Move the ISO to the local storage.
mv /tmp/seed.iso /var/lib/vz/template/iso/
Attach the ISO to the VM.
qm set 888 --ide2 media=cdrom,file=local:iso/seed.iso
Start the VM and wait for it to boot.
qm start 888
Once the VM has booted, ssh to the VM with the username admin and the ssh-key defined with cloud-init
ssh -i ~/.ssh/id_rsa admin@192.168.1.241
Welcome to VyOS!
Check out project news at https://blog.vyos.io
and feel free to report bugs at https://vyos.dev
You can change this banner using "set system login banner post-login" command.
VyOS is a free software distribution that includes multiple components,
you can check individual component licenses under /usr/share/doc/*/copyright
admin@vyos-test#
🥳 Success 🥳
admin@vyos-test# show interfaces
# output
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface IP Address S/L Description
--------- ---------- --- -----------
eth0 192.168.1.241/24 u/u MGMT
lo 127.0.0.1/8 u/u
::1/128
In this post, I showed you how to import a VyOS Qemu image to Proxmox and deploy a VM, applying an initial configuration via cloud-init.
Look out for future posts as I travel on this adventure to configure VyOS for my home network.
https://docs.vyos.io/en/latest/automation/cloud-init.html
https://cloudinit.readthedocs.io/en/latest/reference/network-config.html