PowerCLI: Find a VM Based on RDM’s LUN ID

Let’s say you have a LUN ID that you clearly know is a RDM. How do you determine what virtual machine is associated with that disk?

Recently, I was prepping a cluster for routine ESXi patching. As part of my preparation, I scanned the cluster for RDM disks first to ensure that they were set to Perennially Reserved = True. After doing the RDM scan, I found a cluster that had a single RDM disk, but didn’t know which VM it was associated with. Although VMware has a Knowledge Base article (KB2001823) on how to do find RDM’s and which VM’s they’re associated with, it looks like it will find all RDM’s and VM’s across the entire vCenter Server. Since I know the cluster, and I know the RDM LUN ID, I wanted to narrow down the results for my particular needs.

Karim Elatov has a nice blog post over at VirtuallyHyper that goes through a couple of different ways to filter down the results. His last two script examples were very close to what I was looking for. In the end, here’s the script I put together and used for my particular needs:

Update: I’ve added in an additional check that will report if the RDM’s LUN ID is not found to be attached to any VM’s in the cluster.

########################################
# Script: find-vm-based-on-rdm-lun-id.ps1
# Purpose: Find a VM Based on RDM LUN ID.
########################################

$cluster = "ClusterName"
$naa = "eui."
$vms = Get-Cluster $cluster | Get-VM
$count = 0
foreach ($vm in $vms) {
     foreach ($disk in ($vm | Get-HardDisk -DiskType "RawPhysical","RawVirtual")) {
          if ($disk.ScsiCanonicalName -eq "$naa") {
               Write-Host "----------------------------------------"
               Write-Host "VM Name:  " $disk.Parent.Name
               Write-Host "LUN ID:   " $disk.ScsiCanonicalName
               Write-Host "Disk Name:" $disk.Name
               Write-Host "Disk Type:" $disk.DiskType
               Write-Host `n
               $count = $count + 1
          }
     }
}
if ($count -eq 0) {
     Write-Host "----------------------------------------"
     Write-Host "Disk $naa is not attached to any VM's in the $cluster Cluster."
     Write-Host `n
}

Creating a UEFI-Enabled VM in VMware Fusion

Let’s say you want to build a new VMware Fusion virtual machine using the newer UEFI firmware instead of the traditional BIOS. How is that done in VMware Fusion? Unlike VMware Workstation and ESXi, there’s no GUI-based option to choose EFI over BIOS (at least as of this writing). So, I decided to put this post together to walk you through the process. I should also point out that this needs to be done before an operating system is installed to the VM.

If you’re not sure what the differences are between UEFI and BIOS, How-To-Geek has two great articles that explain how newer UEFI firmware differs from traditional BIOS; “What Is UEFI, and How Is It Different from BIOS?” and “What You Need to Know About Using UEFI Instead of the BIOS.”

It’s pretty simple to tell if your VM is running BIOS or UEFI simply by looking at the boot screen. When you power on your VM, the boot screen will look like one of the following screenshots:

Before We Begin, Install a Quality Text Editor

Before diving into the meat and potatoes of creating a UEFI-enabled VM, I highly recommend installing a more robust text editor, like TextWrangler. (That is, if you don’t already have one installed). Feel free to use the plain text editor of your choice, but I suggest you shy away from using TextEdit, Word, or Pages just to be safe, as they may tweak the formatting of the text.

Create a New Virtual Machine

Open VMware Fusion and create a new virtual machine. After the VM is created, but before installing an operating system, we’ll need to make a change to the virtual machine’s *.vmx file.

  1. If the VM is powered on, shut it down or power it off. From the menu bar, select Virtual Machine > Shut Down and click Shut Down in the confirmation dialog.
  2. From the Virtual Machine Library window, right-click on the VM and choose Show in Finder. Ignore the Finder window for now, as we’ll come back to that in the next section.
    VMware-Fusion-UEFI-03-Open-in-Finder
  3. I also recommend quitting the VMware Fusion app just to be safe. From the menu bar, select VMware Fusion > Quit VMware Fusion.
    VMware-Fusion-UEFI-04-Quit-Fusion

Edit the *.vmx File to Enable UEFI

  1. In the Finder window that appeared in the previous step, locate your VM, right-click, and choose Show package contents.
    VMware-Fusion-UEFI-05-Show-Package-Contents
  2. In the contents of this package are a number of VM-related files and folders. Look for the file that ends with .vmx (Such as Windows 8 x64.vmx).
    VMware-Fusion-UEFI-06-Package-Contents-in-Finder
  3. Right-click on the *.vmx file and open with your preferred text editor.
    VMware-Fusion-UEFI-07-Open-With-Text-Editor
  4. In the text editor, insert the following line of text: firmware = “efi”

    VMware-Fusion-UEFI-08-Modify-VMX
    I typically add firmware = “efi” on line 4 of the VMX file.
  5. Save the changes to the *.vmx file and proceed with the installation of the guest OS! You should now see the UEFI firmware screen whenever the VM is powered on.

    VMware-Fusion-UEFI-01b-UEFI-Boot-Screen
    UEFI Firmware

And there you have it! I hope this post helped you figure out how to create a new UEFI-enabled VM in VMware Fusion! As always, thanks for stopping by!

Building a New Virtual Machine in VMware Fusion

In this blog post, we’ll take a look at how to setup and install a brand-new virtual machine using VMware Fusion. For this post, I’ll be installing a fresh copy of Microsoft Windows to use as an example, but these same steps should apply to just about any operating system. Let’s get started!

  1. Launch VMware Fusion. In the Virtual Machine Library window, click the + icon and select New… in the submenu that appears.
    File > New
  2. In the Select the Installation Method dialog, choose Create a custom virtual machine and click Continue.
    Select the Installation Method
  3. In the Choose Operating System dialog, choose the Operating System and OS Version that matches the type of install you’ll be doing. In this example, I’ll be doing a Windows 8 64-bit installation, so I chose Microsoft Windows > Windows 8 x64. Then click Continue to proceed.
    Choose Operating System
  4. In the Choose a Virtual Disk dialog, select Create a new virtual disk (since a fresh, new VM is being built from scratch) and click Continue.
    Choose a Virtual Disk
  5. In the Finish dialog, you can either:
    • Accept the default virtual hardware settings and click Finish.
    • Or click on the Customize Settings button to adjust the CPU, RAM, and other virtual hardware components to your liking. I’m going to customize this particular instance to demonstrate how it’s done.
      Finish
  6. Clicking either option (Customize Settings or Finish) in the previous step will bring up a Save to Disk dialog. Choose a location and click Save. Note that after clicking Save, one of two things will happen:
    • If the default settings were chosen in the previous step, the VM will power on automatically.
    • If Customize Settings was chosen in the previous step, a Settings window will appear after saving (See step 7).
      Save to Disk
  7. [Optional] In the Customize Settings window, adjust the virtual hardware as you see fit. (Remember to keep the VM within the limits of your underlying hardware). Personally, I like to bump up the CPU and Memory, as well as modify the hard disk so that “Split into multiple files” is unchecked (then click Apply to commit the HDD changes).
  8. Before installing the OS, now is a good time to consider whether the VM needs to use a traditional BIOS (default) or UEFI firmware. Typically, the default BIOS is just fine for most users, but I mention it now, as it typically can’t be changed after the OS is installed. [If installing Mac OS, the VM guest will use UEFI by default.] Also, make sure you have the installation media (CD, DVD, or ISO image) ready.
  9. Mount the OS installation media to your VM’s virtual CD/DVD drive. In this example, I’ll be using a Windows 8 64-bit ISO file. Or, if you have a physical OS installation disc, place the it into your Mac’s DVD drive (assuming your Mac still has an actual DVD drive).
    Mount Virtual CD or ISO File
    Mount ISO File
  10. Now that a virtual CD/DVD has been mounted, power on the VM by clicking the Play icon in the VM window.
    Install Guest OS

    TIP: If your mouse cursor gets ‘stuck’ in the virtual machine console window during installation (or at any time), simply press the Control + Command keys on your keyboard to ‘release’ the mouse cursor. And when you want to jump back into the VM, simply click within the VM console window again to activate the VM’s mouse/keyboard.

  11. At this point, continue installing your operating system as you typically would. Once the guest OS installation is completely finished, I’d also highly recommend installing VMware Tools shortly thereafter to take advantage of the proper drivers and other features.

New Phishing Attempt: Dropbox

If you’ve been following the news, there was a recent phishing scam going around that was involving a number of Google Docs users. (If you’re not familiar with this story, check out this post by US-CERT). Fortunately, I didn’t receive that phishing attempt message myself.

However, there now seems to be a similar phishing attempt going around, but this time it involves Dropbox. A number of sites have stories on the Google Docs scheme, but as of this writing, I haven’t seen very much involving this particular Dropbox scheme. In the email I received, there were a couple of giveaways that stood out to me:

  1. I wasn’t expecting any sort of shared document from the sender. Even though she’s in my contact list and is someone I do communicate with, it wasn’t something we had previously discussed.
  2. This one is probably the most obvious, but the From: and To: email addresses were the same. Even though I received the email, MY email address wasn’t listed in the To: field.
  3. It was sent to the wrong email address. Although this email address was once associated with Dropbox at one time, it isn’t any more. If this was legit, it would’ve gone to another email address.
  4. If I hovered over (not clicked) the “Secured Document” link, I could clearly see that it wasn’t going to a Dropbox URL.
  5. At this point, it was pretty obvious to me that this was an attempted phishing email, but I even reached out to the “sender” of this email to see if she had sent it. Her response back made it clear that she hadn’t sent this out.

Here’s a screenshot of what the email looks like. Remember to stay vigilant and question emails like this, especially when it’s not something you were expecting to receive!

Dropbox Phishing Attempt
Sample Dropbox Phishing Attempt

Mac Seems to Routinely Wake Up from Sleep

Now, I know I said this blog was going to focus mostly on virtualization and all, but every once in a while, you stumble across a tech-related issue and a fix or workaround that’s just worth sharing. This, in my opinion, is one of those times.

Occasionally, my Mac would wake itself up from sleep mode every now and again. At first, it didn’t seem like much of an issue, but I recently noticed that it seemed to be recurring at regular intervals, almost on a schedule of sorts. So, I took to the web to see if I could figure out the issue and here’s what I found:

Check the logs using Terminal

  • Open a new Terminal window (found in /Applications/Utilities) and run one of the following commands (based on your OS version):
  • For Mac OS 10.12 “Sierra”:
    log show | grep -i "wake reason"
  • For Mac OS 10.11 “El Capitan” or earlier:
    syslog | grep -i "wake reason"
  • I ran the terminal commands on my system, and in the screenshot below, the logs showed that a “Wake from sleep” instance was occurring almost every two hours!

What do these “Wake Reason” codes mean?

Ok, so my system is waking from sleep on a regular basis due to a RTC code, but what does that actually mean? Well, I found a blog post over at www.osxdaily.com that explains the codes in more detail:

  • OHC: Open Host Controller (usually a USB or Firewire device). If you see OHC1 or OHC2 it is probably an external USB keyboard or mouse that has woken up the machine.
  • EHC: Enhanced Host Controller is another USB interface, but can also be wireless devices and bluetooth since they are also on the USB bus of a Mac.
  • USB: a USB device woke the machine up
  • LID0: this is literally the lid of your MacBook portable, when you open the lid the machine wakes up from sleep
  • PWRB: Power Button, which is the physical power button on your Mac
  • RTC: Real Time Clock Alarm, is generally from wake-on-demand services like when you schedule sleep and wake on a Mac via the Energy Saver preference pane. It can also be from a launched setting, user applications, backups, and other scheduled events.

As you can see from my Terminal screenshot, I had a RTC code kicking off every two hours. Because of the RTC codes, I decided to check my settings in the Energy Saver system preferences. I also had a few UHC and EHC codes mixed in there, which was probably me (or someone in my family) clicking the mouse or keyboard to wake the system from sleep.

See if “Wake for network access” is set

  • Open System Preferences > Energy Saver
  • Uncheck: Wake for network access

See if a Schedule is set

  • While still in the System Preferences > Energy Saver window, click Schedule…
  • Ensure that Startup or wake is unchecked (unless, of course, you actually want your system to startup or sleep at a specific time).

As it turns out, my particular situation was indeed the result of “Wake for network access” being checked in the Energy Saver preference pane. After unchecking this setting, my system is no longer waking from sleep every two hours! Hopefully this post helps you to resolve your Mac’s “Wake from Sleep” woes. As always, thanks for stopping by!

List RDM Disks in a Cluster Using PowerCLI

Hello everyone! Earlier today, I was looking for a way to list the RDM disks that are currently attached and in use by VMs within a specific cluster. See, we’re in the process of decommissioning an old SAN array, and I needed to verify that specific LUNs and RDMs were no longer in use. I came across this post over on the VMware Communities portal, but needed made a minor tweak, as I only wanted to search a specific cluster. By the way… HUGE thanks to user LucD for posting the original script! After running this script, I was then able to search the output to ensure that the LUN WWNs I needed to decommission weren’t in the list.

$report = @()
$vms = Get-Cluster -name "Cluster01" | Get-VM | Get-View
foreach($vm in $vms){
     foreach($dev in $vm.Config.Hardware.Device){
          if(($dev.gettype()).Name -eq "VirtualDisk"){
               if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or 
               ($dev.Backing.CompatibilityMode -eq "virtualMode")){
                    $row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName
                    $row.VMName = $vm.Name
                    $esx = Get-View $vm.Runtime.Host
                    $row.VMHost = ($esx).Name
                    $row.HDDeviceName = $dev.Backing.DeviceName
                    $row.HDFileName = $dev.Backing.FileName
                    $row.HDMode = $dev.Backing.CompatibilityMode
                    $row.HDSize = $dev.CapacityInKB
                    $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName
                    $report += $row
               }
          }
     }
}
$report

First blog post

Hello, everyone! I’m launching this new web site as a way to share technology-related information and experiences that others might find useful. My goal is to focus mainly on virtualization, but I hope to include other consumer-level tech content as well. For those of you that know me already, I’ve talked about all these various ideas I’ve had for a while now. Starting this web site is the first step in turning some of these ideas in to action. Let’s see how this goes!

D2A_7445