|
|
@@ -112,7 +112,7 @@ Substitute ```enp4s0``` with the interface from Step 1 above.
|
|
|
|
|
|
This method provides full control over VM creation:
|
|
|
|
|
|
- # Create a directory for VM images
|
|
|
+ # Create a directory for VM images
|
|
|
sudo mkdir -p /var/kvm/images
|
|
|
|
|
|
# Download Ubuntu 24.04 Server ISO
|
|
|
@@ -156,7 +156,7 @@ For desktop users, install the graphical interface:
|
|
|
|
|
|
#### Starting and Stopping VMs
|
|
|
|
|
|
- # Start a VM
|
|
|
+ # Start a VM
|
|
|
virsh start ubuntu-vm1
|
|
|
# Start and connect to console
|
|
|
virsh start ubuntu-vm1 --console
|
|
|
@@ -169,7 +169,7 @@ For desktop users, install the graphical interface:
|
|
|
|
|
|
#### Listing and Monitoring VMs
|
|
|
|
|
|
- # List running VMs
|
|
|
+ # List running VMs
|
|
|
virsh list
|
|
|
# List all VMs (including stopped)
|
|
|
virsh list --all
|
|
|
@@ -196,7 +196,7 @@ For desktop users, install the graphical interface:
|
|
|
|
|
|
### Creating Storage Pools
|
|
|
|
|
|
- # Create a new storage pool directory
|
|
|
+ # Create a new storage pool directory
|
|
|
sudo mkdir -p /var/lib/libvirt/images/vmpool
|
|
|
# Define the storage pool
|
|
|
virsh pool-define-as vmpool dir - - - - "/var/lib/libvirt/images/vmpool"
|
|
|
@@ -209,7 +209,7 @@ For desktop users, install the graphical interface:
|
|
|
|
|
|
### Managing Virtual Disks
|
|
|
|
|
|
- # Create a new disk
|
|
|
+ # Create a new disk
|
|
|
virsh vol-create-as vmpool ubuntu-vm2.qcow2 30G --format qcow2
|
|
|
# List volumes in a pool
|
|
|
virsh vol-list vmpool
|
|
|
@@ -220,11 +220,11 @@ For desktop users, install the graphical interface:
|
|
|
|
|
|
### Install Management Utilities
|
|
|
|
|
|
- sudo apt -y install libguestfs-tools virt-top
|
|
|
+ sudo apt -y install libguestfs-tools virt-top
|
|
|
|
|
|
### Using libguestfs Tools
|
|
|
|
|
|
- # List files in VM
|
|
|
+ # List files in VM
|
|
|
virt-ls -l -d ubuntu-vm1 /etc
|
|
|
# View file content
|
|
|
virt-cat -d ubuntu-vm1 /etc/hostname
|
|
|
@@ -252,7 +252,7 @@ For desktop users, install the graphical interface:
|
|
|
# Clone a VM
|
|
|
virt-clone --original ubuntu-vm1 --name ubuntu-vm2 --file /var/kvm/images/ubuntu-vm2.img
|
|
|
# Clone with auto-generated storage
|
|
|
-virt-clone --original ubuntu-vm1 --name ubuntu-vm3 --auto-clone
|
|
|
+ virt-clone --original ubuntu-vm1 --name ubuntu-vm3 --auto-clone
|
|
|
|
|
|
### Managing Snapshots
|
|
|
|
|
|
@@ -278,7 +278,7 @@ Enable nested virtualization to run VMs inside VMs:
|
|
|
|
|
|
### Enable Nested Virtualization
|
|
|
|
|
|
- # For Intel CPUs
|
|
|
+ # For Intel CPUs
|
|
|
echo 'options kvm_intel nested=1' | sudo tee /etc/modprobe.d/kvm-intel.conf
|
|
|
# For AMD CPUs
|
|
|
echo 'options kvm_amd nested=1' | sudo tee /etc/modprobe.d/kvm-amd.conf
|
|
|
@@ -297,13 +297,13 @@ Enable nested virtualization to run VMs inside VMs:
|
|
|
|
|
|
### CPU Pinning
|
|
|
|
|
|
- # Pin vCPUs to physical CPUs
|
|
|
+ # Pin vCPUs to physical CPUs
|
|
|
virsh vcpupin ubuntu-vm1 0 0
|
|
|
virsh vcpupin ubuntu-vm1 1 1
|
|
|
|
|
|
## Memory Optimization
|
|
|
|
|
|
- # Set memory balloon
|
|
|
+ # Set memory balloon
|
|
|
virsh setmem ubuntu-vm1 2048M --config
|
|
|
# Enable hugepages
|
|
|
echo 'vm.nr_hugepages = 1024' | sudo tee -a /etc/sysctl.conf
|
|
|
@@ -313,7 +313,7 @@ Enable nested virtualization to run VMs inside VMs:
|
|
|
|
|
|
Use VirtIO drivers and cache modes:
|
|
|
|
|
|
- <disk type='file' device='disk'>
|
|
|
+ <disk type='file' device='disk'>
|
|
|
<driver name='qemu' type='qcow2' cache='writeback' io='threads'/>
|
|
|
<source file='/var/kvm/images/ubuntu-vm1.img'/>
|
|
|
<target dev='vda' bus='virtio'/>
|
|
|
@@ -323,7 +323,7 @@ Use VirtIO drivers and cache modes:
|
|
|
|
|
|
### Backup VMs
|
|
|
|
|
|
- # Backup VM configuration
|
|
|
+ # Backup VM configuration
|
|
|
virsh dumpxml ubuntu-vm1 > ubuntu-vm1.xml
|
|
|
# Backup disk image
|
|
|
sudo cp /var/kvm/images/ubuntu-vm1.img /backup/
|