initial commit

This commit is contained in:
bretello 2022-05-14 21:53:40 +02:00
commit f1dd7f04d4
Signed by: brethil
GPG Key ID: 876AAC6290170FE7

143
README.md Normal file
View File

@ -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 <domain>
```
then add a pty console:
```xml
<console type='pty'>
<target type='virtio' port='0'/>
</console>
```
Also see notes about serial consoles above.