README.md |
libvirt/virt-install
Prerequisites
libvirt
, qemu
, virt-install
On archlinux:
pacman -S virt-install libvirt qemu-desktop
pacman -S virt-manager # optional, graphical interface to libvirt
pacman -S qemu-emulators-full # optional, provides extra architectures emulation for qemu
systemctl enable libvirtd.socket # socket activation
Installing VMs
Archlinux
curl -O "https://mirror.checkdomain.de/archlinux/iso/2022.05.01/archlinux-2022.05.01-x86_64.iso"
virt-install --name archlinux \
--memory 2048 \
--vcpus=2,maxvcpus=4 --cpu host \
--cdrom archlinux-2022.05.01-x86_64.iso \
--disk size=4,format=qcow2 \
--network user \
--virt-type kvm \
--console pty,target_type=virtio \
--nographics
Follow the installation procedure. Edit the kernel cmdline and a serial console before rebooting otherwise the virsh
serial console won't work:
In /etc/default/grub
, add to the following to GRUB_CMDLINE_LINUX
along with any other cmdline flags you require
GRUB_CMDLINE_LINUX=console=tty0 console=ttyS0,115200 # and any other flags
Update grub:
grub-mkconfig -o /boot/grub/grub.cfg
Nixos
curl -O "https://channels.nixos.org/nixos-21.11/latest-nixos-minimal-x86_64-linux.iso"
virt-install --name nixos \
--memory 2048 \
--vcpus=2,maxvcpus=4 \
--cpu host \
--cdrom latest-nixos-minimal-x86_64-linux.iso \
--disk size=4,format=qcow2 \
--network user \
--virt-type kvm \
--console pty,target_type=virtio \
--nographics
Follow the installation procedure, adding the following to /etc/nixos/configuration.nix
, otherwise the virsh
serial console won't work
boot.kernelParams = [
"console=ttyS0,115200"
"console=tty1"
];
Ubuntu 21.10 (focal)
virt-install --name ubuntu-focal \
--memory 2048 \
--vcpus=2,maxvcpus=4 \
--cpu host \
--pxe \
--disk size=4,format=qcow2 \
--network user \
--virt-type kvm \
--nographics \
--osinfo ubuntufocal \
--extra-args="console=tty0 console=ttyS0,115200" \
--location http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/
Other OSs
You can list other supported Operating Systems using
virt-install --osinfo list
# More info about available OSs
osinfo-query os
Note about serial consoles
In order for the virsh serial console to work, these kernel cmdline options have to be provided
console=tty0 console=ttyS0,115200
Usage
# list all available domains (running and stopped)
virsh list --all
# Start a domain ("archlinux")
virsh start archlinux
# Connect to the serial console
virsh console archlinux
# Destroy (destop) a domain ("archlinux")
virsh destroy archlinux
# Remove a domain
virsh undefine archlinux # disks will **not** be removed
# Edit a domain
virsh edit archlinux
# Get information about network configuration
virsh domifaddr archlinux
Note about serial consoles
Serial consoles might not work out of the box, so it might be required to edit the domain definition to add a serial console:
virsh edit <domain>
then add a pty console:
<console type='pty'>
<target type='virtio' port='0'/>
</console>
Also see notes about serial consoles above.