- Oct 22, 2007 by the_angry_angel
- Geek, Windows and Work
At work we use Microsoft Virtual Server 2005 a fair bit. In some circumstances, particularly when running a Windows guest, the virtual hard disks can grow exceedingly quickly. Thankfully, there is a provided set of tools to help with this problem. A precompactor and a compactor. You run the precompactor to zero out the free diskspace, you then pause or shutdown the virtual machine and run the compactor.
This is all well and good, unless the virtual machines are running in a production environment and you need to do this at 2am in the morning. Like hell do I want to stay up for that, especially as each stage can take some time, depending on the load on the virtual server host.
Also thankfully it's possible to automate this behaviour (thanks to David Wang, this script is heavily based on his existing work)!
- Copy or make the precompactor available to each virtual guest that you wish to compact
- Schedule the precompact to run using Scheduled Tasks, within each virtual server guest. Allow for at least 2 hours, depending on the size of the disk(s). "precompact.exe -Silent -SetDisks:cde" would automatically, and silently, compact drives C, D and E. Ammend or script as appropriate.
- In the virtual server host you then setup a Scheduled Task to run the script below. "cscript path\to\server\filename.js", ensuring that you edit strServer and arrVMNames as appropriate, and that you leave enough time for all the precompacting to complete
Ensure that the script is run by a user account with the correct privileges.
// Automated VHD compacting
// Heavily based on a script by David Wang, http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx
// Usage:
// Edit the strServer and arrVMNames variables below, as appropriate
// Schedule "precompact.exe -Silent -SetDisks:cde", where "cde" are the drives to run the precompact against,
// to run a few hours before this script, inside the virtual machines
// Then on the host machine, schedule this script to run (command below), ensuring that there's enough
// time for the precompact to have finished
// "cscript automated-vhd-compact-custom-multiple.js"
// definitions
// amount of time, in milliseconds, that the script should sleep
var GUEST_OS_SLEEP_RESOLUTION = 250;
var ERROR_FILE_NOT_FOUND = 2;
var CLEAR_LINE = String.fromCharCode( 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 );
var VM_STATE_OFF = 1;
var VM_STATE_SAVED = 2;
var VM_STATE_RUNNING = 5;
var VM_STATE_PAUSED = 6;
// Config
// server that Microsoft Virtual Server 2005 is running on
var strServer = "localhost";
// array of names - each virtual machine you wish to compact
var arrVMNames = ["Standalone - Xenon - XP", "Webserver - Tungsten - 2003 Std"];
var objVS = new ActiveXObject("VirtualServer.Application", strServer);
for (var i = 0; i arrVMNames.length; i++)
{
var objVM = objVS.FindVirtualMachine(arrVMNames[i]);
var task;
if (objVM == null)
{
LogEcho("Virtual Machine " + arrVMNames[i] + " was not found on server " + strServer);
Quit(ERROR_FILE_NOT_FOUND);
}
LogEcho("Selected Virtual Machine " + arrVMNames[i] + " on server " + strServer);
if (objVM.State != VM_STATE_RUNNING)
{
// if the VM wasn't running, then the precompact didn't run,
// therefore there is no point in even running the compact
LogEcho(arrVMNames[i] + " is not running");
continue;
}
LogEcho("Saving VM...");
task = objVM.Save();
WaitForTask(task);
LogEcho("Compacting VHDs");
var enumHardDiskConnection = new Enumerator(objVM.HardDiskConnections);
var objHardDiskConnection;
var objHardDisk;
while (!enumHardDiskConnection.atEnd())
{
try
{
objHardDiskConnection = enumHardDiskConnection.item();
objHardDisk = objHardDiskConnection.HardDisk;
LogEcho("Compacting " + objHardDisk.File);
task = objHardDisk.Compact();
WaitForTask( task );
}
catch (e)
{
LogEcho(FormatErrorString(e));
}
enumHardDiskConnection.moveNext();
}
LogEcho("Compact done!");
LogEcho("Starting up" + arrVMNames[i]);
task = objVM.StartUp();
WaitForTask(task);
LogEcho("Startup done!");
}
LogEcho("Done!");
function Quit(errorNumber)
{
WScript.Quit(errorNumber);
}
function LogEcho(str)
{
WScript.Echo(str);
}
function FormatErrorString(e)
{
return e.number + ": " + e.description;
}
function WaitForTask(task)
{
var complete;
var strLine = "";
var cchLine = 0;
while ((complete = task.PercentCompleted) <= 100)="" {="" strline="CLEAR_LINE.substring(" 0,="" cchline="strLine.length;" )="" +="" complete="" "%="" ";="" this="" should="" not="" exceed="" clear_line="" wscript.stdout.write(strline);="" if="" (complete="">= 100)
{
// delete the % display so that next line is clean.
WScript.Stdout.Write(CLEAR_LINE);
break;
}
WScript.Sleep(GUEST_OS_SLEEP_RESOLUTION);
}
}
- Oct 21, 2007 by the_angry_angel
- Geek and Unix-like
One of the technical questions I had at Blizzard was pertaining to locking down access to a file(s) so that only a given user could download them. I creatively suggested an SSL'ed vhost and some form of auth to get to the file(s). When asked about scp, I stated that scp required a valid shell, which isn't always desired. This means that they can logon to the box.
This has been bugging me since yesterday, as it's a bit of a hack. What if you have a centralised auth system and can state which shell to use? There must be some way to only allow scp. Having done some research, it appears that there is! Enter "scponly". The only downside is that they'd need somewhere to logon to, in order to change passwords in the instance(s) of password expiry, should you wish to go down that route. Perhaps, in this case, it's better for a sysadmin to track and perform account changes though.
- Oct 19, 2007 by the_angry_angel
- Geek, Personal and Work
I started typing this on one of Charles de Gaulle's (CDG) web terminals, only to find that they are the most repulsive device in history. What on earth were they thinking with those keyboards? No tabs? Poor web browser. They maybe designed for heavy use, but they're bollocks - if you're ever there, don't waste your money.
So. Rant over. The big day! I left home for Bristol airport at 4am this morning and got there in one piece to discover that there was a cock up / miscommunication with the booking. In short to even get a flight I had to buy another ticket. I shall be calling easyJet about this Monday. I arrived at CDG in France and picked up my car, a horrible little Peugeot 107 diesel with no grunt. I then proceeded to drive in the wrong direction. 2 hours later I was back at CDG and had come to the conclusion that there was no way I'd manage to do this by myself, with no satnav, in a country I've never been in before, where traffic was up to 10x heavier (thanks to the public transport strikes). I decided to get a taxi - I'm very, very pleased I made this decision as I barely made it in time, with someone who knew where they were going. By this point I'm about £300 up on my original expenses. This is not good and I'm really dreading looking at my bank account at the moment :(
I arrived at Blizzard's building at about 1:45pm and wasn't entirely sure it was the right place. There was a simple logo inside the ground floor. I went up anyway only to be presented by a pair of large, gray, metal doors. I got buzzed in and was slapped with a NDA which I was required to sign, so this unfortunately means that I can't really talk too much about what I saw :( Their offices are very, very nice in comparison to the rest of the building, and it was like walking into a bright sunny day, after months of rain and storm clouds. It was immaculately clean and well kept, and very modern. All locations off the main reception were electronically sealed, and yes as people have said, they do have trophies and statues in reception! The interview lasted about 2 hours, roughly, and was pretty informal and I met a range of people that the person who gets the position will be working with. They all seem like a really cool bunch of down-to-earth individuals, which is pretty cool :D I get to hear the news in a few days / weeks :)
I made my way back to CDG, again via taxi which the lovely Hotel Inn receptionist got for me (the French people are generally quite friendly it seems). Whilst I was waiting for the taxi I had the opportunity to have a wander around Velizy. It's not the greatest place in the world, to put it politely. The traffic on the way back was horrendous, but I was there in plenty of time and I just tried not to nod off in check-in and boarding. Thank you screaming kids. You really helped.
Do I think that all the extra cash was worth it? Hell yeah! I might never get this opportunity ever again - I've seen a small part of the internals of a prominent games company and I've driven through Paris. Plus it's only money at the end of the day; as long as I have enough to survive next month, whatever happens, then it was money well spent.
- Oct 07, 2007 by the_angry_angel
- Multimedia
I went to Chris' at the weekend, and we went to see The Kingdom. Bloodly good film, and I encourage you to see it. Granted it is a little political, and it is a little 'out there' from time-to-time, but it is well filmed and a pleasure to watch.
Unlike the longest 103 minutes of your life that is War. Honestly, I nearly fell asleep several times during War and I was wondering what I could've rather spent the time acheiving. I did come up with the following;
- Sorting my email
- Setting up and using Bzr to replace my SVN repo
- Cleaning the car
- Running around the house and pretending to be a bee
- Staring wildly out of my window at my neighbours
- Oct 07, 2007 by the_angry_angel
- Geek, Personal, Work and Mindless Hatred
So I got a second phone interview from one of the technical guys at Blizzard, and I got a chance to ask a few questions about what I'd be dealing with, what my responsibilities would be and so on. Long and short of it is that I've been asked to go to France to see them in-person. Fantastic.
Unfortunately the whole problem (photo trouble, apparently) with the passport has only been compounded by the fucking postal strike. I'm sorry, but most employees don't stop fucking working because they want a payrise for doing their job. Ok, so maybe they aren't being paid enough, but because this country is ridiculously backwards, from time to time, and we rely on an un-fucking-reliable public service I might miss out. I'm sorry, but the lack of redundancy here worries me.
Tomorrow I'm going to phone the UKPA (UK Passport Agency) and see if I can get a passport renewal in-person at the Newport passport office. Surely it won't take as long as waiting for the pissing postal service to get off their big arses. Honestly, if I tried this I'd be fired. What's bloodly different? There are plenty of unemployed and I'm sure that the possible lack of a job might encourage some to come back to work.