Saturday, June 26, 2010

Converting VMWare server 2.0 images to hyper-V R2

After several attempts with different combination of offline/online conversions, I've finally found a fairly consistent method of converting VMWare Server 2.0 images to Hyper-V R2 images. SCVMM R2 has native support for ESX servers but not the low end free Server 2.0 edition so it requires more effort to get that working.

Software used:
  1. VMWare Server 2.0
  2. Hyper-V R2
  3. SCVMM 2008 R2

Conversion requirements:
Windows 2003 - must have SP2
Windows 2008 preferably at sp1
WinXP should be at SP2/SP3
Vista preferably at SP1
Win7 RTM is fine
Windows 2008 R2 RTM is fine

Step 1:
You must uninstall vmware tools! This has to be done while running the image
on a vmware product (i.e. server, workstation, player). Just go into Add/Remove programs and remove it from there. I can't stress enough how important it is to get this uninstalled before conversion.
Note: By doing this, the machine will lose it's static IP settings if one is set.

Step 2:
Copy image to SCVMM R2 library folder
Wait a few minutes for SCVMM to refresh the library.

Step 3:
From the library view in SCVMM, right click on the VM and choose Convert Virtual.
From there follow the wizard.



Step 4:
After conversion occurs, go into the settings for the image in the Hyper-V console and confirm that a network card has been assigned. If not, add one. The first time you boot you may find that some services fail because the network card hasn't been detected yet. This should go away on the next reboot after you add the network card.



Step 5:
Boot the new image. Log into it and install the Integration components if they are missing.



Step 6:
Test to make sure your newly converted image is working properly.

Optional Step 7:
Compact the newly created VHD disks. This can free up a lot of wasted space. If you started with Static sized disks, the conversion process will have converted them to Dynamic sized disks. In Hyper-V R2 they supposedly fixed a lot of performance differences for dynamic vs static so it should be fine.



Now you should be all done.

Thursday, June 3, 2010

PHP - trimming off characters after the last slash in a URL

I really don't like programming. But every once in a while you've got to break down and do it for special projects. Recently I had to write some PHP code for a specific situation where I needed to be able to take the current URL the script was running at, strip out the script name, strip out the last slash and the directory name that proceeded it. Effectively, I was simulating ../ on the path because security requirements were getting in the way of a script. I played around with rtrim(), dirname(), regular expressions, etc but just wasn't quite getting the result that I wanted. My script determines the current URL, explodes it into a string array spliced at each slash character, then builds the new URL in a loop. You can tweak the iterations of the loop for however many directory levels back you want to go.

<?php
# Using SCRIPT_NAME

$path = $_SERVER['SCRIPT_NAME'];
$path2 = "/";
$domain = $_SERVER['HTTP_HOST'];

#echo "current path: " .$path . "<br>";
$parts = explode("/",$path); // splice by slash

$i=1; // skip zero cuz it's empty
$endi = count($parts) - 2; // number of parts minus 2 hierarchy

while ($i < $endi) {
$path2 = $path2 . $parts[$i] . "/";
$i++;
}
$temp = 'http://' . $domain . $path2;
echo $temp;

?>



Example:
If you run the above code and your original URL was http://www.test.com/blue/test.php
the output would be http://www.test.com/