I followed the instructions in this answer to a related question: Add physical disk to KVM virtual machine

The resulting code in the .xml file for the VM is the following:

<disk type='block' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source dev='/dev/disk/by-partuuid/d8b63353-34n6-6587-ac07-810dmf36d544'/>
  <target dev='vdb' bus='virtio'/>
  <boot order='2'/>
  <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>

Notice how I used /dev/disk/by-partuuid/d8b63353-34n6-6587-ac07-810dmf36d544 for the <source> element, instead of /dev/sda4.

What is bothering me is that my use case is to pass a partition to QEMU, instead of a disk. I installed Windows 10 on it, the Setup installer wouldn't recognize the storage so I had to load the viostor driver from the FedoraProject.

The Windows installation went fine, and the performance is amazing, but when the VM is turned off, the host system doesn't recognize the partition format.

I found it interesting that the Windows installer - with the viostor driver loaded - created the additional partitions normally required by Windows on a bare disk. In other words, it created partitions inside what's supposedly a partition. This shouldn't be possible, or so I thought.

/dev/sda4 is present in the host, but is not recognized as neither an NTFS filesystem (not expected, indeed), nor LVM, nor LDM (tested with ldmtool).

The VM is booting correctly in UEFI mode with the Q35 chipset.

Question: Is my procedure to add a partition to virt-manager correct, or should it only be done for disks - and not for partitions? Also, what partition type or format did I end up with?

  • Personally I use virtual disks rather then raw partitions for exactly the behavior you noticed. If you use a physical partition I advise you use LVM – Panther Jun 21 '17 at 2:25

The solution appears to be passing the whole block device, like /dev/sda or the equivalent from /dev/disk/by-id/, to the <source dev=''> setting.

This allows the Windows setup to see the existing partitions, including the root partition in the host.

There should not be any conflict, as long as:

  • you don't try to mount/modify a partition in the guest that is already mounted in the host; and

  • you don't mount/modify the partition currently in used by the guest from the host, while the VM is powered on.

Regarding the first point, it is of course necessary to unmount the ESP (EFI System Partition) from the host prior to launching the VM. I first wrote a script for that, and then came up with a better solution in the form of a QEMU automation hook. I'm making available at https://gitlab.com/ranolfi/rvirtesp.

What's cool about this is that you can also boot the virtualized OS natively, as in dual-booting, by selecting its new entry in the motherboard's boot menu.

I'm not exactly sure this is "supported". But been using it for almost a year now, without a problem.

  • 1
    It would be nice if KVM supported a configuration to make a particular partition read-write but make the rest of the physical disk read-only – John Moser May 13 '20 at 13:36

If you want to pass a partition as a raw device you can just put /dev/sdaX as a raw image filename it will use it.

However If you already a partition on it NTFS or EXT4 (whatever) and want to make it seen as a disk by virtual machine iSCSI is the way.

you first install open-iscsi and tgt

sudo apt-get install open-iscsi tgt

then you configure it

nano /etc/tgt/conf.d/iscsi.conf

put your partition name instead of sdb1 (target name will be different):

<target iqn.2019-11.example.com:lun1>
     # Provided device as an iSCSI target
     backing-store /dev/sdb1                             
    incominguser iscsi-user password
     outgoinguser iscsi-target secretpass

then restart the service

sudo systemctl restart tgt 

then check it

tgtadm --mode target --op show

open windows and use iscsi initiator to connect it. Windows will see it as an internal disk ,have fun with high speed block access.

if you add a NAT nic and set it virtio installing virtio redhat drivers it probably will be lightning fast. Do not forget to connect via 192.168.123.XXX Instead of your bridge LAN ip.

Notes: Be careful and first test with a test partition .... iqn must be a-z or 1-9 you can. Leave passwords and secretpass blank There is a standard for these they may not accept space or underscore ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.