From f1dd7f04d4b744a550689692965989ab4b037dd5 Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 14 May 2022 21:53:40 +0200 Subject: [PATCH] initial commit --- README.md | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4e49d3 --- /dev/null +++ b/README.md @@ -0,0 +1,143 @@ +# libvirt/virt-install + +## Prerequisites + +`libvirt`, `qemu`, `virt-install` + +On archlinux: + +```bash +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 + +```bash +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: + +```bash +grub-mkconfig -o /boot/grub/grub.cfg +``` + +### Nixos + +```bash +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) + +```bash +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 + +```bash +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 + +```bash +# 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: + +```bash +virsh edit +``` + +then add a pty console: + +```xml + + + +``` + +Also see notes about serial consoles above.