How to Configure Virtual Storage as SSD in KVM/QEMU for Optimal Guest OS Performance


5 views

When migrating from VirtualBox to KVM (QEMU/libvirt), many users notice the missing "Solid-state Drive" checkbox that was present in VirtualBox's storage configuration. This setting plays a crucial role in guest OS behavior, particularly for Windows VMs where it automatically disables disk defragmentation for SSD devices.

Unlike VirtualBox's explicit GUI option, KVM/QEMU handles storage media type identification through different mechanisms. The virtualization stack provides several ways to achieve similar functionality:


# Sample libvirt XML configuration for SSD emulation

  
  
  
  

To properly emulate SSD characteristics in KVM, focus on these critical parameters:

  • discard='unmap': Enables TRIM support (crucial for SSD performance)
  • cache='none': Bypasses host caching for more accurate SSD behavior
  • io='native': Uses optimal I/O paths for virtual SSDs
  • blockio settings: Configure appropriate sector sizes

For more advanced control, use virtio-scsi with explicit rotation rate setting:




  
  
  
  
1

After configuration, verify the guest OS properly recognizes the storage as SSD:

Windows: Check in Device Manager under disk properties or run:

powershell -command "Get-PhysicalDisk | Select-Object FriendlyName, MediaType"

Linux: Use the following command:

lsblk -d -o name,rota

(Where '0' in the rota column indicates SSD)

For optimal SSD-like performance in KVM guests:

  • Enable discard/unmap in both host and guest
  • Consider using raw format instead of qcow2 for better performance
  • Align partitions properly (usually 1MB alignment for modern SSDs)
  • Disable swap partitions or use swap files with proper SSD settings

When migrating from VirtualBox to KVM/QEMU, one notable difference is how storage devices are presented to guest systems. While VirtualBox provides a straightforward checkbox to mark virtual disks as SSDs, KVM requires more explicit configuration.

The most reliable way to make a guest OS recognize your virtual disk as SSD is through the libvirt domain XML configuration:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none' io='native'/>
  <source file='/path/to/disk.qcow2'/>
  <target dev='vda' bus='virtio'/>
  <blockio logical_block_size='512' physical_block_size='4096'/>
  <iotune>
    <ssd>1</ssd>
  </iotune>
</disk>

The key elements here are the <blockio> settings and the <ssd> flag in <iotune> which signal SSD characteristics.

If you're launching VMs directly via QEMU command line, use these parameters:

qemu-system-x86_64 \
  -drive file=disk.qcow2,if=virtio,cache=none,discard=unmap,format=qcow2 \
  -device virtio-blk-pci,drive=disk0,scsi=off,config-wce=off,serial=SSD123 \
  -global virtio-blk-device.rotation_rate=1

The rotation_rate=1 parameter specifically indicates a non-rotational (SSD) device to the guest OS.

After applying these changes, verify the guest OS correctly identifies the disk as SSD:

Linux Guests:

$ lsblk -d -o name,rota
NAME    ROTA
vda        0

Windows Guests:

PS C:\> Get-PhysicalDisk | Select-Object FriendlyName, MediaType

FriendlyName    MediaType
------------    ---------
Virtual Disk    SSD

To further optimize SSD behavior in KVM guests:

<domain>
  ...
  <devices>
    <controller type='scsi' index='0' model='virtio-scsi'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap'/>
      <source file='/path/to/disk.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
  </devices>
</domain>

This configuration enables TRIM/discard support via the virtio-scsi controller, which is particularly important for SSD longevity and performance.

If your guest OS still doesn't recognize the disk as SSD:

  • Ensure you're using virtio or virtio-scsi bus (IDE emulation often prevents proper SSD detection)
  • Check that your QEMU version is 2.5+ for proper SSD flag support
  • For Windows guests, install the latest virtio drivers