VMware Cloud Community
vreiner
Contributor
Contributor
Jump to solution

Separating and relocating .vmdk files

I have a VM which I need to add a couple of virtual disks. I see that I can choose to locate the .vmdk's with the VM, but the VMFS volume the VM islocated on is full. The alternative is to choose a specific datastore and I do have another datastore which has room. I'm going to be able to clear some space later on and I will want to relocate those "loose" vmdk's back to be with the VM when space is available. My question is this: Is it possible to move those vmdk's, and if so how would I do it? Can I just do a "migrate" and specify the EXISTING datastore where the VM is currently located? Will that "herd" the loose .vmdk's back into the VM folder? Or is there another method I have to use?

Thanks in advance!

Reply
0 Kudos
1 Solution

Accepted Solutions
kjb007
Immortal
Immortal
Jump to solution

Option 1

I believe the migrate disk option moves all your vm files together, but I'm not sure if it will support disks in different locations, but it very well may. Of course, try this first, else, you have option 2.

Option 2:

You're already on vmfs, so you can do a simple mv of the disk to the same folder as your vm. One thing you should do when you want to move is to shut down the vm, remove the disk from the vm, make sure you do not delete it from the disk, just remove the mapping. Then run mv /vmfs/volumes/datastore2/vm/vm-new.vmdk vmfs/volumes/datastore1/vm/vm-new.vmdk

Then go back into the vm and add the disk back to the vm as an existing disk, and point it to the folder.

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB

View solution in original post

Reply
0 Kudos
7 Replies
taits
Enthusiast
Enthusiast
Jump to solution

I'm not sure if 'migrating' the VM to the same location will ask if you want to move the VM files. If not then you can manually move the remaining vmdk files by using 'cp -rp' of the files from one location to the other. Note that when you do this you'll have to update (edit) the vmdk descriptor files with the new location. I would make sure you make a backup of all files before doing this. Once complete and the VM is up and running then you can delete the old vmdk files. Yet again - why don't you migrate the existing VM from the location where there's a shortage of space to the location where there's ample space. Create your new disks and then migrate it back to the other location when you have created room there?

nappyrat
Enthusiast
Enthusiast
Jump to solution

I think the proper way to do it is with vmkfstools

vmkfstools -i /path/to/file.vmdk /new/path/to/file.vmdk

kjb007
Immortal
Immortal
Jump to solution

Option 1

I believe the migrate disk option moves all your vm files together, but I'm not sure if it will support disks in different locations, but it very well may. Of course, try this first, else, you have option 2.

Option 2:

You're already on vmfs, so you can do a simple mv of the disk to the same folder as your vm. One thing you should do when you want to move is to shut down the vm, remove the disk from the vm, make sure you do not delete it from the disk, just remove the mapping. Then run mv /vmfs/volumes/datastore2/vm/vm-new.vmdk vmfs/volumes/datastore1/vm/vm-new.vmdk

Then go back into the vm and add the disk back to the vm as an existing disk, and point it to the folder.

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
Reply
0 Kudos
taits
Enthusiast
Enthusiast
Jump to solution

If you use vmotion (i.e. migrate whilst VM powered on) then you don't get the option to move the VM files. Doing a cold migrate (i.e. when the VM is powered off) will allow you to specify whether or not to move the VM files. As to whether the cold migrate will pick up that some vmdk files are in a seperate location I'm not sure.

There are many ways to move or copy a VM from the command line i.e. cp, mv, vmkfstools. I imagine that the thing to ask is how much trouble do you want to go to. Using 'cp' or 'mv' or 'vmkfstools' will mean that you'll need to edit the desciptor and config files for the VM to point to the new location of the disk.

Again I'd recommend migrating (powered off) the VM to the location with more space now and creating your new disk files in the same location, then migrating it back when you've got more space. Or you could just knock up a VM with no guest OS - just disks assigned in different locations and try migrating it to see what happens.

Here's a useful guide for command line options - http://www.rtfm-ed.eu/docs/vmwdocs/esx3.x-vc2.x-serviceconsole-guide.pdf

Tait

Reply
0 Kudos
vreiner
Contributor
Contributor
Jump to solution

I did this once before using mv but as you mentioned updating all the descriptors etc. made me nervous that I might miss something and corrupt the disk or the VM. I did it without guidance and thankfully after working on it for some time (and making some mistakes along the way) I got it right. Hence my question, how to do it the "right" way.

Unfortunately I don't have a location with enough space to house the entire existing VM and the additional disks I need to create for it (almost 900Gb), hence the need to place the new disks elsewhere until I can consolidate enough space in a single VMFS volume to house the entire VM. I have a time constraint to get the new disks online and cannot wait until the space is consolidated.

The idea to detach the new disks from the powered-off VM, move them with mv then reattach sounds like it would resolve the issue of the descriptors being correct. It also saves the time of migrating the entire VM when I really will just need to move the new drives to the existing VM's folder.

Reply
0 Kudos
taits
Enthusiast
Enthusiast
Jump to solution

I'm not sure of the official "right" way to do this but the way I'd recommend would be (when you have enough space to locate all the disks in the same place) to shutdown the VM, remove (but don't delete) the disks that are on the different location, save the settings. This in effect edits the vmx file for the VM with the disk removal changes. The guest OS won't know any different because at this stage it has been powered on. Then 'cp' the disks to the VM directory and edit the settings again to add the 'new' disks. Save this and then Power On. In effect what you have done is edited the VM config file to say I have these disks in this location.

Tait

Reply
0 Kudos
kjb007
Immortal
Immortal
Jump to solution

I just tested this out. If you use the add disk wizard to add a disk in a 2nd datastore. When you're ready, you can choose migrate, without deleting anything, select the 'Move virtual machine configuration files and virtual disks', and then select the datastore. This will move your disks to the same location in the datastore you chose. In my test, I chose the same datastore that my 1st disk was located in, and the new 2nd disk was moved to the same location.

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
Reply
0 Kudos