diff --git a/active/software_virsh/dual-stack-dhcp.xml b/active/software_virsh/dual-stack-dhcp.xml index 9a78211..879e81a 100644 --- a/active/software_virsh/dual-stack-dhcp.xml +++ b/active/software_virsh/dual-stack-dhcp.xml @@ -2,9 +2,9 @@ dual-stack - + - + diff --git a/active/software_virsh/virsh.md b/active/software_virsh/virsh.md index 7ab3f90..c9248c9 100644 --- a/active/software_virsh/virsh.md +++ b/active/software_virsh/virsh.md @@ -8,6 +8,8 @@ Virtual Machine Management - [Virsh Networking](#virsh-networking) - [Create a Virtual Network](#create-a-virtual-network) - [Attach a New Virtual Network](#attach-a-new-virtual-network) + - [Detach a Virtual Network](#detach-a-virtual-network) + - [Destroy a Virtual Network](#destroy-a-virtual-network) - [Set a Static IP](#set-a-static-ip) - [Creating VMs](#creating-vms) - [Create VM with No Graphics and use an Existing QCOW2 Disk](#create-vm-with-no-graphics-and-use-an-existing-qcow2-disk) @@ -56,10 +58,10 @@ virsh shutdown virsh destroy # Remove a VM -virsh undefine +virsh undefine --nvram # Remove a VM including storage -virsh undefine --remove-all-storage +virsh undefine --nvram --remove-all-storage ``` ## Virsh Networking @@ -118,27 +120,42 @@ virsh attach-interface \ --domain ${VM_NAME} ``` +### Detach a Virtual Network + +```bash +# List mac addresses of connected interfaces' +export VM_NAME=my_vm +virsh domiflist --domain $VM_NAME +virsh detach-interface --domain k0s-worker0 --type bridge --mac "52:54:00:f6:b9:83" --live +``` + +### Destroy a Virtual Network + +```bash +export NETWORK_NAME=mynetwork +virsh net-undefine --network $NETWORK_NAME +virsh net-destroy --network $NETWORK_NAME +``` + ### Set a Static IP To set a static IP, run `virsh net-edit default` and add the following between `` and `` -```xml - -``` - -Then run - ```bash -# `--location /path/to/image.iso` supplies a disk installer. (Remove `--import`) -# `--import` skips the installation process. -# `--graphics spice --video qxl --channel spicevmc` installs graphics -# `--console pty,target.type=virtio` adds a console connection -# For any command, use `virt-install --arg=?` to see all available options -virsh net-destroy default -virsh net-start default -virsh shutdown virtual_machine -systemctl restart libvirtd -virsh start virtual_machine +# Add a host +virsh net-update default add-last ip-dhcp-host \ + '' \ + --live --config --parent-index 0 + +# Modify a host +virsh net-update default modify ip-dhcp-host \ + '' \ + --live --config --parent-index 0 + +# Delete a host +virsh net-update default delete ip-dhcp-host \ + '' \ + --live --config --parent-index 0 ``` ## Creating VMs @@ -153,7 +170,9 @@ installation process altogether. ```bash sudo systemctl start osbuild-composer.socket composer-cli compose list -composer-cli compose image --filename /var/lib/libvirt/images/fedora-42-test.qcow2 image-uuid +export IMAGE_UUID= +export VM_DISK_PATH=/var/lib/libvirt/images/fedora43-test.qcow2 +composer-cli compose image --filename ${VM_DISK_PATH} ${IMAGE_UUID} ``` ### Create VM with No Graphics and use an Existing QCOW2 Disk @@ -162,17 +181,21 @@ composer-cli compose image --filename /var/lib/libvirt/images/fedora-42-test.qco # Start the default network if it isn't already virsh net-start --network default +export VM_NAME="fedora43-test" +export VM_DISK_PATH=/var/lib/libvirt/images/fedora43-test.qcow2 + +# OPTIONAL: export your qcow2 disk now if using osbuild +export IMAGE_UUID= +composer-cli compose image --filename ${VM_DISK_PATH} ${IMAGE_UUID} + +# Install # `--location /path/to/image.iso` supplies a disk installer. (Remove `--import`) # `--import` skips the installation process. -# `--graphics spice --video qxl --channel spicevmc` installs graphics +# `--graphics spice --video qxl,model.ram=131072,model.vram=131072,model.vgamem=131072 --channel spicevmc` installs graphics # `--console pty,target.type=virtio` adds a console connection # For any command, use `virt-install --arg=?` to see all available options -export VM_NAME="fedora42-test" -export VM_DESCRIPTION="Test VM with Fedora42" -export VM_DISK_PATH="/var/lib/libvirt/images/fedora-42-test.qcow2" virt-install \ --name "${VM_NAME}" \ ---description "${DESCRIPTION}" \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \ --ram=8192 \ @@ -192,18 +215,16 @@ virt-install \ # `--console pty,target.type=virtio` adds a console connection # For any command, use `virt-install --arg=?` to see all available options export VM_NAME="fedora43-kinoite-test" -export VM_DESCRIPTION="Test VM with Fedora43 Kinoite" -export VM_DISK_PATH="/var/lib/libvirt/images/fedora-43-kinoite.qcow2" -export VM_ISO_PATH="/var/lib/libvirt/iso/Fedora-Kinoite-ostree-x86_64-43-1.6.iso" +export VM_ISO_PATH=/var/lib/libvirt/iso/ +export VM_DISK_PATH=/var/lib/libvirt/images/ virt-install \ --name "${VM_NAME}" \ ---description "${DESCRIPTION}" \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \ --ram=8192 \ --os-variant=fedora41 \ --network bridge:virbr0 \ ---graphics spice --video qxl --channel spicevmc \ +--graphics spice --video virtio --channel spicevmc \ --cdrom ${VM_ISO_PATH} \ --disk "path=${VM_DISK_PATH},size=64,bus=virtio,format=qcow2" ``` @@ -218,10 +239,8 @@ virt-install \ # `--hostdev 0x1234:0x5678` adds a block storage device # For any command, use `virt-install --arg=?` to see all available options export VM_NAME="usb-linux" -export VM_DESCRIPTION="Linux running 0x13fe:0x6500 as the boot drive" virt-install \ --name "${VM_NAME}" \ ---description "${DESCRIPTION}" \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --import \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \