VMware Cloud Community
mujtba
Contributor
Contributor

Using VMKFSTOOLS to DELETE VIRTUAL DISKS

Is there a way to use either p2vtool or vmkfstools to DELETE a virtual disk and remove from inventory? I am trying to automate this somehow and I cannot do it unless it can be done through command line somehow..

please help

Reply
0 Kudos
16 Replies
kjb007
Immortal
Immortal

Yes, with vmkfstools:

vmkfstools -U vmfsPath

I believe you can use the powershell vi toolkit as well to do this.

-KjB

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

I used this command:

vmkfstools -U vmfspath/file.vmdk

That just deletes the VMDK file. It does not remove from INVENTORY. But the OBJECTIVE is I need something to basically do a DELETE FROM DISK, but from command line so I can create a batch file.

I also installed the VI PERL TOOLKIT. I configured IIS to run PERL on my Win 2003 Serv.

However, how do I execute a .pl file? Im not sure how to get this working in windows.

thanks in advance...

Reply
0 Kudos
kjb007
Immortal
Immortal

I haven't used the perl toolkit, only the powershell. I'd post this question in that forum. I believe you can do this with vimsh as well, but I haven't done it that way.

http://communities.vmware.com/community/developer/windows_toolkit

-KjB

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

Hello,

vmkfstools will remove the VMDK but it will not update the VM that its been removed. You need to add some scripting to do this as well.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education. CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354, As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
Reply
0 Kudos
conradsia
Hot Shot
Hot Shot

why not vmware-cmd /path/to/vmx unregister

mcowger
Immortal
Immortal

Because that deletes the whole VM, not just the disk.

Powrshell seems liek the right tool for this job....

--Matt

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
Texiwill
Leadership
Leadership

Hello,

Unregister does not delete the VM but remove it from VC or available VMs to run.

You can use vmkfstools and the vmware <path to VMX> setconfig commands to remove a VMDK from the VM. However, I am no longer sure if setconfig will work as expected either. So I generally edit the VMX file by hand to remove the VMDK if doing it by hand or I just use the VIC to do it. There is also a vimsh option to do this that may work better.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education. CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354, As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
Reply
0 Kudos
mujtba
Contributor
Contributor

Actually, I want to remove that VM and anything associated with it, so would this work:

vmware-cmd /path/to/vmx unregister

How do you use the vmkfstools and vmware &lt;path to VMX&gt; setconfig command? Would this work:

vmkfstools -setconfig /vmfs/volumes/46e6b0dc-4a39d9f4-d9f2-00096be62ef8/a901us115p2v/a901us115p2v.vmx

I was under the impression that the VMDK file is the main thing to delete since it is also the largest file. Basically I want to delete the entire directory and all files in there AND remove from inventory, but using a command line so that I can automate it.

My objective is to use a command line to DELETE A VIRTUAL DISK and remove it from inventory completly so I can automate this some how, so doing it manually won't work.

plz help.. thanx

Reply
0 Kudos
Texiwill
Leadership
Leadership

Hello,

To remove a VM completely and utterly without stopping at Go.

vmkfstools -s unregister PathToVMXfile/VMXFile
rm -rf PathtoVMXFile

To remove a VMDK ONLY not the entire VM. You have to edit the file or use vimsh or setconfig... For setconfig options run vmware-cmd with no options and it will print things out. However, I have had issues using vmware-cmd to do this. I think you will want to use vimsh.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education. CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354, As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
mujtba
Contributor
Contributor

I tried this command and it does not work:

vmkfstools -s unregister vmfs/volumes/MSA1500_LUN_9/a901us115p2v/a901us115p2v.vmx rm -rf vmfs/volumes/MSA1500_LUN_9/a901us115p2v/a901us115p2v.vmx

It said, 'YOU CAN SPECIFY ONLY ONE COMMAND AT A TIME'.

So then I tried this:

vmkfstools -s unregister vmfs/volumes/MSA1500_LUN_9/a901us115p2v/a901us115p2v.vmx

It did nothing.

I then tried this:

rm -rf vmfs/volumes/MSA1500_LUN_9/a901us115p2v/a901us115p2v.vmx

It did nothing as well. Am i typing it all correctly?

Reply
0 Kudos
IgorZ
Contributor
Contributor

If you want a single command, this should work

vmware-cmd -s unregister &lt;path-to-vmx-file&gt; && rm -f &lt;path-to-vm-folder&gt;/* && rmdir &lt;path-to-vm-folder&gt;

So for example if you have a virtual machine in directory /vmfs/volumes/vm-datastore/VirtualMachine01 the command to remove and delete would be the following

vmware-cmd -s unregister /vmfs/volumes/vm-datastore/VirtualMachine01/VirtualMachine01.vmx && rm -f /vmfs/volumes/vm-datastore/VirtualMachine01/ && rmdir /vmfs/volumes/vm-datastore/VirtualMachine01

The above (typed as one long command) will run one command after another, first removing the VM from inventory, then deleting the all files in the VM directory, then removing the enmpty directory.

Reply
0 Kudos
mujtba
Contributor
Contributor

Okay I am making a lot of progress....

So if I get that command to WORK, how do I schedule it to RUN at a certain time always? Im not a linux guy so I dont know how to use CRON.

thanks

Reply
0 Kudos
mcowger
Immortal
Immortal

Then your should checkout the hundreds of sites on the web on how to use cron.

--m

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
IgorZ
Contributor
Contributor

I'm not familiar with CRON so I can't help you there. However what I would suggest is putting that command in a shell script and variablizing the folder location and the the vmx filename and running it manually when you need it. You're not always going to be deleting the same VM over and over so I don't think CRON would even be useful in your case.

Reply
0 Kudos
Texiwill
Leadership
Leadership

Hello,

May I suggest the following book as a beginning on shell scripting.... The UNIX Programming Environment by Kernighan and Pike from Prentice-Hall. This will help you to understand how to write shell scripts, etc. I would start there.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education. CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354, As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
Reply
0 Kudos
Ken_Cline
Champion
Champion

A word of caution...all of the responses provided here are assuming that you have not changed any of the default configurations for your VM. They are also assuming that your VM is in a "Powered Off" state when you execute the commands. If you have placed .vmdk files on different VMFS volumes (i.e. to separate OS and data), then this will not work. If your VM is powered on, it will not work. To get this to work reliably, you will need to parse the .vmx file to find the path(s) to your .vmdk files. You will need to incorporate logic to ensure that your VM is powered off. You will need to put in error checking logic to make sure that your commands have completed successfully.

All in all, while it may look like a fairly simple task, if you want it to be robust and able to tolerate problems (which will occur), you've got a decently complex script to develop.

Ken Cline

Technical Director, Virtualization

Wells Landers

VMware Communities User Moderator

Ken Cline VMware vExpert 2009 VMware Communities User Moderator Blogging at: http://KensVirtualReality.wordpress.com/
Reply
0 Kudos