add virsh networking notes
All checks were successful
Podman DDNS Image / build-and-push-ddns (push) Successful in 1m50s

This commit is contained in:
2025-11-13 17:05:06 -05:00
parent 621be95870
commit 5516f9530b
2 changed files with 52 additions and 33 deletions

View File

@@ -2,9 +2,9 @@
<name>dual-stack</name> <name>dual-stack</name>
<forward mode="nat"/> <forward mode="nat"/>
<domain name="dual-stack"/> <domain name="dual-stack"/>
<ip address="192.168.100.1" netmask="255.255.255.0"> <ip address="192.168.123.1" netmask="255.255.255.0">
<dhcp> <dhcp>
<range start="192.168.100.2" end="192.168.100.254"/> <range start="192.168.123.2" end="192.168.123.99"/>
</dhcp> </dhcp>
</ip> </ip>
<ip family="ipv6" address="fd4d:58e7:17f6:1::1" prefix="64"/> <ip family="ipv6" address="fd4d:58e7:17f6:1::1" prefix="64"/>

View File

@@ -8,6 +8,8 @@ Virtual Machine Management
- [Virsh Networking](#virsh-networking) - [Virsh Networking](#virsh-networking)
- [Create a Virtual Network](#create-a-virtual-network) - [Create a Virtual Network](#create-a-virtual-network)
- [Attach a New Virtual Network](#attach-a-new-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) - [Set a Static IP](#set-a-static-ip)
- [Creating VMs](#creating-vms) - [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) - [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 <domain>
virsh destroy <domain> virsh destroy <domain>
# Remove a VM # Remove a VM
virsh undefine <domain> virsh undefine --nvram <domain>
# Remove a VM including storage # Remove a VM including storage
virsh undefine <domain> --remove-all-storage virsh undefine <domain> --nvram --remove-all-storage
``` ```
## Virsh Networking ## Virsh Networking
@@ -118,27 +120,42 @@ virsh attach-interface \
--domain ${VM_NAME} --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 ### Set a Static IP
To set a static IP, run `virsh net-edit default` and add the following between `<dhcp>` and `</dhcp>` To set a static IP, run `virsh net-edit default` and add the following between `<dhcp>` and `</dhcp>`
```xml
<host mac='xx:xx:0x:xx:xx:1x' name='virtual_machine' ip='1xx.1xx.1xx.xx'/>
```
Then run
```bash ```bash
# `--location /path/to/image.iso` supplies a disk installer. (Remove `--import`) # Add a host
# `--import` skips the installation process. virsh net-update default add-last ip-dhcp-host \
# `--graphics spice --video qxl --channel spicevmc` installs graphics '<host mac="52:54:00:6f:78:f3" ip="192.168.122.222"/>' \
# `--console pty,target.type=virtio` adds a console connection --live --config --parent-index 0
# For any command, use `virt-install --arg=?` to see all available options
virsh net-destroy default # Modify a host
virsh net-start default virsh net-update default modify ip-dhcp-host \
virsh shutdown virtual_machine '<host mac="52:54:00:6f:78:f3" ip="192.168.122.222"/>' \
systemctl restart libvirtd --live --config --parent-index 0
virsh start virtual_machine
# Delete a host
virsh net-update default delete ip-dhcp-host \
'<host mac="52:54:00:6f:78:f3" ip="192.168.122.222"/>' \
--live --config --parent-index 0
``` ```
## Creating VMs ## Creating VMs
@@ -153,7 +170,9 @@ installation process altogether.
```bash ```bash
sudo systemctl start osbuild-composer.socket sudo systemctl start osbuild-composer.socket
composer-cli compose list 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 ### 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 # Start the default network if it isn't already
virsh net-start --network default 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`) # `--location /path/to/image.iso` supplies a disk installer. (Remove `--import`)
# `--import` skips the installation process. # `--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 # `--console pty,target.type=virtio` adds a console connection
# For any command, use `virt-install --arg=?` to see all available options # 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 \ virt-install \
--name "${VM_NAME}" \ --name "${VM_NAME}" \
--description "${DESCRIPTION}" \
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
--cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \
--ram=8192 \ --ram=8192 \
@@ -192,18 +215,16 @@ virt-install \
# `--console pty,target.type=virtio` adds a console connection # `--console pty,target.type=virtio` adds a console connection
# For any command, use `virt-install --arg=?` to see all available options # For any command, use `virt-install --arg=?` to see all available options
export VM_NAME="fedora43-kinoite-test" export VM_NAME="fedora43-kinoite-test"
export VM_DESCRIPTION="Test VM with Fedora43 Kinoite" export VM_ISO_PATH=/var/lib/libvirt/iso/
export VM_DISK_PATH="/var/lib/libvirt/images/fedora-43-kinoite.qcow2" export VM_DISK_PATH=/var/lib/libvirt/images/
export VM_ISO_PATH="/var/lib/libvirt/iso/Fedora-Kinoite-ostree-x86_64-43-1.6.iso"
virt-install \ virt-install \
--name "${VM_NAME}" \ --name "${VM_NAME}" \
--description "${DESCRIPTION}" \
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
--cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \
--ram=8192 \ --ram=8192 \
--os-variant=fedora41 \ --os-variant=fedora41 \
--network bridge:virbr0 \ --network bridge:virbr0 \
--graphics spice --video qxl --channel spicevmc \ --graphics spice --video virtio --channel spicevmc \
--cdrom ${VM_ISO_PATH} \ --cdrom ${VM_ISO_PATH} \
--disk "path=${VM_DISK_PATH},size=64,bus=virtio,format=qcow2" --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 # `--hostdev 0x1234:0x5678` adds a block storage device
# For any command, use `virt-install --arg=?` to see all available options # For any command, use `virt-install --arg=?` to see all available options
export VM_NAME="usb-linux" export VM_NAME="usb-linux"
export VM_DESCRIPTION="Linux running 0x13fe:0x6500 as the boot drive"
virt-install \ virt-install \
--name "${VM_NAME}" \ --name "${VM_NAME}" \
--description "${DESCRIPTION}" \
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \ --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
--import \ --import \
--cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \ --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \