KVM "Virgin" Files — Setting Up a Clean KVM Virtual Machine
1. Download a Clean ISO for Installation
Start with a fresh, verified ISO from official sources. Here are direct links to popular operating systems:
For related Linux/VPS / port topics, see BD Hosting for VPS — Setup and Use, How to Use Port 8080 on a VPS, and Why Do Users from Uzbekistan Prefer European Hosting?.
- Ubuntu: https://releases.ubuntu.com/ (Latest LTS recommended for servers)
- Debian: https://www.debian.org/distrib/
- CentOS Stream: https://www.centos.org/download/
- Rocky Linux: https://rockylinux.org/download/
- AlmaLinux: https://almalinux.org/
- Windows ISO: https://www.microsoft.com/software-download/windows11 (or Windows 10/Server versions)
Save the ISO File
Once downloaded, move the ISO to KVM's standard image directory:
# Create directory if it doesn't exist
sudo mkdir -p /var/lib/libvirt/images/
# Move or download directly to the directory
sudo mv ~/Downloads/ubuntu-22.04.iso /var/lib/libvirt/images/
# Or download directly using wget
sudo wget -O /var/lib/libvirt/images/ubuntu-22.04.iso https://releases.ubuntu.com/22.04/ubuntu-22.04-live-server-amd64.iso
2. Create a Clean KVM Disk Image
Create a pristine disk image that will serve as the virtual machine's storage.
Create a RAW Format Disk (Better Performance)
sudo qemu-img create -f raw /var/lib/libvirt/images/clean_vm.img 20G
RAW format offers near-native performance but doesn't support advanced features like snapshots.
Create a QCOW2 Format Disk (Recommended for Most Use Cases)
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/clean_vm.qcow2 20G
QCOW2 (QEMU Copy-On-Write) supports snapshots, compression, and encryption. It's the recommended format for most KVM deployments.
Format Comparison: Choose QCOW2 if you want snapshots and more features. Choose RAW for maximum performance (especially with SSDs) or compatibility with other tools.
Verify the Disk Image
# List files in the images directory
ls -lah /var/lib/libvirt/images/
# Check disk image info
sudo qemu-img info /var/lib/libvirt/images/clean_vm.qcow2
3. Create a New Virtual Machine Using "Virgin" Files
With your clean ISO and disk image ready, create a new VM using the virt-install command.
Basic VM Creation Command
sudo virt-install \
--name clean_vm \
--ram 2048 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/clean_vm.qcow2,format=qcow2 \
--cdrom /var/lib/libvirt/images/ubuntu-22.04.iso \
--os-type linux \
--network network=default \
--graphics vnc \
--boot menu=on
This creates a KVM VM with the following specifications:
- Name:
clean_vm
- RAM: 2GB (2048 MB)
- vCPUs: 2 virtual CPUs
- Disk: 20GB QCOW2 image (clean_vm.qcow2)
- Installation Media: Ubuntu 22.04 ISO
- Network: Default NAT network
- Graphics: VNC for remote access
- Boot: Menu enabled for installation
Adjust for Your Needs: Modify RAM, vCPU count, disk size, and ISO path according to your requirements. For Windows VMs, change --os-type linux to --os-type windows.
4. Start and Access the Virtual Machine
Start the VM
# Start the VM (if not started automatically by virt-install)
sudo virsh start clean_vm
# Check VM status
sudo virsh list --all
Access Methods
Method 1: VNC Console (Graphical)
# Find the VNC display port
sudo virsh vncdisplay clean_vm
# Output will be like: :0 or :1
# Connect with a VNC client to localhost:5900 (for :0) or localhost:5901 (for :1)
Method 2: Serial Console (Text-based)
# Connect to the serial console
sudo virsh console clean_vm
# To exit the console, press: Ctrl + ]
Method 3: SSH (After OS Installation)
# Get the VM's IP address
sudo virsh domifaddr clean_vm
# SSH into the VM (after OS installation and network configuration)
ssh username@vm_ip_address
5. Remove an Existing VM & Files (Clean Start)
If you need to delete an old VM completely and start fresh with virgin files:
Irreversible Action: This will permanently delete the VM and its disk image. Ensure you have backups if needed.
Complete VM Removal
# 1. Shutdown the VM if it's running
sudo virsh destroy old_vm
# 2. Undefine the VM from libvirt
sudo virsh undefine old_vm
# 3. Delete the disk image file
sudo rm -rf /var/lib/libvirt/images/old_vm.qcow2
# 4. Optional: Delete any associated ISO files
sudo rm -rf /var/lib/libvirt/images/old_vm.iso
Now you can create a completely clean KVM setup with virgin files.
6. Summary of KVM "Virgin" Setup
Step
Command/Action
Download fresh ISO
Get from Ubuntu, Debian, CentOS, Windows official sites
Create clean KVM disk
qemu-img create -f qcow2 /var/lib/libvirt/images/clean_vm.qcow2 20G
Install new VM
Use virt-install with ISO, disk, RAM, and vCPU parameters
Start the VM
virsh start clean_vm
Access VM
VNC: virsh vncdisplay clean_vm or console: virsh console clean_vm
Delete old VM
virsh destroy old_vm && virsh undefine old_vm && rm -rf /var/lib/libvirt/images/old_vm.qcow2
Following these steps will give you a clean, untouched ("virgin") KVM virtual machine ready for your custom configuration!


