bmani27
Enthusiast
Enthusiast

How to know which VMDK corresponds to the system drive of the VM using VI SDK(C#)?

Jump to solution

Hi all,

I have all the vmdk files of a VM. I want to know which VMDK file corresponds to the system drive of the VM using VI SDK (C#). I have browsed thro' the mob to some extent.I am not able to get it. Can anyone help me on this ?

Thanks in Advance,

Mani

0 Kudos
1 Solution

Accepted Solutions
ISYS2
Enthusiast
Enthusiast

The whole premise of Virtualisation is that the kernel doesn't know or care what is installed on the disks allocated to a VM. Likewise an OS on a VM shouldn't be able to see or know about the underlying infrastructure - Isolation is the term used.

That said the MBR is always on SCSI disk 0:0. This is always the first disk presented to a VM through the vmx file. If you can assume that the System drive is on the same disk as the MBR (most systems are built this way) you can look for the path of SCSI disk 0:0 in the vmx file.

However some systems might have the System disk on a separte drive to the MBR. It all depends on which method you have used to build your OS.

I hope this is of some help

ISYS

Message was edited by: ISYS2

View solution in original post

0 Kudos
17 Replies
ISYS2
Enthusiast
Enthusiast

The whole premise of Virtualisation is that the kernel doesn't know or care what is installed on the disks allocated to a VM. Likewise an OS on a VM shouldn't be able to see or know about the underlying infrastructure - Isolation is the term used.

That said the MBR is always on SCSI disk 0:0. This is always the first disk presented to a VM through the vmx file. If you can assume that the System drive is on the same disk as the MBR (most systems are built this way) you can look for the path of SCSI disk 0:0 in the vmx file.

However some systems might have the System disk on a separte drive to the MBR. It all depends on which method you have used to build your OS.

I hope this is of some help

ISYS

Message was edited by: ISYS2

View solution in original post

0 Kudos
tos2k
Expert
Expert

Hehe, sound like your are looking for C:\ (use VM->Guest->Disk)

:smileygrin:

Otherwise, as posted here

http://communities.vmware.com/message/810230

There is a key missing in the VI SDK, that lets you know which virtual disk (vmdk) a partition belongs too.

I posted a feature request on this before:

http://communities.vmware.com/message/831958

Tos2k

bmani27
Enthusiast
Enthusiast

Hi,

Thanks for the reply.Yeah I too noticed that some key is missing for the guest partitions. But explaining my question clearly, I want to know which VMDK file corresponds to the system drive in the VM. I dont mind if the VMDK contains some other partitions. Any suggestions for this ?

Thanks,

Mani

0 Kudos
jrackliffe
Hot Shot
Hot Shot

As noted earlier in the thread the "first" VirtualDisk will be the 0:0 and I believe that this will always have unitNumber = 0. So assuming you can get the ref to the VirtualDisk via the vm.config.hardware you should be able to easily check the VirtualDeviceFileBackingInfo accessible via the backing property of that VirtualDisk. That base class has a fileName property which will have the vmdk path in your DataStore.

Is that what you were looking for?

J

bmani27
Enthusiast
Enthusiast

Hi,

Your information was useful. But I was able to change the first virtual disk to some other (say 0:1) when creating a new VM. In this case also, are you sure that unitNumber will be 0 ?

Thanks,

Mani

0 Kudos
ISYS2
Enthusiast
Enthusiast

Hi Mani - has your question changed from the original one?

If, as you stated earlier, you have a bunch of vmdk files and would like to know which one has the system partition on it would be the same as if you had a set of physical disks in a cardboard box and would like to know which one has the system partition on. The only way you could do it is to mount each one, find the one with the MBR and then by reading the MBR work out which one has the system partition (this will only help if the physical disks have a label on them)

If you have the corresponding vmx file that goes with the disks this is a bit easier because as I said earlier you can read the name of Disk 0:0 in the vmx file (it will contain the MBR).

for example if you had a VM called TEST:-

In the vmx file look for the following

scsi0:0.present="true"

scsi0:0.filename ="TEST_1.vmdk" <----- This is tells you that name of the boot drive is TEST_1.vmdk

I would recommend labelling future vmdk files using an appropriate naming convention that will help identify the system partition.

Sorry this doesn't fully answer the question

ISYS

0 Kudos
jrackliffe
Hot Shot
Hot Shot

Nope I am not sure, thats why I said "I believe". Smiley Wink I thought unitNumber was really a logical item used by VMware w/in VI, but that is far from a definitive.

But like lSYS2 notes the only way to "really" know the boot drive would be to rip the drives early sectors and look for the MBR which is probably not feasible nor recommended (read: supported by VMware).

Now you may want to do your own trial and error. Create machines, move disks to new SCSI ids, remove disks from the machine whatever activity you are trying to automate and see what the outcome is. All the while reviewing the unitNumber and the boot process to assure the machine will successfully boot on the next try.

I guess you need to meet in the middle and decide if the solution you would provide is valuable enough and hits enough of the VMs out there to justify the risk of acting on the wrong disk on a machine that may have been adjusted.

Again everything is a tradeoff when you stray off of documented solutions w any API.

Good luck. J

As a note, I have an RFE in to allow for labeling of VirtualDisks so that during creation and updates so you can apply metadata to the Disk for use in these types of cases. Also, would avoid needing to work around the auto naming/numbering by VI when doing fileOperation.create steps. Who knows if/when that would be supported.

0 Kudos
bmani27
Enthusiast
Enthusiast

Hi,

My question hasnt got changed. Rather i would like to rephrase it :D. I have the names of all the VMDK files (got by VI SDK only) belonging to a particular VM.I want to know which VMDK file corresponds to the system drive in the VM. Extending this question, I would like to know if there is a mapping that can exist between the disk partitions of the VM and the VMDK files (virtual disks of the VM). I read some of your posts and found that there is a key missing in the GuestDisk partitions that can tell which disk that partition belongs to. Any other method for this ???

One more thing. Are you sure that scsi 0:0 will always be the system drive ( ie boot drive ) ? I was able to change the virtual disk to some other ( say scsi 0:1 ) when creating a new VM. Actually i havent installed OS in the new VM. But i was able to create the VM.

But in an older VM (which has the system drive on scsi 0:0 ), i changed the disk to scsi 0:4. Even after changing in the vmx file, i was not able to boot the VM. So can I be sure that system drive will always reside on scsi 0:0 ?

Thanks in Advance,

Mani

0 Kudos
ISYS2
Enthusiast
Enthusiast

Good Morning Mani

There seems to be some confusion here. So here goes

  • The boot drive and the system partition are NOT the same thing.

  • When booting a VM reads its vmx file and looks for the address of the boot drive (normally SCSI 0:0)

  • Then it reads the MBR (Master Boot Record) on the boot drive.

  • Once found, the MBR tells the computer where the System partition is. It could be on the same drive - IT MIGHT BE ON A DIFFERENT DRIVE Smiley Happy.

  • You can change the SCSI number of the boot drive and this will be reflected in the vmx file.

  • If it doesn't find the MBR I don't think it looks elsewhere for it - have to look that up.

The only place that the location of the system partition is defined is the MBR.

Sorry but that is the way it works. Smiley Happy

ISYS

0 Kudos
bmani27
Enthusiast
Enthusiast

Hi,

For this question ???

I would like to know if there is a mapping that can exist between the disk partitions of the VM and the VMDK files (virtual disks of the VM). I read some of your posts and found that there is a key missing in the GuestDisk partitions that can tell which disk that partition belongs to. Any other method for this ???

Thanks,

Mani

0 Kudos
bmani27
Enthusiast
Enthusiast

Hi,

I have done some amount of experimentation with SCSI ids. I have changed the id of the virtual disk where the system partition resides ( say scsi 0:0 to scsi 0:8 ).The change is reflected in the vmx file and in the unitNumber field of config.hardware.device. But the VM is not booting :-(. If i change the ids of other virtual disks, there are no problems. So can I conclude that scsi 0:0 should contain the BOOT partition ? But I have to experiment with creating a new VM and changing the virtual disk id to other numbers. The problem is I cant do it as of now :).

0 Kudos
jrackliffe
Hot Shot
Hot Shot

Mani,

As the other threads have told there is no correlation between GuestDisk partitions and the VirtualDisk that partition resides on. As partitioning is OS dependent it is really a value add that VMware could provide, but would depend on frameworks like vmtools to fill in the data which is how it handles most Guest info. What I would say is submit an RFE to your support team and break down what you need. J

0 Kudos
tos2k
Expert
Expert

What do you mean, something else than this:

http://communities.vmware.com/thread/119757

What else can I do? VMware has not even replied to it...

Tos2k

0 Kudos
jrackliffe
Hot Shot
Hot Shot

Sorry wasn't specific. Nope I was referring exactly to the linked thread and your comments.

Was speaking specifically to Mani's request for the same stuff you already highlighted and about what he could do to put the pressure on VMware to offer a solution. Although VMTN is great it doesn't necessarily come up in Product Feature reviews when VMware looks at SDK "next" nor is VMware required to respond. Now if you submit an RFE through your support channel it should be cataloged and should get reviewed. Now if 10 companies submit the same conceptual RFE then I sure would hope that would get priority.

J

0 Kudos
bmani27
Enthusiast
Enthusiast

Thanks all for your valuable information. I will try to submit an RFE :smileygrin:

Mani.

0 Kudos
bmani27
Enthusiast
Enthusiast

Hi,

Meanwhile if you guys find any information related to this, do share with me Smiley Happy

Thanks,

Mani

0 Kudos
tos2k
Expert
Expert

It's been a shame to read this, finally, after just three other tries, VMware replied where to put requests for change/enhancements:

http://www.vmware.com/support/policies/feature.html

Tos2k

0 Kudos