Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

KVM "Virgin" Files — Setting Up a Clean KVM Virtual Machine

5 min read
25.05.2025

1. Download a Clean ISO for Installation

Start with a fresh, verified ISO from official sources. Here are direct links to popular operating systems:

KVM Clean Virgin VM Setup
Virgin KVM image — cloud base + cloud-init for customization.

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?.

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
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

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!

Frequently asked questions
Ubuntu: cloud-images.ubuntu.com (qcow2, latest 22.04/24.04). CentOS Stream: cloud.centos.org. Debian: cdimage.debian.org/cdimage/cloud/. AlmaLinux: almalinux.org/get-almalinux. Rocky Linux: rockylinux.org/download. All ship qcow2 ready for KVM/libvirt. Official sources only — third-party rebuilds may have backdoors.
On first boot, cloud-init reads metadata (from cloud provider, or a NoCloud datasource via cloud-localds), customizes: hostname, SSH keys, user accounts, package install, scripts. Lets you parameterize a single virgin image for many deployments. Without cloud-init, you'd boot the VM and configure each manually.
Use qcow2's `backing_file` feature: virgin image is the backing file, new VMs get their own thin-cloned qcow2 referencing the backing file. New VMs share base disk (saves space) and only diverge as they write. Snapshot the virgin: `virsh snapshot-create-as `. Roll back: revert to snapshot.
`virt-sysprep -a /path/to/image.qcow2` (from libguestfs-tools). Removes: machine-id, SSH host keys, log files, command history, network MAC configuration. After sysprep, image is ready for redistribution as a true template. Without it, every clone has the same machine-id (causes issues with logging and some daemons).
Related articles
How to Reinstall PrestaShop on Your Server
locale-gen Command on Debian
Install ImageMagick or GD — Server Administrator's Guide