Archive: 2007-12
Linux liposuction, or: Xubuntu in under a gig on the Eee PC
Note: If you upgrade to kernel 2.6.29, your compressed partition won’t work. Read Squashing /usr and the 2.6.29 kernel for a guide to upgrading.
I got an Asus Eee PC for Christmas. It’s a black model with 4 GB (i.e. 3.7 GiB) of solid-state disk and 512 MiB of RAM. The specs aren’t particularly high end, obviously, but it’s cheap, small, light, and robust.
For around £200, you get a little computer with WiFi, a proper (if diminutive) keyboard, and the ability to be stuck in a bag and taken almost anywhere. It’s smaller and lighter than a hardback novel:
Plus, it comes running Linux out of the box! What’s not to like?
To be honest, I looked at the supplied distribution (Xandros) for about five minutes before wiping it and installing my preferred Linux, Ubuntu (in its XFCE variant) on there. I’ve spent the last few days tweaking it to work according to my preferences and optimally within the constraints of the hardware. There’s more to do, but I’m making progress.
As I mentioned, the internal storage is only 3.7 GiB. By default, Ubuntu takes a lot of that for itself, but it can be slimmed down quite drastically. Some of it I freed by removing unneeded packages, like the X11 drivers for graphics cards that I don’t have. Some was released by removing heavyweight software such as OpenOffice.org (I consider word processors actively harmful, but that’s a discussion for another day). Beyond that, though, I’ve delved a little deeper and given the operating system itself a bit of liposuction to take it down to under 1 GiB.
Here’s how.
I ran xdiskusage to find out where the disk space was being used most, and discovered, to my not very great surprise, that most of it (1.5 GiB) was taken up by the
/usr
directory. The obvious solution was to compress it, using a combination of squashfs and unionfs.squashfs lets you compress a filesystem, but it’s read-only. unionfs, meanwhile, allows you to overlay a writeable filesystem on top to allow changes to the data. Obviously, the more you change the data, the more disk space is used, but it’s always possible to recompress and recover the space later on.
All the commands I’m going to give here need to be run as root, and I’m going to assume basic Linux competence. If it doesn’t make sense to you, you probably shouldn’t try it!
The first step is to install a couple of packages:
apt-get install squashfs-tools unionfs-tools
Then make a space for your compressed filesystem and overlay:
mkdir -p /.filesystems/usr/overlay
And compress your filesystem:
mksquashfs /usr /.filesystems/usr/usr.sqfs
Add these lines to /etc/modules:
unionfs squashfs loop
... and these lines to /etc/fstab:
/.filesystems/usr/usr.sqfs /usr squashfs ro,loop,nodev 0 0 unionfs /usr unionfs nodev,noatime,dirs=/.filesystems/usr/overlay=rw:/usr=ro 0 0
Next, reboot from a live distribution on a USB stick, CD, or SD card, mount the internal root partition, and move aside the old
/usr
directory:mkdir /mnt/sda1 mount /dev/sda1 /mnt/sda1 mv /mnt/sda1/usr /mnt/sda1/usr.old mkdir /mnt/sda1/usr
Reboot from the internal disk. Did it work? Then you can remove the
/usr.old
directory to reclaim the space.After all that, my operating system takes only 832 MiB on disk, saving me about a gigabyte. That’s a significant improvement when there’s only 3.7 GiB to start with!
In a comment, Passerby explained how to do this without rebooting into a live system:
Switch to runlevel 1:
init 1
(Ubuntu will prompt you what to do – choose opening a root shell)
Move aside the old
/usr
directory:mv /usr /usr.old
Test whether you previously edited fstab successfully by typing:
mount -a
If you get error messages or your
/usr
directory shows up empty, either fix yourfstab
or undo the changes before rebooting.Instead of the final reboot, you could also just return to runlevel 3 via:
init 3
Yes! We’re Number One again!
2007 may have been another bad year for British sporting prowess (surely an oxymoron), but that’s not to say that we never win anything. We’re world leaders in lardiness and teenage pregnancy, for example. And now, here comes another shiny, CCTV-festooned trophy to add to our groaning national mantelpiece: the award for the lowest privacy ranking in the EU!
Drinking to excess
After falling off my bike and getting concussed the other day, I was recommended to avoid alcohol for six weeks. Since I want to give my brain cells a chance, I’m following that advice scrupulously.
Britain has become a ballroom dancing country
Two headlines caught my attention as I listened to the radio this morning. The first was a report in the Daily Telegraph, no doubt timed to coincide with yesterday’s announcement that warmongering hypocrite Tony Blair has been accepted into the Roman Catholic church, saying that ‘Britain has become a “Catholic country”’:
Dazed and Contused
Seven o’clock
Seven o’clock is the absolute worst time to arrive home. I’ve just missed the half-hour comedy slot on Radio 4; to add insult to injury, the following programme is the everyday story of farming folk, patronising yokel accents, ham-fistedly obvious attempts at shoehorning in every conceivable demographic group, and godawful acting that is The Archers. It’s a soap opera that metastasised out of postwar farming propaganda, and now it’s unstoppable. Getting rid of it would probably raise a greater outcry than Disestablishment or republican revolution. It would probably even get people out to vote in numbers that parliamentary elections could never attain.
How to make your Rails application suck less
Ruby on Rails is all about ActiveRecord, and ActiveRecord is all about making your database look like Ruby objects. Sometimes, that’s great. The barrier to entry is low; it’s a lot easier to read than a convoluted SQL query; it’s easier to test. But it also makes it very easy to write horrifically inefficient code. I don’t just mean N+1: I’m talking about NM+1 or worse!
Oh no, not again!
Another week, another government data loss. Only three million people are affected this time, though, which is practically nothing by the regular standards of incompetence that prevail wherever government agencies have access to people’s information.
Step away from the keyboard
Someone should definitely do something about it
Well, that was a waste of time. 10,000 people flew to Bali to demonstrate their deep grasp of irony—er, I mean, discuss ways to mitigate anthropogenic climate change.
How the Financial Times persuaded me of the case for socialism
There was a glossy full colour pull-out from the Financial Times sitting on the kitchen table at work today, and I was leafing through it as I ate my lunch. It was beyond parody.
Biometrics, or: How I learned to stop worrying and love the Man
I’m really opposed to having to give my physical details to state organisations. I don’t want to have my iris scanned, my fingerprints taken, or my nakedness exposed via back-scatter X-ray. I’m not sure if my objections are rational or just intuitive.