I wrote previously about the pre-made OpenSUSE 10.2 LAMP Server for Windows Virtual PC and it has been helpful in brushing up on command line Linux with a LAMP stack. After playing around it dawned on me that if I had a virtual LAMP server with a more recent version of PHP I could have a development mirror of this WordPress blog. So starting with the Lubuntu VM I created I’ve added a LAMP solution stack and a cloned copy of this blog.
Installing the LAMP Stack
Most of the pages I found about installing a LAMP stack on Lubuntu where very old (in Linux years) so they had far more steps than necessary. The fastest way I found was in a Comment on the Installing LAMP On Ubuntu For Newbies page.
Its really easy to install LAMP with ONE single command in ubuntu:
sudo apt-get install lamp-server^ phpmyadmin
When the installation nears the end you’ll be prompted to do these steps. Continue reading “A Lubuntu LAMP VM”
When you compact a Linux dynamic virtual disk in Windows Virtual PC you’ll find that almost no space is saved. This is because the compact routine only compacts disk area that is filled with zeros. For Windows guest OS’s Microsoft provides a Precompactor tool that zeroes out the unused space so that compaction works.
I thought I’d found a solution in Ben Armstrong’s MSDN Blog, Compacting the virtual hard disk of a Linux virtual machine. You run the following command, turn off the VM and then run the Compact virtual hard disk function.
cat /dev/zero > zero.dat ; sync ; sleep 1 ; sync ; rm zero.dat
It didn’t work for me then I thought, probably needs a sudo before the commands but that didn’t seem to work either. Searching around the net I found many sites suggesting the same or similar commands and others suggesting dd to do the job. After reading a lot of information I came to the conclusion that these methods are more of a hack than an elegant solution and there are quite a few technical reasons why they are sub-optimal.
That’s when I learned about the zerofree program for Linux from Ron Yorston. Read about this nice utility at his Keeping filesystem images sparse page.
Searching for use case examples for zerofree yielded many different recommendations most of which involved what seemed like unnecessary complications. These include installing zerofree on the system you want to run it, restarting in single user mode and remounting the file system read-only to run it.
Then I saw some sites saying to run zerofree from a Linux live CD and that struck me as the smartest and fastest way to do this process. The SystemRescueCd, a great live CD that I’ve used before, includes zerofree and nearly every other Linux disk utility there is.
Here is the process I came up with that is fast and really shrinks your Linux virtual hard disk.
- Shut down the virtual machine and if you have the undo disk feature enabled apply or discard the changes and then disable the feature.
- Backup the VHD file because low level manipulation of the disk file system could break it.
- Boot the virtual machine from the SystemRescueCd ISO.
- Check the file system before zeroing it out.
- Zero out the file system, it took 13 minutes to complete on my VHD.
zerofree -v /dev/sda1
- Check the file system after zeroing it out.
- Shut down the VM.
- Compact the VHD, Settings -> Hard Disk 1 -> Modify button -> Compact virtual hard disk button and remove the ISO from the DVD Drive setting.
That’s all there is to it, I think this is by far the fastest and easiest way of getting this done.