VMWare guest
From Lolly's Wiki
Jump to navigationJump to search
Match the guest disk with the vmdk in Linux
The only way I know is to download the VMX file from the location where your VM resides.
In you VCenter
- find your VM
- go to the Datastores tab
- select the datastore where your VM config is in
- go to the Files tab
- select your VM name on the left side
- find the <VM Name>.vmx file on the right side and select it via the square box left to the name
- Press DOWNLOAD
Save it wherever you want. Open a shell and do:
You hve to sort the scsi hosts by the pci slot number (look at scsi3 in this example):
$ grep -E "scsi[0-9]+\.pciSlotNumber" vmware-guest.vmx | sort -k3,3
scsi0.pciSlotNumber = "16"
scsi3.pciSlotNumber = "32"
scsi1.pciSlotNumber = "34"
scsi2.pciSlotNumber = "35"
For the scsi devices there is a mapping in the option scsi[0-9]+:[0-9]+\.fileName to the corresponding VMDKs:
$ grep -E "scsi[0-9]+:[0-9]+\.fileName" vmware-guest.vmx | sort
scsi0:1.fileName = "vmware-guest_2.vmdk"
scsi0:2.fileName = "/vmfs/volumes/ad3ee111-a9176b63/vmware-guest/vmware-guest.vmdk"
scsi0:3.fileName = "/vmfs/volumes/ad3ee111-a9176b63/vmware-guest/vmware-guest_1.vmdk"
scsi1:2.fileName = "/vmfs/volumes/4c4de182-ed59d164/vmware-guest/vmware-guest.vmdk"
scsi1:3.fileName = "/vmfs/volumes/4c4de182-ed59d164/vmware-guest/vmware-guest_3.vmdk"
scsi2:0.fileName = "/vmfs/volumes/77482ef3-91f2dc5e-0000-000000000000/vmware-guest/vmware-guest.vmdk"
scsi3:0.fileName = "/vmfs/volumes/90b16a56-cda26ee5-0000-000000000000/vmware-guest/vmware-guest.vmdk"
scsi3:1.fileName = "/vmfs/volumes/90b16a56-cda26ee5-0000-000000000000/vmware-guest/vmware-guest_4.vmdk"
I have found no easy way to match the volume ids to volume names until now but if you look at the Summary of your volumes in vSPhere you will find something like:
Type: NFS 4.1 URL: ds:///vmfs/volumes/77482ef3-91f2dc5e-0000-000000000000/
which matches our scsi2:0.fileName in this example.
This knowledge put together in a little awk script:
$ awk '
$1 ~ /scsi[0-9]+\.pciSlotNumber$/ {
scsi=$1;
gsub(/\..*$/,"",scsi);
slots[$NF]=scsi;
}
$1 ~ /scsi[0-9]+:[0-9]+\.fileName/ {
id=$1;
gsub(/\..*$/,"",id);
gsub(/:/,SUBSEP,id);
vmdk[id]=$NF;
}
END{
host=32; # base host id of your linux vm
n=asorti(slots,slots_sorted);
for(i=1; i<=n; i++){
for(key in vmdk){
split( key, values, SUBSEP);
# values[1] is the pciSlotNumber name (scsi0 etc.)
# values[2] is the scsi id
if(values[1]==slots[slots_sorted[i]]) {
print host":0:"values[2]":0",vmdk[key];
}
}
host++;
}
}' vmware-guest.vmx
The output might look like this:
32:0:1:0 "hhlokavs-ts_2.vmdk" 32:0:2:0 "/vmfs/volumes/ad3ee111-a9176b63/hhlokavs-ts/hhlokavs-ts.vmdk" 32:0:3:0 "/vmfs/volumes/ad3ee111-a9176b63/hhlokavs-ts/hhlokavs-ts_1.vmdk" 33:0:0:0 "/vmfs/volumes/90b16a56-cda26ee5-0000-000000000000/hhlokavs-ts/hhlokavs-ts.vmdk" 33:0:1:0 "/vmfs/volumes/90b16a56-cda26ee5-0000-000000000000/hhlokavs-ts/hhlokavs-ts_4.vmdk" 34:0:2:0 "/vmfs/volumes/4c4de182-ed59d164/hhlokavs-ts/hhlokavs-ts.vmdk" 34:0:3:0 "/vmfs/volumes/4c4de182-ed59d164/hhlokavs-ts/hhlokavs-ts_3.vmdk" 35:0:0:0 "/vmfs/volumes/77482ef3-91f2dc5e-0000-000000000000/hhlokavs-ts/hhlokavs-ts.vmdk"
On the host you find the equal ids with lsscsi:
$ lsscsi
[2:0:0:0] cd/dvd NECVMWar VMware SATA CD00 1.00 /dev/sr0
[32:0:1:0] disk VMware Virtual disk 2.0 /dev/sda
[32:0:2:0] disk VMware Virtual disk 2.0 /dev/sdb
[32:0:3:0] disk VMware Virtual disk 2.0 /dev/sdc
[33:0:0:0] disk VMware Virtual disk 2.0 /dev/sdd
[33:0:1:0] disk VMware Virtual disk 2.0 /dev/sde
[34:0:2:0] disk VMware Virtual disk 2.0 /dev/sdf
[34:0:3:0] disk VMware Virtual disk 2.0 /dev/sdg
[35:0:0:0] disk VMware Virtual disk 2.0 /dev/sdh