Mounting nvm-e ssd to a virtual machine

Hello
I want to transform my current windows 10 install to a virtual machine, running under ubuntu.
The current windows 10 is running on a samsung 970 pro 512 gb nvme ssd. And I would like it to continue to do so.
I’ve seen various guides so setting up vm’s, where a physical ssd have been used for the VMs boot drive.
But will it also work for a nvm-e ssd, or should I get a 960 pro sata ssd instead, and transfer the windows install to that?
I can’t really find anything on it, but would using a nvm-e passtrhough to the vm require pci-e passtrough, or can i just select the ssd from within ubuntu?

I think that you can use a raw block device (/dev/nvme0n1 or whatever) rather than do anything exotic such as pci-e passthough; I’ve not done it myself but I did read up on it a few years ago. That way you would avoid any complication arising from it being nvme rather than sata.

I’d also consider using a conventional virtual disk cloned from the physical at least to begin with - there’s quite a few advantages (such as snapshots) that may be helpful. Not least is that you won’t be touching the existing Windows installation whilst you’re getting the virtual machine working.

You can certainly use the raw /dev/nvme0n1 device, but passthrough will give you far superior/native performance. To do so you need to blacklist the nvme kernel module and setup vfio-pci just like you would when passing through a VGA device.

Personally I wanted a hybrid setup as I needed more then the 1TB of data my nvme device could provide, so I setup a RAID0 mdadm array and raw bound /dev/mdXXX to the VM instead.

If you decide to use the raw device rather then passthrough make sure you configure Qemu to tell the guest that the device is a SSD, and to make use of discard (TRIM). To support TRIM you must use a SCSI device. Here is my configuration as an example:

-drive id=disk,file=/dev/disk/by-id/md-uuid-XXXXXXXX,format=raw,if=none,cache=none,aio=native,discard=unmap,detect-zeros=unmap,copy-on-read=on \
-device virtio-scsi-pci,id=scsi \
-device scsi-hd,drive=disk,bus=scsi.0,rotation_rate=1

discard=unmap means to pass the TRIM commands through to the block device.
detect-zeros=unmap converts block writes that are all zeros to TRIM commands.
rotation_rate=1 is how you tell Windows it has a SSD attached to prevent it from attempting to defragment the device.

2 Likes

thanks for the replies.
I ended up reconstructing the windows install in a virtual disk, so I could continue doing work :slight_smile: