Archive

Archive for the ‘Virtualization’ Category

Hyper-V Server and a UPS

February 17th, 2010

Microsoft’s Hyper-V Server 2008 R2 can be a great hypervisor choice for a small business with just one or two servers.  In this environment though the common power protection scheme is going to be a single, direct-connected UPS with a USB signaling cable.  In this scenario we need to be able to safely shutdown the hypervisor and guests before power gives out.

I claim no original thoughts here, but I did want to preserve a link to a good answer I found and have implemented.  The original thread is here on the Technet Forums.

First create ups-shutdown.vbs and load it with:

set wmi = GetObject(“winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2″)
set batteryColl = wmi.ExecQuery(“select * from Win32_Battery”)
set osColl = wmi.ExecQuery(“select * from Win32_OperatingSystem”)

while true
for each battery in batteryColl
battery.Refresh_
if battery.batteryStatus = 1 and battery.EstimatedChargeRemaining <= 40 then
for each os in osColl
os.Win32Shutdown 1
next
end if
next
wscript.Sleep 15000
wend

Schedule this to run at startup using the Task Scheduler.  (Connect from another machine and set this up.)

Next create ups-monitor.ps1 and insert:

# Initialize Variables
# Shutdown threshold at 50% of remaining UPS capacity
$threshhold = 40
$interval = 60
$OnBattery = 0
$Event = 0

$hostname = hostname

# Create SMTP client
$Server = “mail.xxxxxxxxxxxx.com”
$Port = 25
$Client = New-Object System.Net.Mail.SmtpClient $Server, $Port

$Client.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

$To      = “admin@xxxxxxxxxxxx.com”
$From    = “hyperv@yyyyyyyyyyyy.com”

# Loop on Battery Query
while (1)
{
$bat = get-wmiobject -class CIM_Battery -namespace “root\CIMV2″
$batstatus = $bat.batterystatus
$batcapacity = $bat.estimatedchargeremaining
$timetoshutdown = $bat.estimatedruntime/2

if ($batstatus -eq 1)
{
$Event = 1
$OnBattery = 1
# “On Battery”

$Subject = “Utility Power Failure: {0} is running On UPS Battery” -f $hostname
$Body   = “UPS at {0} % remaining capacity, approximately {1} minutes before {2} shutdown.” -f $batcapacity, $timetoshutdown, $hostname

if ($batcapacity -lt ($threshhold +5) )
{
$Body = “Shutdown imminent at {0} %, with ” -f $threshhold + $Body
}

}

elseif (($batstatus -eq 2) -and ($OnBattery -eq 1))
{
$Event = 1
$OnBattery = 0
# “Power Restored”

$Subject = “Utility Power Restored to {0}.” -f $hostname
$Body   = “Battery at {0} % capacity. UPS charging… ” -f $batcapacity
}

if ($Event -eq 1) # Create mail message
{
$Event = 0
$Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
$Message.Priority = [System.Net.Mail.MailPriority]::High
try {
$Client.Send($Message)
# “Message sent successfully”
}
catch {
“Exception caught in UPS_Monitor.ps1″
}
}

sleep $interval
}

Change the mail server, to and from address, and you’re in business.

Create ups-monitor.cmd with the following:

powershell -command c:\path\to\your\script\ups-monitor.ps1

Again using Task Scheduler, schedule ups-monitor.cmd to run at startup, and you’re set.

Make sure you have your VMs set to save at shutdown and autostart, and then go pull the plug on that UPS just to make sure things work to your liking.

Also from the above referenced thread, you can check the battery condition using powershell with this:

PS$ get-wmiobject -class CIM_Battery -namespace “root\CIMV2″

Have fun.

Hyper-V, Virtualization, Windows Server 2008

Windows Server Backup WBAdmin

February 14th, 2010

I was just setting up a Hyper-V Server 2008 R2 box and wanted to get backup running to an external drive.  I installed the Windows Server Backup role via the Core Configurator tool, but then the backups need to be configured and run via the wbadmin command line tool.

This command line reference for wbadmin was helpful so I wanted to mark it in case I need it again in the near future.

Hyper-V, Virtualization, Windows

Links of Interest

February 3rd, 2010

Virtualization Benefits for Small Business

Coalescing a few links I’ve been keeping up with for further reading:

A Virtual Door Opens for SMBsA Virtual Door Opens for SMBs

Other, Virtualization

Disk2vhd P2V Tool for Microsoft Virtualization

November 10th, 2009

This post is mostly a note to myself.  I haven’t tried this yet, but the Disk2vhd tool from Sysinternals is for P2V for Microsoft virtualization such as Hyper-V.

When I get to try this out, I’ll post some notes about using it and how it stacks up against something like VMWare Converter.

Hyper-V, Virtualization

Copy Virtual Machines on VMWare Server 2

May 12th, 2009

This is a simple note to capture process.

  • On the VMWare server, copy the guest’s directory to a new name.
    • cp -ax /vm/srv1 /vm/srv2
  • Rename the vmdk disk image
    • cd /vm/srv2
    • vmware-vdiskmanager -n srv1.vmdk srv2.vmdk
  • Rename the other files
    • mv srv1.* srv2.*
  • Open the VM configuration and change the names there
    • vi srv2.vmx
    • :%s/srv1/srv2/
  • In the VMWare host’s web console, use the Add Virtual Machine to Inventory to add the new VM.

VMWare

Windows Server 2008 in VMWare

April 9th, 2008

I just loaded up Windows Server 2008 into a VM under VMWare Server. I’ve installed one VM as a full load of the OS, and I’m preparing to install a second VM as the “server core” load of 2008 (basically no GUI). To my surprise, it’s gone very well so far. There was only one snafu, and that was easily fixed with a trip to the Google oracle. When the VM first came up, it had no recognized network card. To get a working NIC, add the following to your .vmx file:

ethernet0.virtualDev = “e1000″

Restart the VM, and you’re off to the races.

VMWare, Windows, Windows Server 2008

VMWare Server, MythTV, and Kubuntu

September 2nd, 2007

Having recently acquired a Windows Vista PC for my own personal learning, I find that my Windows XP box is now irrelevant. It is a Dell Optiplex GX 280 (about 2 years old) that I would like to use as a MythTV back-end server and a VMWare Server host. To facilitate this, I picked up a 500GB Western Digital SATA drive. My intention is to install Kubuntu 7 Feisty Fawn, setup an LVM partition to carve out storage for video and VM images, install VMWare Server, and install MythTV.

The first step to getting the base OS up and running is to simply boot the Kubuntu live CD and then kick off the installer. I pretty much ran the defaults except for the disk setup. I setup a 50GB / partition with ext3 and a 2GB swap. I left the other ~450GB unpartitioned to hold an LVM volume later.

After the first reboot I noticed the video wasn’t optimum – 1024×768 from an ATI Radeon X300. I followed this wiki entry to get it running right.

Next on the docket would be LVM. First I need to install LVM:

  • sudo apt-get install lvm2

Also, I would like to have XFS support for use where I store video files.

  • sudo apt-get install xfsprogs

With LVM support installed, I used the article Learning Linux LVM, Part 2 to help go through the following:

  • sudo sfdisk -l turned up this:

Disk /dev/sda: 60801 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sda1 0+ 6078 6079- 48829536 83 Linux
/dev/sda2 6079 6327 249 2000092+ 82 Linux swap / Solaris
/dev/sda3 6328 60800 54473 437554372+ 8e Linux LVM

That looks right. I’ve got a 50GB / partition on sda1, a 2GB swap on sda2, and the rest in sda3 set as LVM type. Let’s get using it.

  • sudo su
  • pvcreate /dev/sda3
  • vgcreate -s 32M main /dev/sda3
  • lvcreate -L150G -nvm main
  • lvcreate -L250G -nvideo main
  • mkreiserfs /dev/main/vm
  • mkfs.xfs /dev/main/video
  • mkdir /vm
  • mkdir /video
  • mount /dev/main/vm /vm
  • mount /dev/main/video /video

Next, add the two new partitions to the /etc/fstab file to mount at startup. A reboot confirms that all is well with the new partitions.

Next, we move on to getting VMWare Server installed and running on this box. During this portion, I used How To Install VMware Server On Unbuntu 7.04 (Feisty Fawn) as a good reference to getting this done.

First, we do some prep:

  • sudo aptitude install linux-headers-`uname -r` build-essential
  • sudo aptitude install xinetd

Then grab the current VMWare Server tar ball. (This was done with VMware-server-1.0.3-44356.tar.gz.) Also, grab this patch file vmware-any-any-update109.tar.gz.

  • cd /usr/src
  • tar -xzf VMware-server-1.0.3-44356.tar.gz
  • cd vmware-server-distrib/
  • ./vmware-install.pl
  • Accept the defaults until the prompt to run vmware-config.pl to which you answer no
  • tar -xzf vmware-any-any-update109.tar.gz
  • cd vmware-any-any-update109
  • ./runme.pl
  • Let it run the vmware-config.pl script
  • Accept the EULA and the defaults unless you want an override.
  • For example, this install I answered No to NAT networking as I just want a bridged connection.
  • I changed the directory for keeping virtual machine files from /var/lib/vmware/Virtual Machines to just /vm to use the LVM volume
  • Enter a serial number for VMWare Server
  • Verify the script successfully starts the services
  • Launch the VMWare Server Console via the vmware command

At this point, the system should be ready to create new virtual machines, but that’s a topic for another post.

Next, we will tackle installing MythTV on this system. I have previously setup a freestanding MythTV box to test it out. That system was an old spare PC when I started, but it did run successfully for a year and a half as my home DVR. Eventually it gave out, and now I would like to setup a replacement for it. This time I intend to setup this system as a MythTV backend system to do the recording and then setup another system as a front-end for viewing.

As a guide in this process I used this page from the Ubuntu Community Documentation.

This system has a Hauppauge PVR-250 tuner card in it, and it looks to be correctly loaded by default.

As the documentation page I’m referencing points out, we only need one package for this configuration — mythtv.

  • sudo su
  • apt-get install mythtv
  • vi /etc/mysql/my.cnf
    • comment out the bind-address 127.0.0.1 line
    • :wq
  • /etc/init.d/mysql restart
  • exit (to drop out of root context)
  • mythtv-setup
  • Click Yes to be added to the mythtv group
  • Enter password for sudo
  • Click Yes to restart your session
  • Login again
  • mythtv-setup
  • Click Yes
  • Enter password for sudo
  • Choose English
  • General
    • Set IP address of local system
    • Set directory to hold recordings to /video
    • Increase max simultaneous jobs to 2
    • Enable auto-commercial flagging jobs when the recording starts
  • Capture Cards
    • New capture card
    • Card type: MPEG-2 encoder card (for my PVR-250)
  • Video Sources
    • New video source
    • Source name: Bright House Cable
    • Enter username and password for zap2it labs account
  • Input Connections
    • Setup Tuner1 for CableTV
  • Channel Editor
    • No changes
  • Exit mythtv-setup
  • Click Yes to run mythfilldatabase
  • mythfrontend

That’s it. At this point, the system is up and running Kubuntu 7, VMWare Server, and MythTV. Stay tuned for more posts about putting this platform to use.

Kubuntu, Linux, MythTV, VMWare