HDD Passthrough in Proxmox

Recently installed a 2x 2.5″ HDD hot swap rack into my server. I got it for christmas, but didn’t want to bring everything down to do so. But recently we’ve been removing tile and carpet, and generating a lot of dust in the house.

There were tornados in town last night, so non-essential services got shut down, the dust needed to be blown out, and this was a perfect opportunity to use my new[ish] toy.

The problem:

I used to use a USB to SATA adapter, and had a 2.5in HDD sitting externally on the server case. Not a great solution. But it was easy to pass through that single USB device to my ZoneMinder VM for the bulk storage. P.S. don’t use the same HDDs for storing photos/videos/important documents and then get tons of R/W cycles by using them as a video recorder. Separate those functions onto different disks.

Nowadays, my NVR hard drive is directly connected with a SATA cable, and Proxmox doesn’t have a convenient way in the GUI to pass through a single device.

The solution:

This is relatively easy, we’re just going to use a QM command to pass that disk into the VM directly. And for me it’s the same UUID, so it should mount well with my current fstab settings.

First we have to make sure we have the right disk. I’m going to install lshw, which is not included in Proxmox by default. But this step is optional. Then we’re going to identify all of our disks and make sure we have UUID, device number, etc. This will all be in the host OS (proxmox) shell, not the terminal/console for the VM ultimately getting the disk.

# install lshw

# lshw -class disk -class storage

(...)    
      *-disk:4
          description: ATA Disk
          product: SAMSUNG HM250HI
          physical id: 0.0.0
          bus info: scsi@8:0.0.0
          logical name: /dev/sde
          version: 01C4
          serial: S1YQJDNS810914
          size: 232GiB (250GB)
          capabilities: gpt-1.00 partitioned partitioned:gpt
          configuration: ansiversion=5 guid=a183ccd0-1b9d-4dac-af8c-cecdcd468b3a logicalsectorsize=512 sectorsize=512

This is what I’m after. Device at /dev/sde, the mount name is already indicating I was using it for zoneminder. Or you can use other tools like lsblk.

# lsblk

(...)
sdb                            8:16   0   7.3T  0 disk 
├─sdb1                         8:17   0   7.3T  0 part 
└─sdb9                         8:25   0     8M  0 part 
sdc                            8:32   0   7.3T  0 disk 
├─sdc1                         8:33   0   7.3T  0 part 
└─sdc9                         8:41   0     8M  0 part 
sdd                            8:48   0 698.6G  0 disk 
└─sdd1                         8:49   0 698.6G  0 part /mnt/pve/backups
sde                            8:64   0 232.9G  0 disk 
└─sde1                         8:65   0 232.9G  0 part /mnt/pve/zoneminder

Ultimately I want the location in /dev/disks/by-id/. We can do this with the following command.

# find /dev/disk/by-id/ -type l|xargs -I{} ls -l {}|grep -v -E '[0-9]$' |sort -k11|cut -d' ' -f9,10,11,12

(...)
11:30 /dev/disk/by-id/ata-ST8000DM004-2U9188_ZR14PZYE -> ../../sdb
11:30 /dev/disk/by-id/wwn-0x5000c500e6d0e126 -> ../../sdb
11:30 /dev/disk/by-id/ata-ST8000DM004-2CX188_ZR10329Q -> ../../sdc
11:30 /dev/disk/by-id/wwn-0x5000c500c8756425 -> ../../sdc
11:30 /dev/disk/by-id/ata-WDC_WD7500AACS-00D6B1_WD-WCAU47088958 -> ../../sdd
11:30 /dev/disk/by-id/wwn-0x50014ee2ad2b2d49 -> ../../sdd
19:46 /dev/disk/by-id/ata-SAMSUNG_HM250HI_S1YQJDNS810914 -> ../../sde
19:46 /dev/disk/by-id/wwn-0x50024e9001ee98c2 -> ../../sde

Then we have what we need to add that UUID to a specific VM. In my case I’m adding it as a scsi device (check your hardware tab first if you already have something named scsi2 in that VM and need to name it something else) to VM 100, so modify your command to match your VM number.

# qm set 100 -scsi2 /dev/disk/by-id/wwn-0x50024e9001ee98c2

In my case I didn’t even need to reboot the VM, it showed up immediately. Your mileage may vary. If needed, go into the console for your VM and modify your /etc/fstab file to mount the new device where you need it. Best practice is to mount by unique identifier, so if you used the same physical disk like I did, it should mount just fine on boot.

Final thoughts:

This was short, and is well documented elsewhere. I just know I’m going to have to do this again sometime (when I destroy this HDD and need to swap in one that isn’t burned up).

You can also quickly disconnect the drive with the “qm unlink” command. In my case

# qm unlink 100 -idlist scsi2

Or remove it entirely after a hardware change with

# update VM 100: -delete scsi2

Posted

in

by

Comments

Leave a Reply

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