Proxmox: How To Share Disks With a VM
While setting up a new Virtual Machine (VM) for TrueNAS, I wanted to passthrough existing SATA drives with serial numbers from Proxmox. I am sharing this as I wasn’t able to find simple instructions on how to do this online.
Notes:
- These instructions are for QEMU/KVM VMs, and not containers
- It assumes you have already created a VM, and know its ID (i.e., 100)
- All commands presented below are to be ran inside the Proxmox server’s shell as root, unless otherwise noted
Gather Information
Before we can share the drive with the VM, we must first document the following variables:
- VM ID: Proxmox’s Virtual Machine ID (I’m using
100
in this example) - SCSI ID: Proxmox’s SCSI ID for the drive (I’m using
scsi2
in this example) - Disk ID: The physical drive’s identifier
- Serial Number: The physical drive’s serial number
SCSI ID
To determine which SCSI ID to use:
- Open Proxmox’s web interface
- View the Hardware screen for the VM you intend to add the disk to
- Find the Hard Disk instance with the highest SCSI ID (i.e., scsi1)
- Incremement that number by one
Example: If “scsi1” is the SCSI ID for the Hard Disk with the highest instance, then use “scsi2” for the new disk
Disk ID
Finding the drive’s ID requires multiple steps. First, run the following command to determine the disk’s name:
$ lsblk
In my case, the following output was received:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 7.3T 0 disk
sdc 8:32 0 223.6G 0 disk
├─sdc1 8:33 0 1007K 0 part
├─sdc2 8:34 0 512M 0 part /boot/efi
└─sdc3 8:35 0 223.1G 0 part
├─pve-swap 253:0 0 8G 0 lvm [SWAP]
├─pve-root 253:1 0 55.8G 0 lvm /
├─pve-data_tmeta 253:2 0 1.4G 0 lvm
│ └─pve-data-tpool 253:4 0 140.5G 0 lvm
│ ├─pve-data 253:5 0 140.5G 1 lvm
└─pve-data_tdata 253:3 0 140.5G 0 lvm
└─pve-data-tpool 253:4 0 140.5G 0 lvm
├─pve-data 253:5 0 140.5G 1 lvm
I am interested in passing through the new 7.3TiB drive, so the disk name I am interested in is sdb
(highlight added).
Next, run the following command (replacing sbc
with the appropriate disk name):
$ ls -l /dev/disk/by-id/ | grep "sdb" | grep -v "wwn-"
The output from the call on my machine reads:
lrwxrwxrwx 1 root root 9 Aug 14 16:26 ata-WDC_WD80EAZZ-00BKLB0_WD-AB1CDEFG -> ../../sdb
This leaves us with:
- Disk ID:
ata-WDC_WD80EAZZ-00BKLB0_WD-AB1CDEFG
Serial Number
To get the drive’s serial number, run the following command from inside the Proxmox shell, changing sdb
in the command below to the name of the drive you are interested in:
$ hdparm -i /dev/sdb
The output from the call on my machine reads:
/dev/sdb:
Model=WDC WD80EAZZ-00BKLB0, FwRev=80.00A80, SerialNo=WD-AB1CDEFG
Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=16
(maybe): CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=15628053168
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
AdvancedPM=no WriteCache=enabled
Drive conforms to: unknown: ATA/ATAPI-1,2,3,4,5,6,7
* signifies the current active mode
The serial number (circled in the output above) appears at the end of the line that begins with Model=
. This leaves us with:
- Serial Number:
WD-AB1CDEFG
Add the Disk
Now it’s time to add the disk to the VM.
Plug your variables into the following command and run it:
$ qm set VM ID -scsiSCSCI ID /dev/disk/by-id/Disk ID,serial=Serial Number
Based on the variable values I collected above, my version of the command looks like:
$ qm set 100 -scsi2 /dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-AB1CDEFG,serial=WD-AB1CDEFG
Validate
To validate that the new disk has been added to the configuration file, run the following command (plugging in your variables):
$ grep scsiSCSI ID /etc/pve/qemu-server/VM ID.conf
My version of the command looks like:
$ grep scsi2 /etc/pve/qemu-server/100.conf
If all went well, you should see something similar to the following:
scsi2: /dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-AB1CDEFG,serial=WD-AB1CDEFG,size=7814026584K
Restart the VM
All that’s left is to restart the VM.