Jump to content
reluctantflux

Hard drive passthrough

21 posts in this topic Last Reply

Recommended Posts

I'm having trouble finding any documentation on hard drive passthrough.  Is this possible?  I have an SSD that I would like to give direct passthrough to a VM with a GPU passthrough for optimal gaming performance.  I'd rather not have it be an image on an SSD with a bunch of other processes running on it.  Thanks!

Share this post


Link to post

I believe you would need to passthrough the entire controller that it is attached to.  I'm not sure if KVM has raw device mapping like ESXi.

 

John

Share this post


Link to post

I just setup an SSD to be mounted outside the array, using SNAP.  I moved my windows8 VM to that drive, then started it, then ran the Windows Experience Index on the VM, and it recognized the drive as an SSD, and scored pretty well.  The VM is running very fast.

 

I tested it by playing a bluray to the TV, streaming another one to my phone from the VM, streaming another one to my laptop from the VM, downloaded an album with SABnzbd, and started a parity check.  All videos played without skipping, or any issues at all.  I've not seen it work that well ever before.

 

I wonder if this would do what you need, without having to passthru the hard drive.  This lets you still access it from unRAID, FWIW.

 

 

Share this post


Link to post

This is kind of easy.  So my old bootable Windows SSD was attached to my VM by adding the following:

 

<disk type='block' device='disk'>
        <source dev='/dev/disk/by-id/ata-Corsair_CSSD-F120GB2_1109650632000461003B' />
        <target dev='hdc' bus='virtio' />
</disk>

 

I set the /dev/disk/by-id/.... so that upon reboot, if my Corsair SSD ended up a different sdX, it would still work.

 

I was able to boot the vm, and it tried to load windows, but then went into a bsod boot loop.  This was to be expected, so I deleted the partitions on the disk using fdisk.  Now, though, when I boot, it tries to boot from that drive, and then fails. For some reason, it doesn't see my .iso boot image.  If I remove the hard drive from the xml, then the vm boots into the iso install.  I'm not sure why it is not seeing my iso as a bootable device.  Both are /dev/hdx devices in my xml.

 

All my disk devices:

 

   <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/cache/iso/Win81Pro.iso'/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/cache/iso/virtio-win-0.1-81.iso'/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='1'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/disk/by-id/ata-Corsair_CSSD-F120GB2_1109650632000461003B'/>
      <target dev='hdc' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk> 

 

Thoughts on how to get it to boot to my Win81.iso while still having my ssd attached?

Share this post


Link to post
  <os>

    <type arch='x86_64' machine='pc-q35-2.1'>hvm</type>

    <boot dev='cdrom'/>

    <bootmenu enable='no'/>

  </os>

 

:D

Share this post


Link to post

Success!  I couldn't just change the boot device, I ended up having to have both <boot dev='cdrom'/> and <boot dev='hd'/> along with <bootmenu enable='yes timeout='3000'/>

 

I've just now installed Windows 8.1 in about 2 1/2 minutes.  This is so crazy and awesome! 

 

<domain type='kvm' id='30'>

  <name>Gaming</name>

  <uuid>331e68d5-820c-660a-cb4e-d7470ec818d8</uuid>

  <memory unit='KiB'>2621440</memory>

  <currentMemory unit='KiB'>2621440</currentMemory>

  <vcpu placement='static'>1</vcpu>

  <resource>

    <partition>/machine</partition>

  </resource>

  <os>

    <type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>

    <boot dev='cdrom'/>

    <boot dev='hd'/>

    <bootmenu enable='yes' timeout='3000'/>

.......

  <devices>

    <emulator>/usr/bin/qemu-system-x86_64</emulator>

    <disk type='file' device='cdrom'>

      <driver name='qemu' type='raw'/>

      <source file='/mnt/cache/iso/virtio-win-0.1-81.iso'/>

      <backingStore/>

      <target dev='hdd' bus='ide'/>

      <readonly/>

      <alias name='ide0-1-1'/>

      <address type='drive' controller='0' bus='1' target='0' unit='1'/>

    </disk>

    <disk type='file' device='cdrom'>

      <driver name='qemu' type='raw'/>

      <source file='/mnt/cache/iso/Win81Pro.iso'/>

      <backingStore/>

      <target dev='hde' bus='ide'/>

      <readonly/>

      <alias name='ide0-1-0'/>

      <address type='drive' controller='0' bus='1' target='0' unit='0'/>

    </disk>

    <disk type='block' device='disk'>

      <driver name='qemu' type='raw'/>

      <source dev='/dev/disk/by-id/ata-Corsair_CSSD-F120GB2_1109650632000461003B'/>

      <backingStore/>

      <target dev='hdc' bus='virtio'/>

      <alias name='virtio-disk2'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

    </disk>

 

.........

 

The <disk> stuff in red is what I added to the xml.  VMmanager added the rest.  So I added:

 

<disk type='block' device='disk'>
      <source dev='/dev/disk/by-id/ata-Corsair_CSSD-F120GB2_1109650632000461003B' />
      <target dev='hdc' bus='virtio' />
</disk>

 

Along with adding the following to the <os> tag:

    <boot dev='cdrom'/>
    <bootmenu enable='yes' timeout='3000'/>'

Share this post


Link to post

Nice!

 

What does this do:

 

 <bootmenu enable='yes' timeout='3000'/>'

 

Display the boot menu where you can select a boot device?

Share this post


Link to post

Yeah, it'll display a boot menu for 3 seconds.  For some reason, if I didn't have that, you don't have a chance to "hit any key to boot from DVD/CDRom", and it just moves on and stops at the no OS on Hard Disk spot.

Share this post


Link to post

Once I completed the install, I removed the Win81.iso from my xml, along with the <bootmenu> and <cdrom> entries from the <os> tag, and it booted up fine.

 

I was curious if there was a performance difference if I set the SSD <disk> as a sata device instead of virtio.  Oddly enough, I was able to boot with it set to Sata, but was then not able to go back to Virtio.  I don't know if there will be a performance increase or decrease like this, but I'm going to leave it unless I notice significant issues.

Share this post


Link to post

Upon quick research, having it set as Virtio instead of IDE supposedly significantly decreases CPU usage. Not sure if this is the same for hard drive passthrough or if it is set to SATA, but I figured it was a fresh image and just reinstalled to make sure it was using Virtio.

Share this post


Link to post

 

 

Upon quick research, having it set as Virtio instead of IDE supposedly significantly decreases CPU usage. Not sure if this is the same for hard drive passthrough or if it is set to SATA, but I figured it was a fresh image and just reinstalled to make sure it was using Virtio.

 

I found that if a cdrom was set to sata and not ide then you can't do snapshots.  Some ich9 error.

Share this post


Link to post

Virtio is what you want. Using sata or ide and you are emulating controller hardware as opposed to using a "virtualization aware" driver stack.

 

Share this post


Link to post

Jonp.  Thanks for the info!  Do you know if there's a way to set it back to Virtio from Sata?  My HTPC is a raw qcow2 image on Sata bus.

 

I've read that you can install the virtio drivers, shutdown the vm, change the bus, and then boot back up and it'll be fine, but I'd like a second opinion before I started messing with it.

Share this post


Link to post

Jonp.  Thanks for the info!  Do you know if there's a way to set it back to Virtio from Sata?  My HTPC is a raw qcow2 image on Sata bus.

 

I've read that you can install the virtio drivers, shutdown the vm, change the bus, and then boot back up and it'll be fine, but I'd like a second opinion before I started messing with it.

Yeah, there is a way to do it like that but I haven't had to do that before, so I'd be guessing if I gave you instructions ;-).

Share this post


Link to post

So I have two questions about this topic.

 

1.  Can I passthrough a unassigned SSD for a VM?

2.  Can I make a separate pool of just SSD that is NOT in the cache?  I would ideally have a separate pool for just VM's.  Not sure if that is possible as of now.

Share this post


Link to post

So I have two questions about this topic.

 

1.  Can I passthrough a unassigned SSD for a VM?

2.  Can I make a separate pool of just SSD that is NOT in the cache?  I would ideally have a separate pool for just VM's.  Not sure if that is possible as of now.

 

1. Yes, use the method above. I have just done it for a 1Tb WD Black drive, works like a charm.

2. I am not sure this is possible, i guess if you motherboard has a raid controller you could create the array and you will end up with a single volume.

Share this post


Link to post

Can you pass through the same HDD to two VMs?

I think it wouldn't be considered a "pass through" if 2 VM uses it at the same time. ;)

 

You can, however, share it among 2 VM, just by the normal sharing method.

Share this post


Link to post

Wasn't sure if this was a genuine pass-through since your just passing the disk through and not the controller

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now