Virtual Machines and Swap

For a while now I have been using VirtualBox to run various windows guest operating systems on my Linux host. One thing that I have always been wary of when using them is how the disk image gradually grows over time. This is because on the host operating system the disk container uses a sparse file so that the virtual disk can appear to be bigger than it actually is, but it can only do this when the guest operating system is not using the space, and the data is effectively set to zero. When you delete a file on the guest operating system it doesn’t bother to set the file contents back to zero, it just removes the record of where the files data was located.

This is not really a problem and most people know that you can use a tool such as sysinternals SDelete to zero the free space. Then using the command

vboxmanage modifyhd --compact <diskimage.vdi>

the space can be reclaimed.

However in windows there is one file in particular called pagefile.sys (also known as the swap file) that is constantly being written to and then subsequently erased. Its possible that windows does this intelligently and re-uses the same sectors of the virtual disk for the pagefile, but it seems more likely to me that windows doesn’t do this, after all it isn’t aware that its really writing to a virtual disk.

What made sense to me was to create a second virtual disk specifically for the pagefile. I made the second disk image immutable. What this means is that all writes to the disk are stored in a differencing image which is thrown away when the guest machine reboots. Because of this I can ensure that it never gets any bigger. This also has some other advantages.

Firstly I can use the same immutable image for all my Virtual machines. These currently include; Windows XP, Windows 7, Windows 8.1, and Windows 10. Secondly because the image is immutable it allows all guests to use the image while all running at the same time.

Thirdly the fun part, I can host the differencing images to the immutable base image in tmpfs meaning that the guests get the advantage of having very fast i/o for their pagefile.sys. This is the advantage I like the most because it certainly seems to improve performance.

Advertisements

How to fix your buttons – Ubuntu

For some reason, with each new major version, Ubuntu keeps changing the location of the minimize maximize and close buttons on the window decorations. Its really annoying because as soon as you get used to one way, they put it back the other way. Once and for all I wanted to fix this problem and have my buttons where they should be, where they have always been (for me this was on the right having come from windows)

gconftool-2 --set /apps/metacity/general/button_layout --type string ":minimize,maximize,close"

Now at least I can get used to them in the right place!

EDIT: For ubuntu 13.04 you need to do this:

gsettings set org.gnome.desktop.wm.preferences button-layout ':minimize,maximize,close'

Desktop Wallpapers Waste Memory.

My colleague often says something along the lines of:

I don’t know why everyone has a desktop wallpaper its nothing but a waste of memory

I thought that this sounded somewhat like an urban myth and decided to see if there was any evidence to support or dispell this claim. Well it turns out that although the wallpaper is pushed to video memory for rendering it cant be kept there as if it were just general purpose RAM. So the wallpaper does have to be stored in conventional memory, but is it a waste?

Well assuming a resolution of 1280×1024 and a 32bpp color (4 bytes per pixel) we get:

1280 × 1024 × 4 = 5 MiB

So I am wasting 5 MiB of my 8 GiB of RAM. As a percentage:

5/8192 × 100 ≈ 0.06%

But yes it is a bit of a waste, I should probably turn off my desktop wallpaper.

Android Development x64 Ubuntu 12.10 (Quantal Quetzal)

The android developer guide suggests you install ia32-libs when developing on a 64bit platform. However this installs some 242 packages. A much more sensible option is to only install the 32bit libraries that are actually needed and then you only have to install 57 new packages. Additionally Quantal Quetzal comes with an up to date version of eclipse (3.8) so you can install this via the package manager as well instead of downloading 3.7 as the guide suggests.

To install the packages simply run the following command:

sudo apt-get install eclipse libgl1-mesa-dev:i386 libsdl1.2debian:i386

The installation of eclipse will also provide a compatible Java runtime required for building android apps.

Ownership Permissions of /var in Debian Squeeze

Suppose you happen to accidentally do sudo chown -R www-data:www-data * whilst the current directory is /var. Now that’s a fairly daft thing to do! but we all make mistakes. There doesn’t seem to be an easy way to correct this other than restore a backup or look at another machine with a similar setup. Rather than having to restore a backup I looked at a machine with a similar setup, the machine has lighttpd, mysql, and sendmail installed on it so I built the following script based on the permissions with those packages installed on a fresh install of Debian Squeeze

#!/bin/bash

echo "Setting Directory ownership" &&
chown -R root:root /var &&
chown -R man:root /var/cache/man &&
chown -R www-data:www-data /var/cache/lighttpd &&
chown -R libuuid:libuuid /var/lib/libuuid &&
chown -R smmta:smmsp /var/lib/sendmail &&
chown -R mysql:mysql /var/lib/mysql &&
chown -R www-data:www-data /var/log/lighttpd &&
chown -R mysql:adm /var/log/mysql &&
chown -R www-data:www-data /var/run/lighttpd &&
chown -R mysql:root /var/run/mysqld &&
chown -R smmsp:smmsp /var/run/sendmail/msp &&
chown -R smmta:smmsp /var/run/sendmail/mta &&
chown -R smmta:smmsp /var/spool/mqueue &&
chown -R smmsp:smmsp /var/spool/mqueue-client &&
chown -R root:staff /var/local &&
chown -R root:mail /var/mail &&
chown -R root:smmta /var/run/sendmail &&
chown -R root:smmsp /var/run/sendmail/stampdir &&
chown -R root:crontab /var/spool/cron/crontabs &&
chown -R www-data:www-data /var/www &&
echo "Setting File ownership" &&
chown root:smmsp /var/lib/sendmail/dead.letter &&
chown root:adm 
 /var/log/auth.log 
 /var/log/boot 
 /var/log/daemon.log 
 /var/log/debug 
 /var/log/dmesg* 
 /var/log/fsck/checkfs 
 /var/log/fsck/checkroot 
 /var/log/kern.log 
 /var/log/lpr.log 
 /var/log/mail.err 
 /var/log/mail.info 
 /var/log/mail.log 
 /var/log/mail.warn 
 /var/log/messages 
 /var/log/news/news.crit 
 /var/log/news/news.err 
 /var/log/news/news.notice 
 /var/log/syslog 
 /var/log/user.log &&
chown root:utmp 
 /var/log/lastlog 
 /var/log/btmp 
 /var/log/wtmp 
 /var/run/utmp &&
chown root:smmsp 
 /var/run/sendmail/mta/smsocket 
 /var/run/sendmail/stampdir/reload &&
chown -f root:smmsp /var/run/sendmail/mta/sendmail.pid &&
chown mysql:adm 
 /var/log/mysql.err 
 /var/log/musql.log &&
chown -f mysql:adm /var/run/mysqld.pid &&
echo "Done."

In addition you will need to set the ownership permissions of /var/spool/cron/crontabs/<user> and /var/mail/<user> depending on the users on the system.

Revisited – make a DVD out of just about any video file.

I recently was asked to create a DVD from a .mov video file. I had already made a post about how to do this under windows using windows ports of various linux based applications. Coming back to it and this time running completely on linux, I have realised that it can be done much more simply.

The required software can be installed using

sudo apt-get install ffmpeg dvdauthor growisofs

First off the video file has to be transcoded into an dvd compatible mpeg2 file.

ffmpeg -i <video.mkv> -aspect 16:9 -target pal-dvd output.mpg

Then the file has to be authored into the correct VOB files using dvdauthor. To make sure that there are no errors in the process the following environment variable must be set.

export VIDEO_FORMAT=PAL

Rather than using an xml control file for simple DVD’s the following two dvdauthor commands will suffice.

dvdauthor -o DVD/ -t output.mpg &&
dvdauthor -o DVD/ -T

Finally the files are burned to DVD media using growisofs

growisofs -dvd-compat -Z /dev/dvd -dvd-video -V "<name>" ./DVD