Optimizing Ubuntu to run from a USB key or SD card
Tip 1: Stop Firefox from writing to disk
Firefox 3 has a hard-to-fix bug that causes linux to write to disk every time you visit a write page. But it doesn't just write Firefox stuff -- it causes your entire system to dump all changes to disk. Unfortunately, your USB key might only have a 6 MB/s write speed, causing everything to freeze up.
- Under the Privacy setting, uncheck "Keep my history for..."
- Under the Advanced Tab, select Network and ensure that you use up to 0 MB of disk space for the cache.
Tip 2: Use preloadThe preload daemon is a program that constantly looks at the programs you are running and figures out which ones you are most likely to use. When you start your computer, it automatically loads these programs and library from disk in the background, so when you start firefox, for example, it will pop up right away. The background is described in the author's Master's thesis.
It's kind of like putting magnets under your pillow to improve health. Maybe it's having an effect, but I can't tell. I install it anyway:
sudo aptitude install preload
Tip 3: Compress your filesThis tip can wreck your system, and to undo it you will need to be able to use a command line editor like nano, emacs, or vim. At worst you will need to mount the USB key on another linux system to recover (by editing /etc/fstab). If you can't do that, then skip this tip.
On solid state storage, space is expensive. Ubuntu uses a huge amount of space will all the programs it installs. The /usr folder contains your programs, and it is usually 1.8 GB. Using squashfs, it can be compressed to 0.7 GB. Since read speeds are so slow, you can actually gain performance because there is less data to read. I've adapted these instructions from here.
Install squashfs and unionfs:
sudo apt-get install squashfs-tools unionfs-tools
Add the following lines to /etc/modules:
unionfs squashfs loop
Remove apparmor. Otherwise, the cups print server will stop working:
sudo apt-get purge apparmor
Make space for the filesystem:
sudo mkdir -p /.filesystems/usr/overlayCompress your filesystem:
sudo mksquashfs /usr /.filesystems/usr/usr.sqfsAdd 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 0Switch to runlevel 1. (Ubuntu will close all open programs, then prompt you what to do. Choose opening a root shell)
sudo init 1
Move aside the old /usr directory and create a new mount point:
mv /usr /usr.old mkdir usr
Test whether you previously edited fstab successfully by typing:
If you get error messages or your /usr directory shows up empty, either fix your fstab or undo the changes before continuing.
Now reboot and make sure it all works:
If it works, remove the /usr.old directory to reclaim the space.
Tip 4: Use memory instead of disk
This tip can also lead to data loss. If you do it, you will have to always shut down your computer properly from now on, because unexpected power failures will lead to data loss.
Linux usually ensures that all changes are written to disk every few seconds. Since disk writes are so slow, you can change your system to keep things in memory longer. All changes will be written to memory, and the excruciatingly slow writes to happen in the background while you continue working. This has an instant, noticeable effect, but it can lead to data loss.
Add these lines to /etc/sysctl.conf, and reboot.
vm.swappiness = 0 vm.dirty_background_ratio = 20 vm.dirty_expire_centisecs = 0 vm.dirty_ratio = 80 vm.dirty_writeback_centisecs = 0
The problem: using this tip means that your system stops writing changes to disk until you shut down or type "sync" at a command line. If your system loses power unexpectedly, you will get bad blocks. I did. You can limit the amount of data loss in the event of a power failure to one minute by setting vm.dirty_writeback_centisecs = 6000.
A side effect is that shutting down your computer will may take several minutes where it appears to be doing nothing. Don't cut the power until it's done, because it is busy writing all those changes to disk.
Rules for Effective C++The rules for safe C++ code are surprisingly controversial.
Compress your JSON with automatic type extractionJSON is horribly inefficient data format for data exchange between a web server and a browser. Here's how you can fix it.
You can cheat so your web site seems faster than it isYou can make your web site seem faster without actually being faster.
Cell Phones on AirplanesMuch ink has been spilled about the use of cell phones on airplanes. Here's the truth, which will be disappointing to conspiracy theorists: Cell phone signals most definately have an effect on other electronic equipment. Read on for more.
A Rhyming EngineHere's a rhyming engine, written in 1000 lines of C++ code. It uses the freely available Moby dictionary, and full source code is provided.
Why you should go to the Business of Software Conference Next YearMost people, having already paid $2000.00 of their hard earned money, and then having flown, driven, or otherwise travelled to Boston to attend a conference, and then having paid an additional $250/night plus $33/night parking and "tourism taxes" to the Seaport Hotel -- most people, after all this, are unlikely to say that it was a waste of time and they should have stayed home watching the remaining salvaged episodes of Doctor Who on Netflix.
In fact, I found it quite useful.