Storage setup for virtual machines

There are several storage solutions for a KVM/QEMU virtual machine.

Use a raw image container file

This is pretty easy to accomplish with a reasonable performance results.
In order to use the maximum amount of an 120GB SSD. I created a raw image file (.img) on it, via:
fallocate -l 111G /media/vm/win10.img

Add the image container as a storage device in virt-manager. I use

  • Source path: /media/vm/win10.img
  • Device Type: SATA Disk
  • Disk bus: VirtIO

In order to access the storage space within Windows, for example during the OS installation, use the VirtIO windows drivers (viostor\w10\amd64\viostor.inf).

Pass an entire storage device to a virtual machine

In case you want to pass through a storage device as a whole, instead of using an image container file. You have to identify the correct drive first.

Use
ls -l /dev/disk/by-id and lsblk to get the drive information.

Edit your virtual machines’ config via virsh edit <vm-name> and add the following block:

<disk type='block' device='disk'>
   <driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
   <source dev='/dev/nvme0n1'/>
   <target dev='sdb' bus='sata'/>
   <boot order='1'/>
   <address type='drive' controller='0' bus='0' target='0' unit='1'/>
 </disk>

Into the <devices> section (one line after </emulator> should be fitting).

Where <source dev='/dev/nvme0n1'/> should match your device or partition name.

When you run in problems on an Ubuntu system, these might be caused by Apparmor.

Edit the /etc/apparmor.d/abstractions/libvirt-qemu file and add your passed through device like this:

/dev/nvme0n1 rw,

save and exit and run

service apparmor restart

Afterwards.

Pass an entire SATA controller to a virtual machine

This is only possible if you have a convenient IOMMU group for the use case.
Proceed as one would do with regular PCI-Passthrough.

Sources:

heiko-sieger.info: Really comprehensive guide (see part 8)

https://level1techs.com/article/ryzen-gpu-passthrough-setup-guide-fedora-26-windows-gaming-linux

Is this content any helpful? Then please consider supporting me.

If you appreciate the content I create, this is your chance to give something back and earn some good old karma.

Although ads are fun to play with, and very important for content creators, I felt a strong hypocrisy in putting ads on my website. Even though, I always try to minimize the data collecting part to a minimum.

Thus, please consider supporting this website directly 😘

4 comments on “Storage setup for virtual machines”

  1. AMD Ryzen based passthrough setup between (X)Ubuntu 16.04 and Windows 10 - www.MathiasHueber.com

    […] this guide I use a raw image container, see the storage post for further […]

    Reply
  2. Kees

    pass entire device to VM

    in case a complete harddrive is passed to the VM, find out the correct device-id.
    use
    ls -l /dev/disk/by-id

    lsblk
    to get the id by with the mount points

    add

    Where should I add? What file?

    Reply
  3. Little

    sorry for maybe the dump question but what does this means?:

    In your example you used the /dev/nvme0n1. In my case I want to use nvme1n1, would this line still be the same.

    sorry for the poor choice of my word. I’m not a native speaker :_/

    Reply
    1. Little

      oh! missed it! Of course thank you for your awesome guide!!! Really neat work!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *