Hello,
Could you tell me , using perl, how can I have all partitions from an ESX server 3.5 and retrieve informations about each partitions (start sector, partition type, ... ) ?
Thank you
Dominic
I've heard from few VMware folks that this information is not explicitly clear when looking for partition information and their respective mount points such as /,/boot,/tmp, etc and I thought I take a look at the storageSystem to see if any correlations can be made with some of the available functions. Specifically the RetrieveDiskPartitionInfo() looked promising but I was not able to figure out a way to extract the device path from QueryAvailableDisksForVmfs() which is one of the required parameters. I ended up manually substituting the devicePath using information from the classic Service Console such as "vdf -h" and "fdisk -l".
vdf -h output:
[root@esx-1 root]# vdf -h Filesystem Size Used Avail Use% Mounted on /dev/cciss/c0d0p2 7.9G 1.3G 6.2G 18% / /dev/cciss/c0d0p1 244M 27M 204M 12% /boot /dev/cciss/c0d0p7 2.0G 249M 1.7G 13% /home none 391M 0 391M 0% /dev/shm /dev/cciss/c0d0p8 2.0G 33M 1.9G 2% /tmp /dev/cciss/c0d0p6 4.0G 361M 3.4G 10% /var /vmfs/devices 2.6T 0 2.6T 0% /vmfs/devices /vmfs/volumes/48e16ed0-420158d5-5601-00215acaa2b2 152G 118G 34G 77% /vmfs/volumes/<some_vmfs_volume1> /vmfs/volumes/48e1a4a6-3b55e69b-02a9-001f29c948e2 151G 100G 50G 66% /vmfs/volumes/<some_vmfs_volume2> /vmfs/volumes/48e1b819-3443974c-03c4-001f29c948e2 150G 117G 32G 78% /vmfs/volumes/<some_vmfs_volume3> /vmfs/volumes/48e1cd81-81223593-6cd8-00215acaa2b2 124G 86G 38G 69% /vmfs/volumes/<some_vmfs_volume4> /vmfs/volumes/4913e014-62bc3b90-da2e-001f29c948f8 50G 521M 49G 1% /vmfs/volumes/<some_vmfs_volume5> /vmfs/volumes/495e986b-b61cc1d6-27b1-00215ab08a79 153G 114G 38G 74% /vmfs/volumes/<some_vmfs_volume6> /vmfs/volumes/d32c5a97-e039bdbf 1.3T 739G 609G 54% /vmfs/volumes/<some_vmfs_volume7>
fdisk -l output:
[root@esx-1 root]# fdisk -l Disk /dev/sda: 134.2 GB, 134217728000 bytes 255 heads, 63 sectors/track, 16317 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 1 16317 131066238+ fb Unknown Disk /dev/sdb: 162.1 GB, 162135015424 bytes 255 heads, 63 sectors/track, 19711 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 19711 158328543+ fb Unknown Disk /dev/sdc: 163.2 GB, 163208757248 bytes 255 heads, 63 sectors/track, 19842 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 19842 159380801 fb Unknown Disk /dev/sdd: 164.2 GB, 164282499072 bytes 255 heads, 63 sectors/track, 19972 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 19972 160425026 fb Unknown Disk /dev/sde: 165.3 GB, 165356240896 bytes 255 heads, 63 sectors/track, 20103 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sde1 1 20103 161477283+ fb Unknown Disk /dev/sdf: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdf1 1 7832 62910508+ 83 Linux Disk /dev/sdg: 17.1 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdg1 1 2088 16771796 fb Unknown Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes 255 heads, 63 sectors/track, 8920 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/cciss/c0d0p1 * 1 32 257008+ 83 Linux /dev/cciss/c0d0p2 33 1076 8385930 83 Linux /dev/cciss/c0d0p3 1077 1285 1678792+ 82 Linux swap /dev/cciss/c0d0p4 1286 8920 61328137+ f Win95 Ext'd (LBA) /dev/cciss/c0d0p5 1286 7863 52837753+ fb Unknown /dev/cciss/c0d0p6 7864 8385 4192933+ 83 Linux /dev/cciss/c0d0p7 8386 8646 2096451 83 Linux /dev/cciss/c0d0p8 8647 8907 2096451 83 Linux /dev/cciss/c0d0p9 8908 8920 104391 fc Unknown
This information will differ based on the type of system, but you'll want to pass in the device path and in our example, will use /dev/cciss/c0d0 and pay close attention from the output from "vdf -h" and you'll see how to correlate between the start,end sectors and the partition types.
Example execution of queryDiskParition.pl script:
[vi-admin@vima ~]$ ./queryDiskParition.pl --server <esx_erver> --device /dev/cciss/c0d0 partition: 1 type: linuxNative startSector: 63 endSector: 514079 isLogical: NO size: 250.98 MB partition: 2 type: linuxNative startSector: 514080 endSector: 17285939 isLogical: NO size: 8.00 GB partition: 3 type: linuxSwap startSector: 17285940 endSector: 20643524 isLogical: NO size: 1.60 GB partition: 4 type: extended startSector: 20643525 endSector: 143299799 isLogical: NO size: 58.49 GB partition: 5 type: vmfs startSector: 20643588 endSector: 126319094 isLogical: YES size: 50.39 GB partition: 6 type: linuxNative startSector: 126319158 endSector: 134705024 isLogical: YES size: 4.00 GB partition: 7 type: linuxNative startSector: 134705088 endSector: 138897989 isLogical: YES size: 2.00 GB partition: 8 type: linuxNative startSector: 138898053 endSector: 143090954 isLogical: YES size: 2.00 GB partition: 9 type: vmkDiagnostic startSector: 143091018 endSector: 143299799 isLogical: YES size: 101.94 MB Total size: 68.33 GB
As you can see you can slowly map back the partitions id from the script output back to either output from the Service Console. To retrieve the size of the each partition, you'll want to take subtract the endSector from startSecotr and multiply by 512 (512-byte sectors).
The partition type was not well documented or documented at all in VI SDK 2.5 but is slightly documented in vSphere SDK 4.0
The Linux related partitions such as /,/boot,/tmp,etc. are defined as linuxNative, you can see that the Service Console swap is defined as linuxSwap and the vmkcore dump is defined as vmkDiagnostic and VMFS partitions are just vmfs. You'll see that the information here is useful but you won't find any mappings to say partition1 = /boot or anything like that.
Again, I haven't figured out a way to extract all disk devices, so you'll need to manually provide that as an input.
Attached is the script and this will work on both VI SDK 2.5 and vSphere SDK 4.0
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
I've heard from few VMware folks that this information is not explicitly clear when looking for partition information and their respective mount points such as /,/boot,/tmp, etc and I thought I take a look at the storageSystem to see if any correlations can be made with some of the available functions. Specifically the RetrieveDiskPartitionInfo() looked promising but I was not able to figure out a way to extract the device path from QueryAvailableDisksForVmfs() which is one of the required parameters. I ended up manually substituting the devicePath using information from the classic Service Console such as "vdf -h" and "fdisk -l".
vdf -h output:
[root@esx-1 root]# vdf -h Filesystem Size Used Avail Use% Mounted on /dev/cciss/c0d0p2 7.9G 1.3G 6.2G 18% / /dev/cciss/c0d0p1 244M 27M 204M 12% /boot /dev/cciss/c0d0p7 2.0G 249M 1.7G 13% /home none 391M 0 391M 0% /dev/shm /dev/cciss/c0d0p8 2.0G 33M 1.9G 2% /tmp /dev/cciss/c0d0p6 4.0G 361M 3.4G 10% /var /vmfs/devices 2.6T 0 2.6T 0% /vmfs/devices /vmfs/volumes/48e16ed0-420158d5-5601-00215acaa2b2 152G 118G 34G 77% /vmfs/volumes/<some_vmfs_volume1> /vmfs/volumes/48e1a4a6-3b55e69b-02a9-001f29c948e2 151G 100G 50G 66% /vmfs/volumes/<some_vmfs_volume2> /vmfs/volumes/48e1b819-3443974c-03c4-001f29c948e2 150G 117G 32G 78% /vmfs/volumes/<some_vmfs_volume3> /vmfs/volumes/48e1cd81-81223593-6cd8-00215acaa2b2 124G 86G 38G 69% /vmfs/volumes/<some_vmfs_volume4> /vmfs/volumes/4913e014-62bc3b90-da2e-001f29c948f8 50G 521M 49G 1% /vmfs/volumes/<some_vmfs_volume5> /vmfs/volumes/495e986b-b61cc1d6-27b1-00215ab08a79 153G 114G 38G 74% /vmfs/volumes/<some_vmfs_volume6> /vmfs/volumes/d32c5a97-e039bdbf 1.3T 739G 609G 54% /vmfs/volumes/<some_vmfs_volume7>
fdisk -l output:
[root@esx-1 root]# fdisk -l Disk /dev/sda: 134.2 GB, 134217728000 bytes 255 heads, 63 sectors/track, 16317 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 1 16317 131066238+ fb Unknown Disk /dev/sdb: 162.1 GB, 162135015424 bytes 255 heads, 63 sectors/track, 19711 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 19711 158328543+ fb Unknown Disk /dev/sdc: 163.2 GB, 163208757248 bytes 255 heads, 63 sectors/track, 19842 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 19842 159380801 fb Unknown Disk /dev/sdd: 164.2 GB, 164282499072 bytes 255 heads, 63 sectors/track, 19972 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 19972 160425026 fb Unknown Disk /dev/sde: 165.3 GB, 165356240896 bytes 255 heads, 63 sectors/track, 20103 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sde1 1 20103 161477283+ fb Unknown Disk /dev/sdf: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdf1 1 7832 62910508+ 83 Linux Disk /dev/sdg: 17.1 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdg1 1 2088 16771796 fb Unknown Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes 255 heads, 63 sectors/track, 8920 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/cciss/c0d0p1 * 1 32 257008+ 83 Linux /dev/cciss/c0d0p2 33 1076 8385930 83 Linux /dev/cciss/c0d0p3 1077 1285 1678792+ 82 Linux swap /dev/cciss/c0d0p4 1286 8920 61328137+ f Win95 Ext'd (LBA) /dev/cciss/c0d0p5 1286 7863 52837753+ fb Unknown /dev/cciss/c0d0p6 7864 8385 4192933+ 83 Linux /dev/cciss/c0d0p7 8386 8646 2096451 83 Linux /dev/cciss/c0d0p8 8647 8907 2096451 83 Linux /dev/cciss/c0d0p9 8908 8920 104391 fc Unknown
This information will differ based on the type of system, but you'll want to pass in the device path and in our example, will use /dev/cciss/c0d0 and pay close attention from the output from "vdf -h" and you'll see how to correlate between the start,end sectors and the partition types.
Example execution of queryDiskParition.pl script:
[vi-admin@vima ~]$ ./queryDiskParition.pl --server <esx_erver> --device /dev/cciss/c0d0 partition: 1 type: linuxNative startSector: 63 endSector: 514079 isLogical: NO size: 250.98 MB partition: 2 type: linuxNative startSector: 514080 endSector: 17285939 isLogical: NO size: 8.00 GB partition: 3 type: linuxSwap startSector: 17285940 endSector: 20643524 isLogical: NO size: 1.60 GB partition: 4 type: extended startSector: 20643525 endSector: 143299799 isLogical: NO size: 58.49 GB partition: 5 type: vmfs startSector: 20643588 endSector: 126319094 isLogical: YES size: 50.39 GB partition: 6 type: linuxNative startSector: 126319158 endSector: 134705024 isLogical: YES size: 4.00 GB partition: 7 type: linuxNative startSector: 134705088 endSector: 138897989 isLogical: YES size: 2.00 GB partition: 8 type: linuxNative startSector: 138898053 endSector: 143090954 isLogical: YES size: 2.00 GB partition: 9 type: vmkDiagnostic startSector: 143091018 endSector: 143299799 isLogical: YES size: 101.94 MB Total size: 68.33 GB
As you can see you can slowly map back the partitions id from the script output back to either output from the Service Console. To retrieve the size of the each partition, you'll want to take subtract the endSector from startSecotr and multiply by 512 (512-byte sectors).
The partition type was not well documented or documented at all in VI SDK 2.5 but is slightly documented in vSphere SDK 4.0
The Linux related partitions such as /,/boot,/tmp,etc. are defined as linuxNative, you can see that the Service Console swap is defined as linuxSwap and the vmkcore dump is defined as vmkDiagnostic and VMFS partitions are just vmfs. You'll see that the information here is useful but you won't find any mappings to say partition1 = /boot or anything like that.
Again, I haven't figured out a way to extract all disk devices, so you'll need to manually provide that as an input.
Attached is the script and this will work on both VI SDK 2.5 and vSphere SDK 4.0
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Thank you for all your informations.
Dominic
np. Don't forget to award correct or helpful points
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Hello,
Finally instead of using /dev I use /vmfs/devices/disks/vmhbaA:T:L:0.
I found all luns for each hbas and use your code to find partition informations for all available partitions on the ESX host.
Thank you for your help
Dominic
If that's the case, I can probably re-write the script to automatically extract all vmhbaA:T:L:0 without having to specify it. I'll need to find some time and test this out
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Looking from this information is that possible to get allocated(occupied) sector count for disk?