As part of a recent cleanup of our vSphere infrastructure, I was tasked with removing disused datastores from our Nimble CS500. The CS500 had been replaced with a newer generation all-flash Nimble, and the VMs had been moved a couple of months ago. Now that the new array was up and had accumulated some snapshots, I was cleaning up the old volumes to repurpose the array. I noticed, however, that even though all of the files were removed from the datastores, there were still a lot of VMs that “resided” on the old volumes.
VMware addresses this in a KB (2105343) titled “Virtual machines show two datastores in the Summary tab when all virtual machine files are located one datastore.” It suggests that the VM is pointing to an ISO that no longer exists on the old datastore.
After looking at the configs, I realized that, sure enough, some of the VMs were still pointing to an ISO file that was no longer on that datastore. Easy, right, except that on one of the test VMs, I set the optical drive setting back to “Client Device.” It was still pointing at the old datastore.
Looking through the config again, I noticed that the Floppy Drive setting is missing from the HTML5 client. I fired up the Flex client and set the floppy drive to “Client Device” as well. Still no go. For the few VMs that were pointing at a nonexistent ISO, setting the optical drive back to “Client Device” worked, but for VMs that were pointing at a nonexistent floppy, changing the floppy to “Client Device” wasn’t working. A bug in the floppy handling? Perhaps.
I created a blank floppy image on one of my new datastores and pointed the VM’s floppy to that new image. Success! The VM was no longer listing the old datastore, and I could then set the floppy to “Client Device.” After checking out other VMs, I realized that I had over 100 VMs that had some combination of optical drive or floppy drive pointing at a non-existent file on the old datastores. PowerCLI to the rescue!
$vm = $args
$cd = get-cddrive -vm $vm
floppy = get-floppydrive -vm $vm
set-floppydrive -Floppy $floppy -FloppyImagePath "[datastorename] empty-floppy.flp" -StartConnected:$false -Confirm:$false
set-floppydrive -Floppy $floppy -NoMedia -Confirm:$false
set-cddrive -cd $cd -NoMedia -Confirm:$false
Simply save this as a .ps1 file and pass it the name of the VM (in quotes if it contains spaces.) It will get the current floppy and CD objects from the VM, set the floppy to the blank floppy image previously created, and then set both the CD and floppy to use “NoMedia.” This was a quick and dirty script, so you will have to install PowerCLI and do your own Connect-VIServer first. Once connected, however, you can either manually specify VMs one at a time or modify the script to get VM names from a file or from vCenter itself. All of these settings can be changed while the VM is running, so there is no need to schedule downtime to run this script.
After all of this work, I found that there were still a few VMs that were showing up on the old datastores. Another quick Google search revealed that any VMs that had snapshots that were taken with the CD or floppy mounted would still show up on that datastore. Drat! After clearing out the snapshots, I finally freed up the datastores and was able to delete them using the Nimble Connection Manager.
So now a little root cause analysis: why were there so many machines with a nonexistent CD and floppy mounted? After seeing that they were all Windows 2016 VMs, I went back to our templates and realized that the tech who built the 2016 template left the Windows ISO (long since deleted) and floppy image (mounted so he could F6-load the paravirtualized SCSI driver during OS installation) mounted when he created the template. I converted the template to a VM, removed the two mounts (using the same two-step method for the floppy) and converted it back to a template.
With that job done, I’m continuing to plug away at converting our other vCenters from 6.5 to 6.7U1. Have a great day, everyone!