advanced
VM Management and Advanced Features
Managing Your Ubuntu VM
Basic VM Operations
Starting and Stopping
- Start: Click on the VM in GNOME Boxes main window
- Pause: Click pause button while VM is running (saves current state)
- Shutdown: Click power button → "Shut Down" (graceful shutdown)
- Force Shutdown: Right-click VM → "Force Shutdown" (like pulling power)
Keyboard Shortcuts in VM Window
- Ctrl+Alt: Release mouse from VM window
- F11: Toggle fullscreen
- Ctrl+Alt+F: Toggle fullscreen (alternative)
- Ctrl+Alt+Q: Quit VM window (VM keeps running)
Snapshots
Snapshots save the complete VM state at a point in time, perfect for:
- Before system updates
- Before installing new software
- Creating restore points for testing
Creating Snapshots
- Right-click VM → Properties
- Go to Snapshots tab
- Click "+" button
- Name it descriptively:
- "Fresh Install - Ubuntu 24.04"
- "Before Development Setup"
- "Clean State - 2024-01-15"
Managing Snapshots
# From command line (advanced)
# List snapshots
virsh snapshot-list "Ubuntu-VM-Name"
# Create snapshot
virsh snapshot-create-as "Ubuntu-VM-Name" "Snapshot-Name" "Description"
# Revert to snapshot
virsh snapshot-revert "Ubuntu-VM-Name" "Snapshot-Name"
# Delete snapshot
virsh snapshot-delete "Ubuntu-VM-Name" "Snapshot-Name"
Snapshot Best Practices
- Take snapshots when VM is shut down for consistency
- Delete old snapshots to save disk space
- Name snapshots descriptively
- Don't rely on snapshots as backups
Cloning VMs
Cloning creates an exact copy of your VM:
Via GNOME Boxes
- Ensure source VM is shut down
- Right-click VM → Clone
- Enter new name
- Wait for cloning to complete
Via Command Line
# Full clone (independent copy)
virt-clone --original "Ubuntu-VM" --name "Ubuntu-Clone" --auto-clone
# Check the clone
virsh list --all
VM Import/Export
Exporting a VM
# Find VM storage location
virsh domblklist "Ubuntu-VM"
# Export VM definition
virsh dumpxml "Ubuntu-VM" > ubuntu-vm.xml
# Copy disk image (usually in)
cp /var/lib/libvirt/images/ubuntu-vm.qcow2 ~/backup/
Importing a VM
# Define VM from XML
virsh define ubuntu-vm.xml
# Copy disk image to correct location
sudo cp ~/backup/ubuntu-vm.qcow2 /var/lib/libvirt/images/
# Start the imported VM
virsh start "Ubuntu-VM"
Advanced Features
USB Device Passthrough
To use USB devices in your VM:
- Insert USB device into host
- In GNOME Boxes, while VM is running:
- Click the "..." menu in VM window
- Select "Preferences"
- Go to "Devices & Shares"
- Toggle on the USB device
Troubleshooting USB
# In VM, check if device is detected
lsusb
# If not showing, install utilities
sudo apt install usb-utils
# Check permissions
sudo usermod -aG plugdev $USER
Network Configuration
Default NAT Network
- VM gets IP like 192.168.122.x
- Can access internet
- Host can't directly access VM
- VM can't be accessed from network
Viewing Network Info
# In VM
ip addr show
ip route show
# On host
virsh net-list --all
virsh net-info default
Port Forwarding (NAT)
# Example: Forward host port 8080 to VM port 80
# Edit network configuration
virsh net-edit default
# Add inside <network> tags:
<forward mode='nat'>
<nat>
<port start='8080' end='8080'>
<to addr='192.168.122.100' port='80'/>
</port>
</nat>
</forward>
# Restart network
virsh net-destroy default
virsh net-start default
Resource Hot-Adding
Some resources can be changed while VM is running:
Add/Remove CPUs
# Check current CPUs
virsh vcpucount "Ubuntu-VM"
# Set CPU count (VM must support hotplug)
virsh setvcpus "Ubuntu-VM" 4 --live
Memory Ballooning
# Check current memory
virsh dommemstat "Ubuntu-VM"
# Adjust memory (in KB)
virsh setmem "Ubuntu-VM" 4194304 --live # 4GB
Disk Management
Expand Virtual Disk
# Check current disk size
qemu-img info /var/lib/libvirt/images/ubuntu-vm.qcow2
# Expand disk (VM must be off)
qemu-img resize /var/lib/libvirt/images/ubuntu-vm.qcow2 +10G
# In VM, expand partition
sudo growpart /dev/sda 1
sudo resize2fs /dev/sda1
Add Additional Disk
- In GNOME Boxes: Properties → Add Hardware → Storage
- Create new disk image
- In VM, format and mount:
# Find new disk
lsblk
# Format (assuming /dev/sdb)
sudo mkfs.ext4 /dev/sdb
# Mount
sudo mkdir /mnt/data
sudo mount /dev/sdb /mnt/data
# Make permanent
echo '/dev/sdb /mnt/data ext4 defaults 0 2' | sudo tee -a /etc/fstab
Backup Strategies
Method 1: Snapshot-Based Backup
# Create snapshot
virsh snapshot-create-as "Ubuntu-VM" backup-$(date +%Y%m%d)
# Export snapshot
virsh snapshot-dumpxml "Ubuntu-VM" backup-$(date +%Y%m%d) > backup.xml
# Copy disk image while VM runs
cp /var/lib/libvirt/images/ubuntu-vm.qcow2 ~/backup/
Method 2: Live Backup with Virsh
# Backup running VM
virsh backup-begin "Ubuntu-VM" backup.xml
# Check backup progress
virsh domjobinfo "Ubuntu-VM"
Method 3: Inside VM Backup
# Use standard Linux backup tools
sudo apt install timeshift
# Or
sudo apt install deja-dup
Performance Monitoring
Host-Side Monitoring
# Monitor VM resource usage
virt-top
# Detailed VM stats
virsh domstats "Ubuntu-VM"
# Real-time performance
virsh dommemstat "Ubuntu-VM" --period 1
Guest-Side Monitoring
# Install monitoring stack
sudo apt install prometheus-node-exporter
sudo apt install netdata
# Access Netdata dashboard
# http://localhost:19999
Automation with Virsh
Create Start/Stop Scripts
#!/bin/bash
# start-vm.sh
virsh start "Ubuntu-VM"
virt-viewer "Ubuntu-VM" &
# stop-vm.sh
virsh shutdown "Ubuntu-VM"
Autostart VM on Boot
# Enable autostart
virsh autostart "Ubuntu-VM"
# Disable autostart
virsh autostart --disable "Ubuntu-VM"
Security Hardening
Enable AppArmor/SELinux for VMs
# Check security driver
virsh capabilities | grep secmodel
# Enable AppArmor profile
sudo aa-enforce /etc/apparmor.d/libvirt/libvirt-*
Limit VM Resources
# Set CPU quota (50% of one CPU)
virsh schedinfo "Ubuntu-VM" --set vcpu_quota=50000
# Set I/O limits
virsh blkdeviotune "Ubuntu-VM" sda --total-bytes-sec=10485760
These management features give you professional-level control over your Ubuntu VM while keeping the simplicity of GNOME Boxes for day-to-day use.
Backlinks