Shrink your Windows disk image on VMWare Fusion (Mac)

March 31, 2008 by

It is possible to free up quite a bit of hard disk space by compacting your virtual disks for VMWare.

Here is a easy (manual) way to shrink a Windows guest image hosted on VMWare Fusion for Mac OS. I have used the recipe below to successfully save about 50% of disk space for a Windows 2003 R2 guest image on Mac OS 10.5.2 running VMWare Fusion 1.1.1. Other Windows guest OS’s like Windows 95, 98, NT 4.0, Win2K, XP should work with this recipe as well, although this is untested at this time.

Warning: This recipe may/may not work for you. Beware of the risk! Remember to backup your disk image before messing with it. Finally, do not shrink a disk with snapshots as this is known NOT to work!! Update: See additional recipe at bottom of this post for how to deal with snapshots.

Shrink recipe:

  1. First backup your guest os disk image and other files (just in case something goes wrong) + make sure you have plenty of spare disk space on your harddrive.
  2. Start Windows guest OS in VMWare Fusion and login as administrator
  3. Clean up & defrag guest OS disk image from within guest OS
    * Delete all unused files, empty your trash can, delete your browser cache etc.
    * Defragment your guest OS (f.x. using “defrag c:” in the cmd prompt).
  4. Zero out unused disk space in guest OS disk image
    * Download Mark Russinovich’s disk erase tool SDelete v1.51+ and place it on the local guest drive (*1).
    * From a command prompt navigate to where you saved the above delete tool and write “sdelete -c c:”, which will clear all free disk space
  5. Close guest OS and VMWare
    * Shutdown your Windows guest OS.
    * Quit VMWare fusion
  6. Shrink disk image using VMWare’s diskTool
    * Navigate to the VMWare Fusion tools directory. E.g. type “cd /Applications/VMware Fusion.app/Contents/MacOS”
    * Run VMWare Fusion’s diskTool command with the shrink option “-k” to compact your virtual drive (*.vmdk). E.g. type “./diskTool -k 0 full-path-to-your-virtual-desk-image.vmdk”. (*2)
  7. Finished!

*1) Nb. this erase tool is not documented to be compatible with Windows 2003/XP, but it works just fine on on my Win2003 R2 (as far as I can tell).

*2) Do remember the “./” when running diskTool to avoid mis-executing the Mac OS disk tool with the same name instead.

UPDATE – QUICK SNAPSHOTS CONSOLIDATION TIP:

If your disk image has snapshots you need to consolidate those into one large disk before attempting the above recipe. You can create a single disk image by cloning (merging) your disks using VMWare’s diskCreate tool (located in same folder as diskTool). The procedure is:

  1. Again backup your stuff first in case things go wrong (and again make sure you have plenty of spare disk space).
  2. Create a new folder with the extesion .vmwarevm to hold the output files.
  3. Navigate to the VMWare Fusion tools directory. E.g. type “cd /Applications/VMware Fusion.app/Contents/MacOS”
  4. “./diskCreate -C path-to-latest-snapshort-vmdk-file.vmdk path-to-new-merged-disk-file.vmdk” (use output folder above for destination).
  5. Copy the .vmx , .vmdk and .vmxf files into the output folder. Use a texteditor to edit the .vmx (and .vmxf) files to reflect the new disk file name.
  6. Test that the new consolidated image works in VMWare fusion.
  7. You can now proceed to the recipe for shrinking your disk.

Using ExtJS tree on rails with the prototype adapter

February 22, 2008 by

UPDATE: Notice that the new version of ExtJS is now on Prototype 1.6, yeah…

So I’m doing a folder tree using the ExtJS javascript with the prototype library adapter. I’m pretty much doing this.

This was somewhat working. Every third or forth browser refresh the tree didn’t load any nodes. Very odd indeed. I debugged my way through using Firebug, but when this was on, it worked everytime. Since Firebug slows down the entire javascript environment I concluded that the error occured when something (or loading) happened too fast.

In the ext-all-debug.js (version 2.0.1) I tracked the error down to line 23754. The json result being evaluated is undefined (notice that this only happens some of the time). So… after hours of head scratching and putting alerts in both the prototype library and ExtJS library to see what was wrong, it hit me…

The version ExtJS I have, come bundled with prototype 1.5.0 while rails 2.0.2 comes with prototype 1.6.0.1. In my layout I simply included <%= javascript_include_tag :defaults %>, but after I changed this to:

<%= javascript_include_tag “application.js” %>
<%= javascript_include_tag “ext/adapter/prototype/prototype.js” %>
<%= javascript_include_tag “ext/adapter/prototype/effects.js” %>

Everything seemed to work. Now my only problem is that I now use Rails 2.0.2 with an old version of prototype. So can I use all the rails helpers?!?

Installing Mephisto (multi site) on DreamHost

January 7, 2008 by

The title might be a bit off, since I’m not providing you with a step by step guide. This post do however sum up my notes during the install.

I started by following excellent guide:
Mephisto and Dreamhost

After looking at several guides, this one was really the easiest to follow.

Now Mephisto was installed and I wanted to add multiple sites support and I followed the guide:
Setting up Mephisto for multiple sites

I did everything but couldn’t figure out why the site still used the site root (/public) as cache location. Well silly me. As it turned out I had to restart the fcgi process (something that I really thought I’ve already done). So… Remember to do a:

touch public/dispatch*

from the application root folder.

Installing RadRails and getting error “Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.”

January 2, 2008 by

Up until now, I’ve been using TextMate to create my Ruby on Rails code, but I’ve been missing stuff like autocompletion (I know, a bit more difficult when using dynamic languages, but I really miss it because I also do alot of C# development in Visual Studio).

So.. I decided to try out RadRails that is now named Aptana Studio and the Rails development package installed as a plugin.

After the download and the installation I then tried to install the Rails plugin, but got this strange error:

“Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.” and “ Subclipse Mylar Integration (1.0.1) requires plug-in org.eclipse.mylar.tasks.core (0.9.2)”, or later version.”

After some searching I found the answer here. All you have to do is to un-select the Mylar integration. Although this might be a simple operation for experienced users of Aptana Studio, I was a bit puzzled about this. As someone who just wanted to try out the Rails environment (and I guess I’m not the only one), this seemed like an unnecessary complex installation (at the time I didn’t even now what Mylar was – now Mylyn)

Best of Ruby/Rails in 2007

January 1, 2008 by

Thanks to the great work of the Ruby & Rails communities, the year of 2007 saw many exciting new software releases. I have listed a few releases that I would like to point out in particular and expressively thank the developers for:

* Rails 2.0 – A great open-source framework got better in December 2007 with the v2.0 release. In particular I like the improvements in security, test fixtures, http support, performance, debugger and the non-beta addition of ActiveResource by default.

* JRuby 1.0 – By mid 2007 the first proper open-source release of JRuby arrived and it was able to run (most) Rails applications. Very impressive but a bit beta-like (many key API’s are still changing and there is little documentation in the download). Look out for an even better and faster JRuby 1.1 with JIT support in early 2008.

* Ruby 1.9 ( development release) – The proper development release of the next ruby programming language and implementation, version, 1.9, was released in open-source form on 25th December. Not suited for production but gives the community a chance to experiment with, and provide feedback for, many new Ruby features and implementation changes before Ruby 2.0 arrives. My favorite changes are string encodings (for f.x. unicode) and the new YARV virtual machine included in the Ruby 1.9 release.

* RubyGems 1.0.0 – First proper release of RubyGems in December 2007 as open-source. With RubyGems Ruby developers neatly avoids Java’s classpath-hell (*). Basic but cool stuff!

* Active Scaffold 1.1 (almost) – I was not sure if I was going to include this plugin on the list because it is not quite ready (it’s a release candidate last updated in December) and because the old version 1.0 had a bit too many limitations for my taste. However, this open-source Rails plugin is simply too great to leave out. It’s is basically a parallel to “ActiveRecord” but for the front end allowing the developer to implement visual, model-driven CRUD operations quite neatly. You should check it out.

* Commerical IDEs with real Ruby+Rails support arrives in plenty. Proper IDE releases in 2007 includes Netbeans, Aptana (RadRails), IntelliJ, 3rdRail, Ruby In Steel, Komodo IDE etc… At last some real competition to plain old emacs or textmate !

Nb) I use this term for a lack of a more neutral yet common description of the issues with installing jars and configuring classpaths in Java. Java is a great development platform – which I have used proficiently and happily for 10+ years – but classpath/package/module/jar/version management is not it’s strong point

Ruby on Rails’ footprint on Microsoft

December 21, 2007 by

This post could also be called how David (DHH) inspired Goliath (MS).

Lately Microsoft has release a number of products and new technologies on the .NET platform. Of course this could just be seen as the way of .NET framework. I mean.. 3.0 and 3.5 are just what comes after 2.0, right?!

Anyway… We’ve had this WebForms framework for doing websites for years now, and MS never really strafed from this strategy even though the Model View Controller pattern has had alot of followers and proven itself on the Java platform. Why should we have an MVC stack when working with .NET?!? Well.. I for one find it really easy to understand. No more advanced event cycles and s… viewstate. No more postback and advanced control design… Well that’s just me. When that is said, I’ve worked almost exclusivly with WebForms since the .NET 1.0 beta was out… Of course there has been some alternatives. In the last post I linked to the MonoRails project. On the frontpage it even says that it is inspired by Ruby on Rails (just see the .rails file extension for the httphandler in all their examples).

As I wrote in the last post, Microsoft are now launching their own MVC stack… Hmmm… Why the sudden change? As with everything Microsoft goes into, they pretty much market it as something completely new and innovative. Just look at the MVC frenzy going on over at: ScottGu and Haacked.com (ok.. also alot of great examples… ).

So is this another MS MVC post… Well not really, I just wanted to sum up some recent stuff out of MS and then leave it up to you to decide if they are not (heavily) inspired by RoR:

MVC

As already discussed, the heart of RoR and a sudden shift from MS.

REST

While not invented by DHH, he spoke (and) … and the world listened. This completely suprised MS. “Does people actually need this silly rest thingy?!”. Well apparently MS is now REST’ing a but with the Astoria Project.

NRuby?

We currently have JRuby and MS recently launched their first dynamic language (IronPython) on the .NET platform. Furthermore there are job ads like this. There is also this open source project however.

O/R Mapping

While RoR uses Martin Fowler’s Active Record pattern for its o/r mapper, Microsoft finally has something they almost can call an o/r mapper. While MS has brought the dynamic expression i c# to the table with the LINQ technology, LINQ for Entities (and SQL) is really too little too late.. I’ve been using NHibernate for years now and with the LINQ for NHibernate I might just stay there :) . And also remember that this is not the first o/r mapper MS tries to bring to the market. Who doesn’t remember ObjectSpaces.

While I don’t claim that MS has picked up on o/r mappers after RoR, they certainly comes in handy with their brand new lightweight MVC package.

So…

What do you think?! Is MS inspired by RoR?! I believe they are at least keeping a very big eye on it (Sauron style) but that’s just my to cents?

Asp.net MVC framework

October 12, 2007 by

And so it happened… Microsoft acknowledged that not all developers like the whole event driven/viewstate model.

Other web frameworks like the MVC model has been used for years on other platforms, alternatives like MonoRails have existed on the .net platform with a small loyal crowd of developers.

But now…. (my guess is because the whole buzz about Ruby on Rails and its MVC model) Microsoft launches their own MVC framework:

http://codebetter.com/blogs/jeffr…mvc-framework-at-alt-net-conf.aspx

At last… I can’t wait to try it out and to see how adoption goes.

Don’t rename the title field in sharepoint lists and doing caml lookup by id

August 8, 2007 by

I guess alot of you that if you rename the Title field in a SharePoint list, the internal name is still “Title” (only the viewable name is actually changed). I had such a scenario where another developer had renamed the Title field to E-mail because there was really no need for having a title field in the list.

By itself this posed no problem, but when you work intensive with CAML problems quickly add up. When writing CAML queries in SharePoint you query on the internal name of the field. This didn’t pose as a problem for me, I just made a comment in the code so my fellow developers could see why I’d written “Title” in my query when the “E-mail” was what I needed. After I then ran my code nothing happend. SharePoint just returns “0 found posts” if anything is wrong with the CAML query making it hard to really see where the error is.

Somewhat confused by this, I downloaded the Stramit SharePoint Caml Viewer. Great application. When looking at the data for the entire list, I could see another field called “LinkTitle”. When I used this in my query it magically worked.

While I found a solution, I was really too far out in the internal fields of SharePoint, so I deleted the list and created a new one WITH THE TITLE FIELD :) . I’m not sure if this oddity was caused by all the renaming but the lesson learned (at least for me) was: Don’t mess with the title field…

If you’re still reading, a quick tip for working with lookup fields in CAML. A normal caml query with lookup looks like:

<Where><Eq><FieldRef Name=”Category” /><Value Type=”Lookup”>My category</Value></Eq></Where>

Nothing fancy here, but something that I’ve only found on a few blogs out there is how to do the lookup with the item id. Here’s how:

<Where><Eq><FieldRef Name=”Category” LookupId=”TRUE” /><Value Type=”Lookup”>234</Value></Eq></Where>

Happy SharePointing :)

VM-ware Fusion and remote desktop fun

August 7, 2007 by

While I’ve been using apple computers for years now, I’m new to virtualization.

Because we develop web applications using Ruby on Rails, we decided to work with apple MacBooks. This is really nice because we then look cool while writing cool code, but a challenge when we do consultancy work on other platforms. Currently I’m doing Sharepoint (MOSS 2007) development for a customer and for this MacOS just won’t cut it. For this we’ve bought VMware Fusion. I cannot praise this magnificent piece of software enough. It just works (and I’m still running with the beta version).

So a couple of days ago I had to connect via remote desktop to my MOSS development environment and change my default password. To change my password on the Windows 2003 server I had to do a “ctrl-alt-delete“, and then it hit me… How the heck do I do this with my MacBook keyboard?! I’ve started a Windows XP in VMware Fusion and connected to a (virtual) Windows 2003 Server through Remote Desktop (talk about virtualization :) ). I search the net but could not really find anything about this cocktail, so I wanted to share my findings on this tricky key combination (or at least store it somewhere for when I need it again in six months):

fn-M + numeric enter (the funny up arrow next to the right apple key) + <– (the top right delete key)

I used like an hour to figure this one out :)

Shooting yourself in the leg with a bazooka

July 13, 2007 by

The colorful title reflects that this posting is about common mistakes done by good but relatively inexperienced software developers. Big mistakes that a developer actually need quite some skills to make. Mistakes that we unfortunately see all too often and we would rather not see much of again (hopefully this blog entry can aid a bit towards that goal):

  1. Overly complicated design – Instead of a simple design for a simple project some developers insist on using a impracticable mix of all the newest, fanciest abstractions, design patterns, techniques and advanced language constructs that can possibly be combined in one software solution. All design elements have benefits and drawbacks. Great (experienced) developers know when a particular benefit of an abstraction, pattern, technique or feature outweighs the drawbacks. There is no silver bullet. No design element works well in all situations (just as no rules that you learned in “programming school” are in fact absolute). Developers that get way too eager ends up with one big unmaintainable design mess with the combined drawbacks of all decisions but few if any real benefits remaining…. Remember, a simple design is a beautiful design!
  2. Writing too much code – Writing lengthily code with a high maintenance cost by hand when writing such code can be avoided. Much code can be avoided by choosing a more suitable design/architecture, using standard framework/library features (xml serialization is a common example), using techniques such as dynamic reflection or specialized code generation and aspect oriented tools (be careful though).
  3. Reinventing the wheel – Some developers think they can write their own code much faster than learning to understand the underlying framework and available libraries. This might in some cases even be true, but when considering overall quality and maintainability (which developers seldom do) reinventing the wheel is almost always a bad idea.
  4. Incorrect use of advanced concepts such as multithreading – Some developers use multithreading without the discipline and deep understanding that writing correct, safe multi-threaded code requires. Multithreading can improve the user experience immensely. It is also the answer to scalability nowadays. However, before even considering to use multithreading in your design, make sure to know the theory and features in your environment well. A vague recollection of mutexes and semaphores from school is not good enough. You should also realize that by deciding to use multithreading, you generally need to upgrade on testing, documentation, reviews and quality insurance.

Follow

Get every new post delivered to your Inbox.