Comparing KVM Disk Types: Raw vs QCOW2 vs LVM – Performance, Cloning, Expansion and Migration Guide


2 views

When provisioning KVM virtual machines, choosing the right disk format impacts performance, manageability, and scalability. The three primary options each have distinct characteristics:

Raw format provides direct access to storage without additional abstraction layers.

# Create a 20GB raw image
qemu-img create -f raw vm_disk.raw 20G
  • Performance: Near-native speed (direct I/O passthrough)
  • Cloning: Fast but space-intensive (full copy required)
  • Expansion: Manual process using tools like fallocate or dd
  • Backup: Requires full image copy (LVM snapshots can help)
  • Migration: Simple file transfer but large size impacts speed

The most feature-rich format with snapshot and compression capabilities:

# Create qcow2 with 10GB virtual size (thin provisioning)
qemu-img create -f qcow2 vm_disk.qcow2 10G

# Convert raw to qcow2
qemu-img convert -f raw -O qcow2 input.raw output.qcow2
  • Performance: ~5-15% overhead due to metadata management
  • Cloning: Fast with backing files (only stores delta changes)
  • Expansion: Simple resize command: qemu-img resize vm.qcow2 +5G
  • Features: Snapshots, compression, encryption, sparse allocation
  • Backup: Efficient with incremental backups using qemu-img

Directly using logical volumes offers advanced storage management:

# Create LV for KVM
lvcreate -L 50G -n vm_disk vg_kvm

# Convert to thin provisioning
lvcreate -V 100G -T vg_kvm/thin_pool -n vm_thin
  • Performance: Excellent (bypasses filesystem overhead)
  • Cloning: Instant with LVM snapshots: lvcreate -s
  • Expansion: Online resize with lvextend
  • Migration: Requires shared storage or LVM replication
  • Features: Thin provisioning, RAID integration, caching
Requirement Best Choice
Maximum performance Raw or LVM
Snapshot support QCOW2 or LVM
Storage efficiency QCOW2 (sparse) or LVM thin
Cloud migration QCOW2 (standard format)
SAN/NAS integration LVM or raw

Combining QCOW2 with LVM for optimal balance:

# Create LVM thin pool
lvcreate -L 100G -T vg_kvm/thin_pool

# Allocate thin volume
lvcreate -V 50G -T vg_kvm/thin_pool -n vm_base

# Format as QCOW2
qemu-img convert -f raw -O qcow2 /dev/vg_kvm/vm_base vm_base.qcow2

# Create derivative images
qemu-img create -f qcow2 -b vm_base.qcow2 vm_clone.qcow2

When setting up KVM virtual machines, choosing the right disk storage format significantly impacts performance, manageability, and scalability. Let's examine the three primary options with practical examples.

Characteristics:

  • Direct byte-for-byte representation of disk contents
  • No overhead from formatting or metadata

# Creating a raw disk image
qemu-img create -f raw vm_disk.raw 20G

Pros:

  • Best performance (native disk access)
  • Simple format for direct hardware passthrough
  • Easily mountable for forensic analysis

Cons:

  • No snapshot support
  • Fixed allocation (sparse files possible but less efficient)
  • Difficult to resize while VM is running

Advanced features:

  • Copy-on-write for snapshots
  • Dynamic allocation
  • Compression and encryption

# Creating a qcow2 image with compression
qemu-img create -f qcow2 -o compression_type=zstd vm_disk.qcow2 20G

# Converting raw to qcow2
qemu-img convert -f raw -O qcow2 vm_disk.raw vm_disk.qcow2

Performance considerations:

  • ~5-10% overhead compared to raw
  • SSD caching improves performance significantly
  • Best for development environments needing snapshots

Enterprise-grade solution:

  • Direct block device access
  • Thin provisioning support
  • Advanced volume management

# Creating an LVM volume for KVM
lvcreate -L 20G -n vm_disk vg_kvm

# Using thin provisioning
lvcreate -V 50G -T vg_kvm/thin_pool -n vm_thin_disk

Migration strategy:


# Live migration example using LVM
virsh dumpxml vm1 > vm1.xml
lvcreate --snapshot --name vm1_snap --size 1G vg_kvm/vm_disk
dd if=/dev/vg_kvm/vm1_snap | ssh newhost "dd of=/dev/vg_kvm/vm_disk"
Feature Raw QCOW2 LVM
Performance ★★★★★ ★★★☆☆ ★★★★☆
Snapshot Support No Yes Yes (LVM snapshots)
Live Expansion Difficult Easy Easy (with thin provisioning)
Backup Efficiency Low (full copy) Medium (incremental possible) High (block-level)

For production databases: Use raw or LVM for maximum performance. Example MySQL setup:



  
  
  

For developer workstations: QCOW2 provides the best balance. Enable compression: