Writing files to an NTFS volume in OSX using VMware Fusion

This is more of a quick tip than the usual full blog posts I do, but a useful one none the less (at least for me). By default when you plug an NTFS (Windows) volume into an Apple Mac, you are able to read the volume, but not write to it. There are ways to forcefully allow NTFS writes, but for those who do not wish to mess with system settings and are using VMware Fusion, this may come in handy.

  • Make sure your Windows VM is powered on and booted, then your plug external USB drive with the NTFS formatted volume into Mac
  • When prompted, choose to connect the drive to your Windows VM
  • Make sure you have a folder from your Mac shared to your Windows VM (e.g. Documents) through Fusion

 

  • Place any files you would like to write to your NTFS volume in your shared folder on your Mac (e.g. Documents folder)
  • Using your Windows VM, open explorer, navigate to the shared folder presented to Windows via Fusion, find the files you want to copy, and then copy/paste them to your NTFS volume that has been passed through and mounted on your Windows VM
  • As Windows is doing the writing it will of course allow writes to the NTFS volume which has been passed through from the Mac

 

Using plink to modify ESXi host configuration files via SSH from a PowerCLI script

I am a big advocate of automation and saving time with a good script. Whenever I can find a task that is fairly lengthy, and is likely to be repeated in future, I always consider scripting it. There are many way to configure an ESXi host when it comes to writing build or automation scripts. In fact, I often feel we are quite spoilt for choice. Here are just some of the tools we have available to use:

  • PowerCLI
  • esxcli
  • vMA
  • vCLI

I was working on a build configuration script the other day using PowerCLI and found the need to edit some configuration files on the hosts. I wanted to edit the configuration file /etc/vmware/config during the execution of a single PowerCLI script without needing to stop the script or have an additional step to do myself. The following is what I came up with to achieve this:

  • Configure host as normal using PowerCLI
  • Use PowerCLI to start SSH service on host
  • execute plink script to connect to host, run command via SSH, then disconnect
  • Use PowerCLI to stop SSH service on host
  • Continue with rest of PowerCLI script

 

Plink is a command line connection tool – essentially a command line version of PuTTy. You can call it from dos prompt and issue it with a single, (or list) of commands to run once connected to a specified host. You can download Plink over here.

 

So without further ado, let’s take a look at the script as I described above.

# At start of our script we ask for the host's IP or name (this could be automated if you like)
$hostIP = Read-Host "Enter ESX host IP/dns name: "
$vmhost = Get-VMHost $hostIP

# Start the SSH service
$sshService = Get-VmHostService -VMHost $vmhost | Where { $_.Key -eq “TSM-SSH”}
Start-VMHostService -HostService $sshService -Confirm:$false

# Use SSH / plink to configure host with some additional script
cmd /c "plink.exe -ssh -pw HOSTROOTPASSWORD -noagent -m commands.txt root@$hostIP"

# Stop SSH service
Stop-VMHostService -HostService $sshService -Confirm:$false

 

As you can see, we start off by asking for the host IP or name, this is the only bit of manual input, but even this could be automated. The script then finds the SSH service on the host, and starts it. After this, the script calls the plink.exe file via cmd /c and connects using the root user@ the host’s IP as we entered at the beginning of the script over SSH. Plink is pointed to a commands.txt file (previously placed in the script execution folder), which contains the actual lines of bash script to be executed on the ESXi host via SSH.

Here is the content of the commands.txt file that I refer plink.exe to use (as an example, this bit of script enables copy/paste operations on all VMs running on this host in the guest OS’ console, as per VMware KB 1026437), but could contain any other commands you wish to execute on the ESXi host over SSH.

echo 'isolation.tools.copy.disable="FALSE"' >> /etc/vmware/config
echo 'isolation.tools.paste.disable="FALSE"' >> /etc/vmware/config

 

* Note two very useful techniques show by Alan in the comments section below, showing how to automatically download plink.exe if it is not available when the script is run, and also how to accept the SSH fingerprint key request by piping Y to plink.exe via the script – check out Alan’s blog post here for more detail.

UK VMware User Group (UKVMUG)

 

Last week I was lucky enough to be able to attend the UKVMUG, hosted at the National Motorcycle Museum near Birmingham.

 

Wednesday (14/11/2012)

Travelling up early Wednesday evening, I made it to the venue at about 18h45 – just in time for the Veeam sponsored vCurry evening. Here I met up with a few fellow bloggers and local London VMUG members, such as, Jane RimmerJeremy BowmanDarren Woollard, Julian Wood, Steve Bruck, Stu McHugh, and Jonathan Medd amongst others! An excellent vCurry was had along with a drink or two. After that it was back to the hotel in preparation for the UKVMUG the following day.

 

Thursday (15/11/2012)

Registration started at 08h00 with all attendees receiving a welcome pack and VMUG lanyard with their details. Breakfast and teas/coffees were served and everyone had a bit of time to chat before Alaric Davies (of the London VMUG team) opened the proceedings. After this, Joe Baguley did the opening keynote. His keynote was interesting, and generally well received, keeping everyone riveted as far as I could tell.

 

Proceedings were slightly delayed and led to Alaric asking if attendees wouldn’t mind forfeiting the first coffee break – much to the dismay of most, including Simon Long 😀

Throughout the rest of the day, I managed to attend the following sessions:

  • Nimble Storage | Stress-Free Data Protection for VMware and VDI
  • Alan Renouf and William Lam | Practical Automation for Everyone
  • Mike Laverick | Building my vCloud Director Home Lab
  • Duncan Epping and Frank Denneman | Deep-Dive Discussion Group

 

In-between sessions I managed to chat with Automation gurus William Lam, Alan Renouf and Jonathan Medd. Apart from demoing a small little iOS app I have been working on (for my company Xtravirt),  I bounced some ideas off of Jonathan regarding a small mini-project I have been working on to automate vSphere lab environment deployment. I got some useful advice here, especially with regard to deploying vCenter unattended (thanks Jonathan!) It was also great to meet William Lam in person and have a brief chat about the VMware MOB (which I find extremely useful for a project I am currently working on).

I was also interviewed by Steve Bruck for the vNews podcast – they were interested in chatting about vMetrics – so I managed to get a small plug in for my WordPress plugin there.

 

Finally the closing keynote by Scott Lowe was held, entitled “Staying Sharp and Relevant in IT”. This was an excellent session and provided some great insight, ideas and thoughts into learning new technologies or employing techniques to help study new areas for today’s IT pro.

 

After the event was over, Jane Rimmer from the London VMUG team was very kind to invite Darren and I to a small dinner gathering at a nearby restaurant. This was perfect for me as I wanted to avoid rush hour traffic for my drive back home (120 miles or so). We had an excellent dinner and chat with the likes of Jane Rimmer, Simon Gallagher, Alaric Davies, Hans De Leenheer, some ladies from the US VMUG team, and last but not least, Scott Lowe.

 

All in all the event was a success.

Just for fun, I decided to create pie/donut chart representing the number of #UKVMUGYAY hashtagged tweets vs #UKVMUGBOO (good vs bad) – note that some of the “boo” tweets did seem to be playful – i.e. not really showing dissatisfaction! This was a quick and rough calculation by searching for “ALL” tweets on each hashtag and counting them manually – I may have been a couple out here or there 🙂 This is as of tonight (18/11/2012).

 

ESXi 5 Host Backup & Restore GUI Utility updated to 1.1

This little host backup utility I created back in February 2012 has been receiving quite a bit of attention, and has already managed to get over 2000 downloads.

 

Someone recently asked the other day if it was possible to restore a configuration file to a new host (i.e. new hardware). With version 1.0 of my utility, this was not possible due to mismatches that the PowerCLI cmdlet finds (i.e. MAC addresses on NICs etc… on the new hardware when compared to the existing backup). However, the Set-VMHostFirmware cmdlet allows the use of a -Force paramter, so I set about updating the utility to allow for this.

 

Here is a quick list of changes in version 1.1

  • Allows restore to new hardware (tick the “Force restore to new hardware” checkbox). Please note that I have only very briefly tested this on virtualised ESXi hosts – it works, but I am not sure how networking configurations are applied to NICs and differing physical NIC orders – so it is best to test this thoroughly in a dev/test environment before using anywhere else!
  • Tested against single ESXi hosts as opposed to connecting to vCenter first.
  • Updated labels to neaten up a bit – connection box now shows that you can connect to single hosts or vCenter
  • Tested on ESXi 5.1

 

You can download version 1.1 from the same page as before: ESXi 5 Host Backup & Restore GUI Utility

 

 

PowerCLI – script to deploy multiple random VMs

There are probably tons of scripts out there to deploy VMs in a vSphere environment, but I was in the mood for scripting this evening and decided to create my own PowerCLI script to automatically deploy multiple random VMs to my home lab. The point was to create random “content” for something exciting I have been working on 🙂

 

 

[download id=”19″]

 

$i = 1
[int]$NumberToDeploy = 10 # Number of VMs to deploy
[string]$NamingConvention = "homelab-VM-" # Prefix for VM names
[string]$folderLoc = "Discovered virtual machine" # Name of VM folder to deploy into

while ($i -le $NumberToDeploy) {
	$NumCPUs = (Get-Random -Minimum 1 -Maximum 3) #NUM CPU of either 1 or 2.
	$MemoryMB = ("16","32","64") | Get-Random # Get a random VM Memory size from this list (MB)
	$DiskSize = ("256","512","768" ) | Get-Random # Get a random disk size from this list (MB)
	$targetDatastore = Get-Datastore | Where {($_.ExtensionData.Summary.MultipleHostAccess -eq "True") -and ($_.FreeSpaceMB -gt "10240")} | Get-Random
	$targetVMhost = Get-VMHost | Where { $_.ConnectionState -eq "Connected" } | Get-Random # Selects a random host which is in "connected State"
	$targetNetwork = ("VM Network","VM Distributed Portgroup") | Get-Random
	$GuestType = (	"darwinGuest","dosGuest","freebsd64Guest","freebsdGuest","mandrake64Guest",
					"mandrakeGuest","other24xLinux64Guest","other24xLinuxGuest","other26xLinux64Guest",
					"other26xLinuxGuest","otherGuest","otherGuest64","otherLinux64Guest","otherLinuxGuest",
					"rhel5Guest","suse64Guest","suseGuest","ubuntu64Guest","ubuntuGuest",
					"win2000AdvServGuest","win2000ProGuest","win2000ServGuest","win31Guest","win95Guest",
					"win98Guest","winLonghorn64Guest","winLonghornGuest","winNetBusinessGuest",
					"winNetDatacenter64Guest","winNetDatacenterGuest","winNetEnterprise64Guest",
					"winNetEnterpriseGuest","winNetStandard64Guest","winNetStandardGuest","winNetWebGuest",
					"winNTGuest","winVista64Guest","winVistaGuest","winXPPro64Guest",
					"winXPProGuest") | Get-Random
	$VMName = $NamingConvention + $i

	if ((Get-VM $VMName -ErrorAction SilentlyContinue).Name -eq $VMName) {
		Write-Host "$VMName already exists, skipping creation of this VM!" -ForegroundColor Yellow
		}
	else {	
		Write-Host "Deploying $VMName to $folderLoc ..." -ForegroundColor Green
		#Create our VM
		New-VM -Name $VMName -ResourcePool $targetVMhost -Datastore $targetDatastore -NumCPU $NumCPUs -MemoryMB $MemoryMB -DiskMB $DiskSize `
		-NetworkName $targetNetwork -Floppy -CD -DiskStorageFormat Thin -GuestID $GuestType -Location $folderLoc | Out-Null
		}
	$i++
}

 

This script will automatically deploy a variable number of Virtual Machines, based on a certain naming convention you specify. It’ll also randomly choose VM settings. Here is what it does:

 

  • Deploy any number of VMs by changing the total number of VMs to deploy (specify in script as $NumberToDeploy)
  • Deploys each VM to a random ESXi host which is in a connected state
  • Deploys each VM to a random shared datastore (i.e. a datastore with multiple hosts connected)
  • Sets a random vCPU count to each VM (specify options in the script as $NumCPUs)
  • Sets a random Memory size for each VM (specify options in the script as $MemoryMB)
  • Create a virtual disk as thin provisioned on each VM with a random disk size (specify disk size options in the script as $DiskSize)
  • Adds each VM to a random VM network (specify VM network options in the script as $targetNetwork)
  • Specifies a random GuestOS type for each VM deployed
  • Creates each VM in a specified VM & Templates folder (specify in script as $folderLoc)

 

All options are already set to defaults in the script as is stands, but don’t forget to change important options unique to your environment like the $folderLoc (folder to deploy VMs into), and the list of VM networks ($targetNetwork). Other items are automatically determined (datastore and host to deploy to for example).

Also note that some of the built-in guestOS types might not be supported on some ESXi hosts. In these cases, the script just skips creating that VM and moves onto the next. You may see a red error message for the failed VM in these cases. For a full list of GuestID types, check out this page.