Moving VMs from datastore to datastore using PowerCLI and Storage vMotion

Overview

This is the time of season for us sysadmins to perform upgrades, updates and installation of new gear. In a virtualized world we may think that this is no longer something that is difficult or time consuming. In most cases this line of thought is correct, however, there are instances where the underlying process can be very time consuming, especially if done manually with mouse and man via the GUI interface we so love.

I am talking about upgrading a data storage system that our virtual machines ride upon. When you upgrade the storage system you need to take it offline or power it off. Obviously if you do this you will either power off all virtual machines or need to migrate them to storage that is not going to be taken down. But if you migrate all or large quantities of  VMs at the same time you may run into bandwidth bottle necks causing latency problems or worse.

This document is intended to help solve this problem by executing one move at a time automatically.

Connecting to vCenter

The first thing you want to do, assuming that you have PowerCLI setup and working correctly, is to connect to the vCenter server.

Connect-VIServer -Server  -Protocol https -User  -Password

Once the connection is established you will be able to run the subsequent commands.

Identifying the machines you wish to move

Now we want to give some thought to the machines that we want to migrate and see if there are ways to limit the quantity of machines to move. Basically adding filters to limit the returned list of virtual machines that we will eventually run our move command against.

Get-datastore | Where {$_.name -like '*MY_DATASTORE_BACKUP*'} | Get-VM | Where {$_.name -like '*ORGANIZATION_01*'}

Executing the move one virtual machine at a time

Once we have the list we want to execute the move command against each of the entries, but not all at the same time. Why? Because, it will saturate the link to your datastore which increases latency and inevitably causing server response issues or even failures.

So, we don’t want to do that. We want the system to execute each move command individually in a serial fashion. Think of it as first in first out or FIFO.

$VMs = (Get-datastore | Where {$_.name -like '*MY_DATASTORE_BACKUP*' } | Get-VM  | Where {$_.powerstate -eq 'PoweredOn' -and $_.name -like '*ORGANIZATION_01*'})

Foreach ($VM in $VMs) {
Get-VM $VM | Move-VM -Datastore "MY_DATASTORE_PRIMARY"
}

Here, I also took the liberty to only target the VMs that were powered on at the time. In our case the ones that were powered off were decommissioned systems that we slated for deletion.

The foreach loop is what executes each move individually. The system executes and waits for the execute to get done prior to iterating to the next item in the $VMs variable list.

Hopefully this helps others who must upgrade storage systems that their VMware infrastructure rides upon.

Advertisements

Using Ubuntu Unity – Virtual Desktops

Intro

When I first started using Ubuntu a few years back, I remember doing so begrudgingly. It seemed that I was going backwards in productivity when having to use Unity, so I always tried to find alternatives.

Background check here: I am a middle aged IT person that has used Linux for 15+ years. But, I had mostly used Linux in a server role and used rarly used Linux as a desktop OS. When I did use Linux as a desktop I preferred to use KDE on CentOS. I then changed jobs from managing many servers that provided ISP services, to creating IT training labs used by students. Today’s students were becoming very Linux savy and their distribution of choice was Ubuntu, so I decided to use Ubuntu as the desktop.

I decided that I would use Ubuntu as my personal desktop operating system to force myself to learn how to work through all scenarios that may crop up in the lab environments.

At first I tried using Ubuntu straight out of the box. The UI was smooth and responsive, however, it consumed a lot of real estate and was very constrictive. I had been using various virtual desktop software for Windows as well as on KDE on my CentOS system and knew there was virtual desktop availability in Unity, but the question in my mind was; “can I controll it”?

The rest of this blog will walk you through what I have done in Unity and begin to demostrate why I am now a Unity junkie!

More backgroud: my primary system is a Lenovo P50 with 64 GB RAM running Ubuntu 16.04.There are the need for some tweaks to get things to work, but some things that you can tweak on Linux work out much better than stuff you cannot easily tweak in Windows (like using 2k resolution on 4k 15″ notebook screen).

What can you do with Ubuntu Unity?

Well, this is the crux of the story. I can use many virtual desktops and lay them out in a grid of my choosing. selection_101For me I like a 3×3 solution where I can have a an instance of Firefox, Chrome, Thunderbird, Konsole, VMware Workstation and an IDE each open in their own virtual desktop that I can easily move to and move apps around using keyboard shortcuts. You can accomplish some of this with with 3rd pary tools on Windows and OSx using Dexpot and Total Spaces respectfully, but the functionality is no where near what you get with Unity. Nor could I achieve a similar smoothness of operation in KDE that I can in Unity.

Okay, so moving from virtual desktop 1 (upper left) to virtual desktop 2 (upper center) requires the use of Ctrl+Alt+➡️. If you want to move an application, you place focus on the application and use Ctrl+Shift+Alt+➡️. You can also move an application to certain locations on a virtual desktop using a keyboard shortcuts. Ctrl+Super+➡️ will place your app on the right half of your screen. You also have keyboard shortcuts for each linked application, Super+(0-9), in the launcher bar.

So, why is Unity dogged by many as a user interface? My guess is that it is too dumbed down out of the box for users first experience. It required adjustments and the download, installation and configuration of the Unity Tweak Tool before I could truly see the benefits of Unity.

Personally, I cursed using it as a lab operating system for months. After becoming completely frustrated with Unity, I finally allocated the time and effort to dig through forums, man pages and help files to figure out how to better use out of this operating environment. Now I can’t go back to using other systems for this one is working all too well.

How can you set it up?

The first thing you want to do is select System Settings from the app menu in the uppper right-handselection_108 corner of the menu bar. You can also depress Alt + F10 to access the items in the menu bar using the keyboard. Just navigate using your arrow keys to the icon that looks like a gear. A more detailed introduction to using the desktop can be found here.

Once the System Settings window is open, double-click on the Appearance icon.

In the Appearance window, under the Behavior tab put a check into the Enable workspaces box.

unknown_103

Now you will have an icon in your launcher bar that looks like this: selection_104

This icon represents your virtual desktops. By default you have 4 virtual desktops which you can manipulate by using keyboard shortcuts or by clicking on the icon and selecting a different desktop to use.

Okay, how can I get more than 4 virtual desktops?

I am glad you asked that question. Let’s start answering that question by downloading some software to help us out. Lets open a terminal session and type the following:

sudo apt-get update

You will need to submit your password. Then type the following:

sudo apt-get install unity-tweak-tool

selection_105

Depress the Super + A keys to open the Dash App lens and type unity in the search bar:

screenshot-from-2016-10-02-22-16-04

Double-click on the Workplace Settings icon. Here you can adjust the quantity and layout of the your virtual desktops as well as many more items.

selection_106

Note: you can display many keyboard shortcuts available by continually depressing the Super key. Here is a screenshot of the shortcut menu for you:

selection_107

 

Virtual Machines “Inaccessible” after Datastore Outage

Issue

If you ever had to take a NFS datastore down to perform updates on an early release of vSphere 5.1 then you may have seen  (inaccessible) following the grayed and italicized virtual machine name in the vSphere Client.

This is a know issue and is identified in VMware ESXi 5.1u1 release notes as:

Virtual machines residing on NFS datastores are inaccessible in ESXi 5.1 host after vSphere Storage Appliance (VSA) 5.1 exits maintenance mode

The hostd agent reports the status of virtual machines incorrectly to vCenter and the ESXi host after you disconnect the NFS storage as it goes over the Misc.APDTimeout value. This issue is observed on powered off virtual machines.

This issue is resolved in this release.

This issue is commonly seen when an ESXi hosts loses connectivity with an NFS datastore.

Resolution

Methods for correcting the issue is as follows:

Power CLI:

#Get Inaccessible Virtual Machines
$VMs = Get-View -ViewType VirtualMachine | ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"} | select name,@{Name="GuestConnectionState";E={$_.Runtime.ConnectionState}}write-host "---------------------------"
write-host "Inaccessible VMs"
write-host "---------------------------"

$VMs

#Reload VMs into inventory
Get-View -ViewType VirtualMachine | ?{$VMs} | %{$_.reload()}

#Show new state of reloaded VMs
$ReloadedVMs = Get-View -ViewType VirtualMachine | ?{$VMs} | select name,@{Name="GuestConnectionState";E={$_.Runtime.ConnectionState}}

write-host "---------------------------"
write-host "Reloaded VMs"
write-host "---------------------------"

$ReloadedVMs

vim-cmd:

vim-cmd vmsvc/getallvms >grep skip
Skipping invalid VM '118'
Skipping invalid VM '127'
vim-cmd vmsvc/reload [NUMBER] 

Articles Cited:

Using Power CLI: http://blog.mattvogt.net/2013/02/08/vms-grayed-out-after-nfs-datastore-restored/
Using vim-cmd: http://vmdamentals.com/?p=4503
VMware ESXi 5.1u1 Release Notes: https://www.vmware.com/support/vsphere5/doc/vsphere-esxi-51u1-release-notes.html#resolvedissuesstorage

How to disable IE Enhanced Security in Windows 2008

Have you installed Windows 2008 and tried using Internet Explorer only to find that everything that you go to has to be added to an approved list?

Have you installed another browser just to get around this problem?

Well, you probably don’t need to install another browser if you don’t want to because there is a quick way to turn this security feature off.

In the taskbar you can click on the Server Manager icon as depicted below:


In the Server Manager main window under Server Summary -> Security Information you will find a link named Configure IE ESC. Click on Configure IE ESC.

The Internet Explorer Enhanced Security Configuration will appear. This window is where you can shut-off the Enhanced Security feature by clicking the Off radio button for Administrators and/or Users account and clicking OK.

Note – you will need to close and re-open Internet Explorer to see the effects of this changed setting.

VMware I Moved It / I Copied It

The Problem

In our environment we use virtual machines on a nested hypervisor for testing. When clone or move the nested hypervisor virtual machine to another machine, the internal virtual machines all had the icon next to them indicating that they could not power up and needed attention. Upon opening a remote console session to the virtual machine, I am prompted with the following:

Of course this can be rather annoying if you must manually alter the settings for these machines on a large scale.

The Resolution

Found in the VMware KB article  “I moved it” or “I copied it” selection really just specifies whether or not the virtual machines UUID is kept or recreated.

This question can be answered automatically in the virtual machines VMX file.

To always keep the UUID add the following line to your VMX file:

uuid.action = “keep”

Note there are other circumstances that can affect the popup box appearance. I will defer to the VMware KB article for additional explanations regarding specific circumstances.