Now that Virtual PC is finally free, I've become obsessed with producing the smallest possible Windows XP Virtual PC image. It's quite a challenge, because a default XP install can eat up well over a gigabyte. Once you factor in the swapfile and other overhead, you're generally talking about around 2-4 gigabytes for relatively simple configurations.
My best result so far, however, is a 641 megabyte virtual machine image of a clean, fully patched Windows XP install. Not bad. And here's how I did it.
First, start with the obvious stuff:
Don't install anything else yet! Remember, we're trying to get to a minimal baseline install of Windows XP first. A nice, flat platform to build on.
It's critical to turn off system restore, because that eats up hundreds of megabytes of disk space. In a virtual machine environment, having a rollback path doesn't make sense anyway. And if the Windows software environment wasn't so pathological, we wouldn't need complex rollback support embedded in the OS, either, but I digress.
Now let's put together our toolkit of virtual machine optimization:
Thes utilities are mostly free. And, except for Crap Cleaner, they don't even require installers. Just plop all the files for each one into a folder; I call mine VM-utils. Copy this folder to the target VM.
XPlite is easily the best utility of its type; it removes scads of useless things built into XP that have no explicit uninstall mechanism. Unfortunately, XPlite is payware. There is a free version, but it's crippled; it can only remove a fraction of the items the full version can. See the full list of items it can remove along the right-hand side of the product page.
By default, XPlite generally shows things that are safe to remove. Note that the "Advanced Components" item is shown in that screenshot, which is definitely stuff that's not safe to remove unless you really know what you're doing. Anyway, here's what I consider totally safe to remove in XPlite's standard list:
The others require a bit of judicious selection.
Once you've made your selections, let XPlite do its thing. It's worth the effort, because you'll have an unbelievably squeaky clean Start menu when it's done. Who knew Windows XP could be this.. simple?
You can use any defragmenter you like, of course, but this one is free and works quite well.
copy bootdfrg.exe c:\windows\system32\
defrag -i
defrag -d c: -B
Either way, you're mounting an ISO. The Microsoft Pre-Compactor is in a folder named "Virtual Machine Additions" under your Virtual PC install folder. Once mounted, the precompactor will autorun. Let it prep the drive; this doesn't take long.
Cleanly shut down the virtual machine.
.. and prepare to marvel at the tiny size* of the resulting hard drive image!
It's really quite amazing how snappy and compact Windows XP can be, once you remove all the useless cruft from it.
* that's what she said.
Posted by Jeff Atwood View blog reactions
« Why Can't Database Tables Index Themselves? I Pity The Fool Who Doesn't Write Unit Tests »
The resulting 758 megabyte .vhd (Virtual Hard Drive) image is also highly compressible.
I created a self-extracting RAR image of the .vhd and the .vmc file -- it's only *243* megabytes!
Really cool!
Jeff Atwood on July 20, 2006 11:19 AMHave you tried running VMOptimizer on the final image, to see if you can squeeze it down a bit more?
Kevin Dente on July 20, 2006 11:37 AMThis is del.icio.us material! What a cool concept that you can distribute a full VM on a single CD-R!
Since my laptop doesn't have a DVD Burner, I struggled with this.
However, as soon as you install Visual Studio / Sharepoint / SQL Server, and such it will push it over the 800mb limit, but at least you can have a CD of something to start with.
Good work.
Ben Scheirman on July 20, 2006 11:39 AMYou may want to look at the free nLite tool to create a stripped-down Windows XP CD. It appears to include some of the same functionality as XPlite, but applies it before the OS is installed.
Alex Tsang on July 20, 2006 11:50 AMNlite's great for creating very stripped-down disc images to install from. It provides cleaning options very similar to XpLite and is free.
Pat cavit on July 20, 2006 12:05 PMit would be nice to have a heavily trimmed down windows xp install entirely geared towards gaming
for us linux and mac users to install on another partition
oldman on July 20, 2006 12:09 PMCompress it with 7-Zip instead of RAR, and you'll save even more space.
It's free (LGPL).
C-J Berg on July 20, 2006 12:43 PM> Have you tried running VMOptimizer on the final image
I was skeptical, but VMOptimizer worked. You use their special ISO to compact instead of the buil in Pre-Compaction ISO. Here's what I got...
Original size: 758 megabytes
VMOptimizer size: 641 megabytes
Did you turn off hibernation support? hiberfil.sys is a big as the VM's ram.
Leonel on July 20, 2006 01:58 PMI have an XP boot CD made using...something (I forget what), so that's obviously a very small build.
[ICR] on July 20, 2006 02:04 PM"Unfortunately, XPlite is payware"
Why is paying for a good product an issue? Don't you
like to get paid for the develpment work you do?
Like many out there I like open source and free whenever it makes since but clearly you liked the product and shouldn't the developer or team that created be rewarded.
VHF on July 20, 2006 02:12 PM> hiberfil.sys is a big as the VM's ram.
Hibernation is generally off by default in XP.. I always have to manually enable it.
> Why is paying for a good product an issue?
It's not an issue. In fact I bought a copy of XPlite during the composition of this post. But one of these things is not like the other..
Jeff Atwood on July 20, 2006 02:22 PMI'll second the VMOptimizer recommendation. It saves tons of time, does a great job, and it's a very inexpensive. One of the few pieces of software I was happy to buy.
And 7-Zip's worth it when you get to files that size. I wrote up some info on it before here:
http://weblogs.asp.net/jgalloway/archive/2005/05/07/406074.aspx
I think one of the switch names may have changed in newer 7-Zip releases.
True, a lot of people don't have 7-Zip installed, but it's really easy to make an SFX (self-extracting zip), so you distribute an EXE file which unzips itself.
Jon Galloway on July 20, 2006 03:01 PMGreat post, but seriously, I'm amazed you'd waste this kind of time and not just use Virtual Optimizer.
http://www.hanselman.com/blog/InvirtusVirtualMachineOptimizer.aspx
On my post you said this functionality wasn't worth $40. You MUST have spent at least an hour messing with this and writing this post. How much are you paid an hour? ;)
Scott Hanselman on July 20, 2006 05:16 PMAnd another thing...no way I'm installing a defrager made by the "Whitney Family." Who do you trust?
pagedfrg by SysInternals:
http://www.sysinternals.com/Utilities/PageDefrag.html
:P
Scott Hanselman on July 20, 2006 05:18 PM> I'm amazed you'd waste this kind of time and not just use Virtual Optimizer.
The Virtual Optimizer only zeroes out the drive. it doesn't..
1) Reduce the size of Windows XP
2) Defragment the drive
It does provide a 15% size reduction, which is nice, but it's hardly the entire point of the article. It does work as advertised, but personally, I'd rather spend that $40 on XPlite.
> no way I'm installing a defrager made by the "Whitney Family." Who do you trust?
Yes, it might destroy my.. virtual.. machine.. oh no. ;)
Jeff Atwood on July 20, 2006 09:51 PMThere was a big thread at neowin.net's forum where some guys tried to have the smallest windows folder. One of those guys wrote a complete guide which you can read at http://www.bold-fortune.com/forums/index.php?showtopic=229
Everything is done manually
I wonder if Parallels' compressor (trialware) would compress any better than Invirtus VM Optimizer or Virtual PC?
http://www.parallels.com/en/products/compressor/workstation/
Why free matters: I'm allowed to use free utilities at work, but anything I have to pay for requires a lot of red tape. It is actually easier to get a $600 tool than say a $40 tool.
rsbohn on July 21, 2006 05:18 AMI assume you did this, but not specifically mentioned:
Go into the Windows directory and delete all the patch backup directories, these can easily add up to > 50MB space on disk.
Richard on July 21, 2006 06:55 AMJeff:
Have you also gotten rid of all of the driver cab files. Your hardware is a known issue, so you shouldn't need any of the autodetect hardware stuff. I believe it is "%windows%/driver cache." In the past when Connectix owned it, I would even minimize the size of the swapfile. With 2GB RAM, my VM's are hardly noticable during demos.
I must say though, if anyone reading this is going to do presentations with VM's--don't say..."It's the VMs fault"--it's your fault if you haven't prepared a correctly working VM (including plenty of RAM to go with it)! It's like Hanselman's comment on "I know you can't read this, but..." See hanselman.com/tools for ways to fix that too.
Brian Sherwin on July 21, 2006 07:18 AMHi,
I thought you might be interested in this thread concerning the so called "TinyXP" build that is claimed to be sub 70 MB in size.
<a href="http://www.xtremesystems.org/forums/showthread.php?t=84885">http://www.xtremesystems.org/forums/showthread.php?t=84885</a>
I haven't personally verified claims, so i will be very interested in the results if you choose to test it.
Here's another idea - how come we don't see VM image freely distributed over Bit-Torrent and such? I mean as far as i understand - if the system is Sysprep'ed prior to distribution - it will require license key and in many ways will be indentical to a regular install, so that doesn't necessarily equate to piracy. At least that's not my intention bringing it up.
Fine, maybe Microsoft can be opposed to 3rd party distribution for one reason or another - but they themselves could defenitely distribute beta versions of their products in such form, no?
Vlad Ivanov on July 21, 2006 07:35 AMI am sorry, i had the link in my bookmarks for a while, so my memory of the contents was a little bit hazy - i just visited the link again prompted by your post and i'd like to make a correction:
It's a 100MB install that results in a 400MB installed image, that is claimed to only use 40MB of RAM to run.
Seems like still an improvement over your results.
Vlad Ivanov on July 21, 2006 07:42 AMYou should change your path from:
C:\windows\system32\
to:
%WINDIR%\system32\
:-)
Omar Shahine on July 21, 2006 08:40 AM> Have you also gotten rid of all of the driver cab files. Your hardware is a known issue, so you shouldn't need any of the autodetect hardware stuff. I believe it is "%windows%/driver cache."
Good idea. I ticked those two boxes in XPlite (remove cached server pack files, remove cached driver files). I tried to run Invirtus again, but it refused -- "can only run one time per VM for trial edition". Instead, I ran the invirtus drive zero-ing command line tool ( InvirtusFreeSpace.exe ) that's on the Invirtus trial ISO image. That produced the same compaction results as doing an autorun (!)
The resulting image is now 587 megabytes.
Jeff Atwood on July 21, 2006 10:18 AMDoes all this work with virtual server too, or this a vpc thing only?
Here's an easy one:
Still not using that good old modem and are not planning to in the foreseeable future? Got a xDSL line, Wifi connection or LAN you always hook up to?
I thought so...
Then why not kill all the modem driver description files from "%systemroot%\inf"? They're the "mdm*.inf" ones and they take up quite a few megabytes.
Btw.: Does anyone know a simple way to locate other deletable driver files... like say: old ISA-card drivers, drivers from obsolete graphic cards and TV-tuner devices?
Henrik Spuur Hansen on July 21, 2006 05:56 PMthis post is a keeper!
(lb tucks the entry away in his del.icio.us account)
lb on July 23, 2006 03:13 AMYou can also delete %WINDIR%\$NtUninstall--------$ folders: I am assuming that you would keep a backup of 'original' virtual image somewhere safe (like DVD or CD), and these folders can run up to several hundred MB..
I would also reduce/disable trash bin size and space your browser allocates for disk cache.
Maksim Pavlishin on July 24, 2006 11:55 AMHas anyone had any luck with Win2k3? I can only get to about 1.5 GB with SQL Server and IIS.
dave on July 31, 2006 01:37 PMAnother interesting idea: once the "base" drive image is created you can switch the virtualPC machine to use a differential drive based on the "base" drive. This differential drive can be kept in sync using FolderShare so you can use the same Virtual machine from different computers without many synchronization troubles.
Paperino on July 31, 2006 03:47 PMSounds great - no good for test machines where you need it to be a pure 'out-of-the-box' self-resetting VM, but just the ticket for specialist needs, such as setting up a Subversion server, or creating a sandboxed Internet browser VM.
Hmm - your filter is now blocking (dot)info web addresses as 'questionable content'.
Paul Coddington on August 1, 2006 05:58 AMJust shrunk my Win2k3 base drive to < 1GB using the methods outlined here and the Invirtus optimizer.
Thanks!
Bryant Likes on August 22, 2006 05:16 PMWe've got a 14Mb XP iso booting cmd.exe as shell and a standard project that will create a 50Mb XP boot CD with explorer as shell (not to mention a few other features like the hability to boot and run from RAM)
This is done using WinBuilder and the projects that come included with it. All our works and developments are free to everyone.
Nuno Brito on August 25, 2006 04:27 AMhey, just randomly came across this when searching for something else... just goign to say, i run TinyXP and it does what it says, i'm using it as a main OS though as my windows xp was broken and i didnt realise when i formatted my pc... but tinyxp does use 40mb of ram and around about 400mb installed... it's a great OS.
lonewolfxix on September 13, 2006 03:42 PMHmmm, seems possible to get it small enough to fit on a flash drive.
lee on November 4, 2006 10:55 AMYeah nLite is a kick ass software.
My favorite proggy!
Here is another useful resource for you article:
http://addons.wordpress.com/
A hell what of nLite addons :)
Mike on December 1, 2006 10:51 AMJeff, great post. Thanks for your time in helping the rest of us by sharing your knowlege.
=-=-=-=-=-=-=-=-=-=-=-=-=-=
If you want a free tool for zeroing out the empty space of a drive use the, formerly sysinterals, product SDelete.exe. You can download it from here http://www.microsoft.com/technet/sysinternals/utilities/SDelete.mspx
Use the command:
>sdelete.exe -p 1 -c <driveletterwithcolon>
This will pass over all the empty space of the drive once and write zeros. I use a copy of the UBCD4Wim (http://www.ubcd4win.com) that I made to boot my VM and use the tool when not actively booted to the drive image I want to zero out.
Hope this helps some out there.
-JMM
Another interesting idea: once the "base" drive image is created you can switch the virtualPC machine to use a differential drive based on the "base" drive. This differential drive can be kept in sync using FolderShare so you can use the same Virtual machine from different computers without many synchronization troubles.
Windows XP Tips on March 25, 2007 09:05 AMAlthough this article applies to VPC 2004 - I've recently been working on creating a developer image and followed the steps here and had one small problem.
If you uninstall the indexing service for Windows, the search box in IE 7 is completely hosed. The only way I could get it to work correctly was to reinstall the service. I don't know why these two items are coupled together, but it's something to watch for.
Nicolas Webb on November 26, 2007 05:59 PMThanks for the great info. My motivation for shrinking down hosted versions of XP, is so the Virtual PC disk can fit into a Solid State Disk (also know as RAM disk). Programs there run faster (and quiter) since both OS and data are stored in RAM.
SteveK on March 14, 2008 11:25 PMThis is terrific! Wish I had the time to make a minimal XP VM like this myself. I'd probably not go quite as far as you-- I'd want to leave IIS and remote desktop access and a few other things like that in place. But having just spent two weekends banging my head against making the smallest VMs I could manage with Oracle databases and other apps pre-configured (the tightest one I could come up with compressed down to 5GB) seeing your example is a real inspiration. Maybe I can get down to an Oracle DB in Windows XP, compressed to fit on one DVD...
I was also using WinRAR, to make self-extracting images; maybe I should look at 7-Zip if it can do better.
vm addict on April 13, 2008 10:22 PM| Content (c) 2008 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved. |