Pages

Wednesday, June 29, 2011

Set vino (Gnome Remote Desktop Settings) from the command line

Trying to configure Linux VMs for students today i found it was difficult to configure the Remote Desktop Settings from a script. I finally found the information in other places but it was spread out and difficult to find. By default the Remote Desktop found in many distro's can be configured graphically under Preferences -> Remote Desktop.

However to configure it from the command line you must run the following as root.

gconftool-2 --set --type bool /desktop/gnome/remote_access/enabled true
gconftool-2 --set --type list --list-type string  /desktop/gnome/remote_access/authentication_methods '[vnc]'
gconftool-2 --set --type bool /desktop/gnome/remote_access/prompt_enabled 0
gconftool-2 --set --type string /desktop/gnome/remote_access/vnc_password $Base64encodedPassword

The $Base64encodedPassword is just a base64 encoding and its easy enough to do.

Links

Tuesday, June 28, 2011

How to SSH from PowerShell using Putty/Plink

Today working with my brother we needed to automate some administration of some Linux VMs for Students. The goal was simple enough, in a PowerShell script create the Linux VMs, Power it on and then SSH into it to configure Linux and create student account on their VM.

Its an odd project that is sort of last minute but we think we can script a solution for the college faculty. One of the assumed easy features of this plan was to SSH into the Linux VM from PowerShell. But surprisingly their didn't a appear to be any easy solutions. The two options available appeared to be:

SharpSSH - I tried to use it but could only get the following error:

Exception getting "formatValueList": "Microsoft.PowerShell.Commands.Internal.Format.FreeFormatEntry.formatValueList"

And /N Software NetCmdlets which is a paid solution i don't have access to and didn't find very good usage on. Lastly I found that it appears best to use plink.exe. Plink comes with putty and is the command line only version of putty. The result being you can pipe your command and through plink however you first have to accept to trust the host key. That a problem because despite all my attempts I couldn't find a command parameter to allow it to accept the host key. Here is the prompt.

C:\Program Files (x86)\PuTTY>plink -ssh username@host -pw password  
The server's host key is not cached in the registry. You ave no guarantee that the server is the computer you think it is.  
The server's rsa2 key fingerprint is:  
ssh-rsa 2048 8e:39:5f:6e:6d:80:77:50:6e:39:b0:c1:13:98:ab:c1 
If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the connection. 
Store key in cache? (y/n)  

However I worked out a solution, it isn't pretty but it works well.

Using " Echo y " and piping that to the plink it will accept the host key, but keep entering y over and over. The solution is to then pass the command exit to plink which will logout the ssh session the second it gets logged in. With that the host key is cache and trusted. How simply plink again with out the "echo y"

ehco y | plink -ssh username@host -pw password exit

plink -ssh username@host -pw password ls

Below is the PowerShell script that will allow you to pass multiple SSH commands at once. Comment if you have questions or ways to improve this.

test

Function Invoke-SSHCommands {
 Param($Hostname,$Username,$Password, $CommandArray,
  $PlinkAndPath,
  $ConnectOnceToAcceptHostKey = $true)

 $Target = $Username + '@' + $Hostname
 $plinkoptions = "-ssh $Target -pw $Password"

 #Build ssh Commands
 $CommandArray += "exit"
 $remoteCommand = ""
 $CommandArray | % {
  $remoteCommand += [string]::Format('{0}; ', $_) 
 }

 #plist prompts to accept client host key. This section will
 #login and accept the host key then logout.
 if($ConnectOnceToAcceptHostKey)
 {
  $PlinkCommand  = [string]::Format('echo y | & "{0}" {1} exit',
   $PlinkAndPath, $plinkoptions )
  #Write-Host $PlinkCommand
  $msg = Invoke-Expression $PlinkCommand
 }

 #format plist command
 $PlinkCommand = [string]::Format('& "{0}" {1} "{2}"',
  $PlinkAndPath, $plinkoptions , $remoteCommand)

 #ready to run the following command
 #Write-Host $PlinkCommand
 $msg = Invoke-Expression $PlinkCommand
 $msg
}

$PlinkAndPath = "C:\Program Files (x86)\PuTTY\plink.exe"
$Username = "remoteshell"
$Password = "pa$$w0rd"
$Hostname = "Linuxhost"

$Commands = @()
$Commands += "ls"
$Commands += "whoami"

Invoke-SSHCommands -User $Username  `
 -Hostname $Hostname `
 -Password $Password `
 -PlinkAndPath $PlinkAndPath `
 -CommandArray $Command

Wednesday, June 8, 2011

OleAut date did not convert to a DateTime Correctly

Some times I at least make stupid mistakes that generate errors that don't generate any search results in Google.

Today this happened while porting to C# a Powershell script I had written that generates some Charts showing VMware View statistics. While trying to use "DataManipulator.InsertEmptyPoints"  I have the following code:

Chart_ViewSessions.DataManipulator.InsertEmptyPoints(1, IntervalType.Hours, "*");

When Run in debugger it was throwing the following System.ArgumentException.

"OleAut date did not convert to a DateTime correctly."

I tested the Powershell and it runs fine so searched Google but nothing with that error really came up. If I  comment the line out and everything runs but doesn't stack the columns correctly as the Chart is a StackedColumn. After about 10 minutes with no luck i finally realize I added the data points after the I had called InsertEmptyPoints. The problem all along was because I had it trying to Convert a DateTime on No Data Points.

So here a reminder to stop and think about the order your doing things if the error doesn't make sense.

Tuesday, June 7, 2011

Using Local Solid State Drives to provide VMware View Storage

While Implementing Vmware View on campus we're looking at what hardware and storage to use or purchase. In our current Vmware environment we have a mixture of technology due to migration from one to another.
  • Server Hardware:  we currently have a mixture of Large Dell and IBM hosts and half a rack of Cisco UCS.  
  • Storage Hardware: we have/had IBM sans, EMC sans, Equallogic, and now IBM N Series (read Netapp with out support).
Note: You would think the answer would be simple, just use the NetApp with the PAM cards it has but we've had very bad performance  and currently a 4 Month Support call with IBM with no solution in sight. So such we're not wanting to add to the IOPS load of the Netapp.

Our View Enviroment looks to be growing to the 1000 VM Range however these are non-persistent VM's that are refreshed on logoff for student use.

While researching Pivot3's vBank I started researching Solid-State Storage(SSD) for VMware figuring anyone trying to speed up the IOPS for Vmware View was just going to stick the Replica on a SSD anyway and ideally a SSD local to the VMware host. 

This lead me to reading Brian Madden's Post on the pretty much my same conclusion on View and SSD's. Anyway a commenter on his post, Lance Hundt, gave a link to VMware Reference Architecture for Stateless Desktops. Following that Document I found a more detailed really great Vmware PDF on how to actually do this with Local Solid State Drives. 


Once you read this it because so clear, but the normal Vmware ESX mental rules get in the way. Normally Local  ESX storage is useless, we don't use it nor want it. This idea flips that on its head.

If you only had local really fast SSD's for storage everything would be really really fast. However the SSD's don't have much storage space because their two expensive. Not a problem however because the Stateless VM's are replica's and don't use much space. The idea seems sound to me but there is a added management cost when you take a host down and put it in maintenance mode, you first have to do some manual housekeeping.

I wish I provide more detail on this but I haven't been able to talked to anyone doing this yet but would be curious if any has. I'll update this post if I put together some SSD's to try it with and update this post if I do.



Friday, June 3, 2011

VMware View Composer has a maximum of 8 Hosts Per Cluster

Last week we added some Cisco UCS Hosts to our Vmware environment with out any real problems. Then today using Vmware View tried to compose some additional View VMs.

Instead of provisioning them I instead get the following error.


VMware.Sim.Fault.TooManyHostsInComputeResourceFault: Resource pool MoId = resgroup-133, cluster MoId = domain-c132, numHosts = 16, maxHosts = 8

Looking into the VMware.Sim.Fault.TooManyHostsInComputeResourceFault I find a Vmware forum post stating that "The limitation is around Composer and you can only  have a maximum of 8 Hosts per Cluster".  Hoping this was simply a mistake or changeable I looked into it further. It seems to be unchangeable rule that you have to deal with.


From this Vmware Admin Guide they state that the cluster must have 8 or fewer hosts.

NOTE   Only clusters of 8 hosts or fewer are supported and shown.

Links

Wednesday, June 1, 2011

Switching Windows 7 Build to use AHCI

This is a common problem but I figured I reference in order to switch a Windows 7 image from using the PCI IDE Controller driver to using AHCI boot driver.

If your image, (Ghost or otherwise) boots and starts windows loading then reboots. That or it may come up with the blue screen error code 0×0000007B. Which one it comes up with depends on if the BIOS is set to AHCI drives or SATA.

This can be caused by incorrect Hal but it may be be the Driver. If you have the original machine you pulled the image from make this change to the AHCI change in the registry.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\msahci]
“Start”=dword:00000000



HOW TO: Switch to AHCI boot driver in Windows 7 after install

Then repull that image and push to the hardware before that had issues loading it.

Details
In my case a Windows 7 Ghost image made for a Dell GX620 would boot when cloned to a GX760. I deployed the image to a VMware VM with an IDE drive, made the registry change listed above, pulled a image of it and deployed it to the GX760 which now boots correctly but needed additional drivers.

Modifying the Registry on the machone already imaged.
I'm not sure if this works but I worked out from this link that it may be possiable to simply use the recovery console to load the registry hive on the not booting drive.


  • Using Recovery Console get the a Command Line Prompt
  • Open the registry editor: regedit
    • Note: This loads the registry editor with a temporary registry, not the windows registry from the hard disk.
  • Select HKEY_LOCAL_MACHINE in the registry tree, and go to the File menu and choose "Load Hive"
  • Open the registry hive file SOFTWARE from the location: C:\Windows\System32\Config
    • Give it a random name different to any of the existing names (the name doesn't matter).
  • Make the necessary changes to the registry hive.
  • Select the registry hive you edited, go to File, and choose "Unload Hive".
  • Then exit the recovery console and restart. The registry should have been changed.