![How to Emulate SSD in KVM Virtual Machines](/content/images/size/w2000/2025/01/Lora_simple_SSD___Storage_image_but_with_epic_aura_d6884475-8b38-441c-995a-727e1536e269_waifu2x_art_noise1_scale.png)
When working with KVM virtual machines to test setups like Ceph or OpenStack Clusters, it can be useful to have SSD storage available. Instead of using actual physical drives, you can emulate these storage types to achieve the same functionality for your testing purposes.
Emulate SSD Drives
SSD drives require a slightly different setup. To emulate an SSD, add a drive to your KVM guest as usual, specifying the desired bus (e.g., SCSI or SATA). Then, use the appropriate command to set the rotational speed to indicate it’s an SSD. Note that in QEMU, you set this value to 1
, which translates to 0
in Linux (indicating a non-rotational drive).
To do this, you’ll need to know the exact device name, which depends on the number and type of drives you’ve added. Typically, the naming follows a pattern like scsi0-0-0-0
for the first SCSI drive on the first SCSI controller or sata0-0-0
for SATA drives. However, it’s always a good idea to verify the exact name.
- Create Disk
qemu-img create -f qcow2 /var/disks3/vms/raja-lab-sda.qcow2 20G -o preallocation=full
- Attach Disk with SCSI targetbus
virsh attach-disk raja-lab \
--source /var/disks3/vms/raja-lab-sda.qcow2 \
--target sda \
--driver qemu \
--subdriver qcow2 \
--targetbus scsi \
--persistent \
--config \
--live
- You can confirm the device name by querying the guest using the
virsh qemu-monitor-command
tool, as shown below. Note the givenid
virsh qemu-monitor-command raja-lab --hmp "info qtree" | grep scsi
---
dev: virtio-scsi-pci, id "scsi0"
dev: virtio-scsi-device, id ""
bus: scsi0.0
dev: scsi-hd, id "scsi0-0-0-0"
device_id = "drive-scsi0-0-0-0"
scsi_version = 5 (0x5)
scsi-id = 0 (0x0)
- Shutdown & Edit VM
virsh shutdown raja-lab
virsh edit raja-lab
<domain type="kvm" xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
...
<qemu:override>
<qemu:device alias='scsi0-0-0-0'>
<qemu:frontend>
<qemu:property name='rotation_rate' type='unsigned' value='1'/>
</qemu:frontend>
</qemu:device>
</qemu:override>
</domain>
- Start VM
virsh start raja-lab
Confirming drive is an SSD
You can confirm the rotational speed with lsblk
, like so.
sudo lsblk -d -o name,rota
This will return either 0 (for rotational speed false, meaning SSD) or 1 (for rotating drives, meaning non-SSD). For example, here’s a bunch of drives on a KVM guest where you can see /dev/sda
are SSD.
![](https://rjhaikal.my.id/content/images/2025/01/image.png)
You can also check with smartctl
, which will report the rotational rate as an SSD. Here’s an example on /dev/sda
which is set to be an SSD in KVM guest.
smartctl -i /dev/sda
This shows a result like this, note Rotational Rate
is Solid State Device
.
![](https://rjhaikal.my.id/content/images/2025/01/image-2.png)