Using Physical Disk in KVM/QEMU Windows VM


  1. Posts : 11,247
    Windows / Linux : Arch Linux
       #1

    Using Physical Disk in KVM/QEMU Windows VM


    Hi there
    If you have a spare external (or even internal) HDD / SSD that you want to use as a "Physical" Disk drive say on a Windows VM using native ntfs for exampleso you can unplug it later and connect to a Windows physical machine etc to copy data etc then it's easy enough to do.

    1) ensure the disk is not mounted on the Host

    2) edit the Windows xml definition file in the libvirt/qemu directory (virsh edit or whatever you use to edit xml files)
    and add the disk definition. File is in /etc/libvirt/qemu and the name is the name of your Windows VM.
    </disk>
    <disk type="block" device="disk">
    <driver name="qemu" type="raw"/>
    <source dev="/dev/sdg"/> <======= whatever the device is on your system -- lsblk will show devices
    <target dev="vda" bus="virtio"/> (for 2nd virtio device then replace vda by vdb etc )
    # <address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/> this line is generated when the VM is booted so you don't enter this one
    </disk>

    3) if device hasn't been partitioned or whatever in windows then use in the Windows VMwindows as admin diskpart -> list disk ->select disk nn ->clean ->convert gpt ->create partition primary ->format fs=ntfs quick ->list vol ->selct vol xx ->assign

    then exit

    Now it's available as native NTFS drive (the GPT step is optional but I prefer using gpt drives)

    on the Host you can see now the disk (after powering off the VM is indeed NTFS).

    You will need to dedicate a whole disk for this though as a partition isn't a block device.

    In this case the windows ntfs data is on /dev/sdg2 and it can be plugged in to any windows system.

    Using Physical Disk in KVM/QEMU Windows VM-screenshot_20210522_135401.png

    This is useful when you need to capture things like WIM image, take system backup , copy large bits of data from the VM - where a USB stick is not large enough etc etc and want to use it on other Windows physical machines - saves defining large virtual disks and the other Windows machines you want to use the data on might not be "network acessible".

    Cheers
    jimbo
      My Computer


  2. Posts : 1,325
    Windows 11 Pro 64-bit
       #2

    Thanks.
    Will try asap.
    Better than virtual disks when dealing with portable cases.
      My Computers


  3. Posts : 1,325
    Windows 11 Pro 64-bit
       #3

    Nice.
    Gets the job done very well.

    In case someone likes to try the graphical way, via virt-manager:
    Use 'Add New Virtual Hardware' to VM settings.

    'USB Host Device': will show all your external USB disks, for instance external USB - SATA or NVMe controllers will be displayed by name.
    For internal disks, use 'PCI Host Device': host SATA or NVMe controllers will be shown there, unless they are connected via USB as above.
    Using Physical Disk in KVM/QEMU Windows VM-image.png
      My Computers


  4. Posts : 11,247
    Windows / Linux : Arch Linux
    Thread Starter
       #4

    Hopachi said:
    Nice.
    Gets the job done very well.

    In case someone likes to try the graphical way, via virt-manager:
    Use 'Add New Virtual Hardware' to VM settings.

    'USB Host Device': will show all your external USB disks, for instance external USB - SATA or NVMe controllers will be displayed by name.
    For internal disks, use 'PCI Host Device': host SATA or NVMe controllers will be shown there, unless they are connected via USB as above.
    Using Physical Disk in KVM/QEMU Windows VM-image.png
    Hi there
    This may fail though on some systems if you use a SATA->USB adapter for attaching the device - usually external SSD's -- the best way in this case is to attach the SSD as a device on the HOST and then add it as a RAW physical device in the VM config.

    I have a few spare SSD's which I often connect via USB->SATA coadapters -- if you try directly the VM will (at least on my hardware) throw up on the GUEST : USB re-direction error -- so the get around is to do it via the HOST indirectly. Stanadrd USB external drives work just OK.

    Cheers
    jimbo
      My Computer


  5. Posts : 1,325
    Windows 11 Pro 64-bit
       #5

    jimbo45 said:
    I often connect via USB->SATA coadapters -- if you try directly the VM will (at least on my hardware) throw up on the GUEST : USB re-direction error -- so the get around is to do it via the HOST indirectly. Stanadrd USB external drives work just OK.
    Good to keep in mind.
    Interesting to see what kind of coadapters those are. I haven't tested many hardware but I have seen a few fails, especially with USB redirection menu in VM window.

    This one works perfectly, in my case, on Intel and AMD, via add USB Host Device:
    USB 3.1 Gen1 (USB 3.0) Screwless 2.5 inch SATA HDD/SSD enclosure | Ewent

    I have a couple of these around with HDD's inside.

    They fail via USB Redirection menu since the XML points to a 0000 device. Here it expects a USB flash stick, not a SATA controller so it seems.

    But I can add them flawlessly via add USB Host Device settings.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:07.
Find Us




Windows 10 Forums