In this case I wanted to find a way to easily and systematically find all of the virtual machines in my environment that had an ISO mounted to the virtual machine and then disconnect the ISO without any manual intervention on my part, other than perhaps running the script.
My goto for this task of course was PowerCLI. I have found that the more I play with and get to know PowerCLI the more excited I become about the possibilities it offers.
If you do a quick internet search for tasks like, "Use PowerCLI to get all VMs with a mounted ISO and disconnect ISO" you will find loads of blog posts on how to perform this task and some with different code styles and syntax, but all fairly basic as PowerCLI makes this a pretty simple operation.
The problem I discovered with this...well, actually I discovered a few problems.
The first was that I had broken a cardinal rule of gathering code examples off of the web. This is usually a rule I am very diligent in abiding by.
The first was that I had broken a cardinal rule of gathering code examples off of the web. This is usually a rule I am very diligent in abiding by.
Test, Test, and Test some more!
The second problem I discovered was that you should not assume that an operation against a virtual machine will behave in the same manner when those virtual machines are running different guest operating systems.
This ultimately was my downfall.
The third and final problem I discovered was that you cannot simply disconnect an ISO from a virtual machine running a Linux operating system, in this case CentOS, and expect the operating system to simply relinquish control of the media.
Now before you say, "I can't believe you didn't test the code first!", I did test the code I had found, I just didn't test it across virtual machines running different operating systems. I manage a small albeit growing environment in which we've only somewhat recently started adding a number of Linux based virtual machines and I am still learning a lot of the ins and outs of Linux.
In my test I performed a quick test of the code against a low-level Windows VM and it worked flawlessly. I thought, "Well, that worked great. Let's expand that to the entire environment. After-all, I'm just disconnecting an ISO. What could happen?"
Famous last words, right?
Just for reference, here is the simple one-liner I discovered that worked exactly as advertised, unless you're running Linux VMs. Credit for the original code can be found here, Skepper.
So...What happens if you try to disconnect an ISO from a Linux VM where the guest operating system still has a lock on the media you ask? Well, that is a great question. The answer to which I found out the hard way, and will never forget. If you've experienced this before yourself then you know where I'm going with this.
If you attempt this you will see this message show up in vCenter.
If you click on "Answer Question" at the end of the message you will get this window.
While this message is displayed in vCenter, the virutal machine and guest operating system in question is in an unresponsive state. Not a good thing if one of the few Linux VMs in your environment just happens to be running your core business application. I told you I said I would never forget this one, didn't I.
I recommend leaving this at the default of, No. Once you answer this question the VM will become responsive once again.
I recommend leaving this at the default of, No. Once you answer this question the VM will become responsive once again.
Well, the simple, but important solution to this is to make sure you unmount the media inside of the Linux guest before you disconnect the ISO from the virtual machine.
On most modern flavors of Linux, this can be done with the incredibly simple command below.
Once you've ejected or unmounted the media inside of the Linux guest you can disconnect the ISO from the virtual machine without fear.
VMware has the following KB on this issue, https://kb.vmware.com/s/article/2144053
In my next post I will show you the PowerCLI script I came up with to perform this task against Linux virtual machines properly without causing the guest OS and virtual machine to become unresponsive.
Thanks for reading!
In my next post I will show you the PowerCLI script I came up with to perform this task against Linux virtual machines properly without causing the guest OS and virtual machine to become unresponsive.
Thanks for reading!
No comments:
Post a Comment