Passthrough Physical Disk or USB to VM on Proxmox VE

PowerADM.com / Virtualization / Proxmox / Passthrough Physical Disk or USB to VM on Proxmox VE

In this article, we will look at how to pass through a physical hard disk (HDD/SSD) or USB storage to a virtual machine running on Proxmox VE.

How to Passthrough Physical Disks (HDD/SSD) to a Proxmox Virtual Machine?

The Proxmox VE web interface allows you can add only USB disks or flash drives to the virtual machine. To pass a physical hard disk (passthrough mode) to a Proxmox virtual machine, you must use the hypervisor shell. The qm set command is used to do this.

Command syntax:

qm set <vm_id> -[virtio|sata|ide|scsi][№] /dev/sd[a|b|c|...]
  • vm_id – Virtual machine ID (in the Proxmox WebGUI GUI it is specified before the virtual machine name)
  • [virtio|sata|ide|scsi][№] – virtual disk controller type and interface number
  • /dev/sd[a|b|c...] – a physical device to passthrough

List the physical disks on the hypervisor:

# lsblk

For example, you want to add the /dev/sdb1 disk partition to the VM. It is possible to use the device address to passthrough the disk to the VM, but this is not recommended. The fact is that the disk path can change when adding, disconnecting, or rearranging disks. Therefore, it is better to use its UUID  or serial disk number (ID) to pass through a disk.

To get the UUID:

# blkid /dev/sdb1

blkid get disk UUID on LInux

If the disk does not appear, you will need to partition and format it first.

Check if the disk is displayed in the /by-uuid directory:

# ls /dev/disk/by-uuid/

If you do not see your UUID in the output of the command, you will need to use the disk ID or the path to it (/dev/sdb1).

You can get the disk serial number with the command:

# lshw -class disk -class storage

Copy serial value. For example, Serial: D221KDV1Z

Display the identifiers of the hard disk and the partitions on it by their serial number:

# ls -l /dev/disk/by-id | grep D221KDV1Z

For example, the command gave me this disk ID: ata-WDCxxxxxx-xxxxxx_D221KDV1Z

Open the Proxmox web interface and remember the ID of the virtual machine you want to connect the physical disk to (119 in my example).

proxmox VM ID

To pass through the disk to this VM by UUID, run the command:

# qm set 119 -virtio2 /dev/disk/by-id/0b56138b-6124-4ec4-a7a3-7c503516a65c

To add a physical disk/partition by ID and serial number:

# qm set 119 -virtio2 /dev/disk/by-id/ata-WDCxxxxxx-xxxxxx_D221KDV1Z

Or you can specify the disk path (not recommended)::

# qm set 119 -virtio2 /dev/sdb1

Check that your disk has been added to the VM configuration file:

# cat /etc/pve/qemu-server/119.conf

Something like this should appear in the configuration file:

virtio0: volume=/dev/sdb1

or

sata0: volume=/dev/sdb1

Check that the new drive appears in the VM Hardware tab of the Proxmox interface.

HDD Passthrough to a Proxmox VM

After the hypervisor is restarted, the mapped disk will remain mounted in the VM.

If you have a Windows guest operating system installed in the Proxmox VM, it may not be able to recognize the new drive. In order for Windows to detect the physical disk drive on the virtio controller, you need to install the VirtIO driver according to this guide.

If you want to passthrough a disk from a RAID controller, you must use the -virtio(x) format, not a -scsi(x).

To disconnect the hard disk from the Proxmox virtual machine, run the following command

# qm unlink 119 --idlist virtio2

Adding USB Drive to Proxmox VM

You can add any USB device from the host to the Proxmox virtual machine directly from the PVE web console.

  1. Open the Proxmox VE web interface;
  2. Locate the virtual machine you need and go to the Hardware tab;
  3. Select Add -> USB Device;proxmox: add usb drive to virtual machine
  4. Select the USB device that you want to passthrough from the list. You can use one of two modes:
    Use USB Vendor/Device ID – If you need to pass a USB device through to the VM, regardless of which USB port it is connected to.
    Use USB Port – full physical USB port redirection, where any device connected to the specified USB port is passed to the VM.
    In our example, this is Mass Storage Device. Enable the Use USB3 option if required.passthrough usb storage to proxmox
  5. A line appears in the VM configuration with information about the connected USB stick;
  6. Reboot the VM and check that the new USB drive is recognized by the guest OS.

You can also passthrough the USB drive to the VM from the shell. First, check how your USB device is recognized by the host OS:

# lsusb

If it’s a USB drive, view information about its partitions and file system:

# fdisk -l

To pass a USB drive to a Proxmox virtual machine, specify its number and the USB device ID that you get using the lsusb command. For example

# qm set 119 -usb0 host=0bba:b020

If it’s a USB 3.0 device, use the command:

# qm set 119 -usb0 host=0bba:b020,usb3=yes

To disconnect the USB drive from the virtual machine:

  1. Make sure that the device is not being used in your guest operating system (when you unmount the device, the error message “Unmount device is busy” should not appear)
  2. From the Proxmox console, remove the USB device from the guest VM:
    # device_del <idofyourdevice>
  3. Remove the USB drive from the VM configuration in the Proxmox web interface or run the command:
    # qm set VMID -delete usb0
4 thoughts on “Passthrough Physical Disk or USB to VM on Proxmox VE”
  1. Great post! There is a small typo in one of the commands:

    # qm set 119 -virtio2 /dev/disk/by-id/0b56138b-6124-4ec4-a7a3-7c503516a65c

    should be

    # qm set 119 -virtio2 /dev/disk/by-uuid/0b56138b-6124-4ec4-a7a3-7c503516a65c

    Thanks again for all your hard work!

Leave a Reply

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