How to tell which disk files a KVM guest is using?

Wow, I've just spent the morning on Google for an answer to this and basically nothing has come up (except maybe this but I'm not sure: http://blog.zugschlus.de/archives/882-Block-devices-in-KVM-guests.html)

Looks like I might have to shut the guest down and try mounting each disk in turn from a boot CD to determine which file is being used on which mount point on the guest, then re-name the files to make that clear.

Really??
 
Each disk shows up as a device in the guest and`lsblk` in the guest should give you an overview of which partitions are part of which device.
 
Perfect! SOLVED!

... I think. So if I see this:
Code:
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1   595M  0 rom
vda    253:0    0     2G  0 disk
└─vda1 253:1    0     2G  0 part /
vdb    253:16   0     2G  0 disk
└─vdb1 253:17   0     2G  0 part /var
vdc    253:32   0    20G  0 disk
└─vdc1 253:33   0  19.6G  0 part /var/mail
vdd    253:48   0    20G  0 disk
└─vdd1 253:49   0    20G  0 part /home/mail
vde    253:64   0     1G  0 disk
└─vde1 253:65   0  1023M  0 part [SWAP]
What part of that identifies the disk file on PVE? eg, "vm-101-disk-2.raw"
 
Last edited:
vdX are virtio-based devices (virtio0, virtio1, virtio2, ...) in your config. Normally the order should be the same for letters and numbers (although hotplugging, udev rules etc might influence the device names on linux, but by default it should at least be of the same order).
You can verify by looking at their /sys entries (but be careful, the numbering isn't necessarily following the same pattern).

Eg. I have a machine like this:

gui.png

lsblk shows:
Code:
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                         8:0    0  512G  0 disk /nfs
sdb                         8:16   0    1T  0 disk
├─ailvm-vm--3000--disk--1 253:0    0    8G  0 lvm
└─ailvm-vm--751--disk--1  253:1    0    4G  0 lvm
vda                       254:0    0   32G  0 disk
├─vda1                    254:1    0  256M  0 part /boot
└─vda2                    254:2    0 31.8G  0 part /
vdb                       254:16   0   32G  0 disk /data/brick1
vdc                       254:32   0   64G  0 disk

Unless I fiddled with device names I can assume 'sda' corresponds to scsi3, 'sdb' corresponds to scsi4, giving them the ZFS volumes "vm-2100-disk-3" and "vm-2100-disk-2". From that you can already see I've attached and removed devices a couple of times so the volume names are ordered the other way round for the SCSI devices.

Then there are the virtio devices: vda, vdb and vdc are virtio0, virtio1 and virtio2.
Now in /sys you can take another look, but the naming/numbering is different: virtio starts at 1, SCSI is even more complex, but you can see '2:0:3:0' and '2:0:4:0' there so the '3' and '4' are the important bits there.

Code:
# ls -l /sys/class/block/{sda,sdb,vda,vdb,vdc}
lrwxrwxrwx 1 root root 0 Mar  1 07:51 /sys/class/block/sda -> ../../devices/pci0000:00/0000:00:05.0/host2/target2:0:3/2:0:3:0/block/sda
lrwxrwxrwx 1 root root 0 Mar  1 07:51 /sys/class/block/sdb -> ../../devices/pci0000:00/0000:00:05.0/host2/target2:0:4/2:0:4:0/block/sdb
lrwxrwxrwx 1 root root 0 Mar  1 07:51 /sys/class/block/vda -> ../../devices/pci0000:00/0000:00:0a.0/virtio1/block/vda
lrwxrwxrwx 1 root root 0 Mar  1 07:51 /sys/class/block/vdb -> ../../devices/pci0000:00/0000:00:0b.0/virtio2/block/vdb
lrwxrwxrwx 1 root root 0 Mar  1 07:51 /sys/class/block/vdc -> ../../devices/pci0000:00/0000:00:0c.0/virtio3/block/vdc

And lastly, to explain this portion of the lsblk output:
Code:
├─ailvm-vm--3000--disk--1 253:0    0    8G  0 lvm
└─ailvm-vm--751--disk--1  253:1    0    4G  0 lvm
This has nothing to do with the vm. sdb here is an LVM storage connected to a PVE machine using it for two if its VMs 3000, 751.
I chose this one on purpose to mention this part as a note of caution
 
  • Like
Reactions: JonathanB19
I'm sorry to dredge up an old post, happy to create a new one but this is exactly on topic.

This is going to become quite hard to figure out as you get more disks. So far I've tried to just make them all different sizes so I can easily identify them. This is not a great solution. Has anyone come up with an easier solution than relying these to be in order, because as my server age, I remove and add disks, and in my case, they are no longer in order anymore.

2024-04-26_13-25.png

2024-04-26_13-28.png

2024-04-26_13-32_1.png
 
Last edited:
How would you keep track of this craziness if you were using physical disks?

The answer is you would have to keep records. So do that. Write down which host block devices have which UUID inside the VM. You could put it in the notes for the VM.
 
for scsi disks you can also set various properties like WWN, vendor or serial number.. but even without that, you should already get identifiable information in the VM:

Code:
$ ls -lh /dev/disk/by-id/
total 0
lrwxrwxrwx 1 root root  9 Apr 26 09:04 ata-QEMU_DVD-ROM_QM00001 -> ../../sr0
lrwxrwxrwx 1 root root  9 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0 -> ../../sda
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi1 -> ../../sdb
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi1-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi1-part2 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi1-part3 -> ../../sdb3
lrwxrwxrwx 1 root root  9 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi2 -> ../../sdc
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi2-part1 -> ../../sdc1
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi2-part2 -> ../../sdc2
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi2-part3 -> ../../sdc3
lrwxrwxrwx 1 root root  9 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi3 -> ../../sdd
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi3-part1 -> ../../sdd1
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi3-part2 -> ../../sdd2
lrwxrwxrwx 1 root root 10 Apr 26 09:04 scsi-0QEMU_QEMU_HARDDISK_drive-scsi3-part3 -> ../../sdd3
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!