It’s been a long time coming, but I think I’m finally content with a fresh array of Edgy speed tweaks.
These are mostly the result of working with sub-1Ghz machines that needed every crutch available to make them spunky, but it’s also a result of working with Arch linux early in my Ubuntu experience. After you’ve seen the speed and response you can get from an Arch build, you start to wonder why the same machine doesn’t behave like that in Ubuntu.
Regardless of the reasons, Ubuntu has a lot of bonuses that Arch lacks. It doesn’t merit listing them here, since ultimately the downside of one distro is a perk in another — and vice versa. And this isn’t a comparison any more — it’s a healthy rack of tweaks that would/should/could make an Edgy Ubuntu build spunky and fun.
I’m putting this together as a series of steps, rather than a list of tweaks. There’s a good reason for that; the bulk of these things are best performed in order, with some things happening early on, and others happening at the end of the construction.
Perhaps more importantly, these were never my ideas — only ideas posted on the forums that I adapted or tested in Edgy, and modified to work with the newest distribution of Ubuntu.
The final product (that I like to make) is an Edgy build that uses Openbox 3.3.1 with feh to manage the desktop background, xfce4-terminal as an interface with the system, ObMenu to manage Openbox’s menu applications, Iceweasel as a browser, iDesk for a little bit of splash and XFE as a file manager. All of these were picked because they have low system loads and are easy to put together without too much hassle.
I’ve built these systems on a variety of hardware. I used the core elements of this to put together a 75Mhz Ubuntu box, a 120Mhz Pentium system, a 300Mhz laptop for my mom to use, a 750Mhz laptop for music and movies, a 1Ghz desktop for gaming (you laugh, but I can run NWN at 1280×1024 on that :) ) and a 2.26Ghz see-if-you-can-break-it machine.
The results depend on the hardware, as you might imagine. But my proudest achievements are the fact that the 75Mhz Pentium build gets to the desktop on less than 22Mb (19Mb for the 300Mhz laptop!) and the 2.26Ghz machine goes from the Grub menu to the desktop in 27 seconds. It’s a joy to watch.
As with anything in life, there needs to be a disclaimer or two. First, your mileage may vary. What works for me might be absolute rubbish for you. Along those lines, try these things and see what happens, but don’t feel like my way is the best way.
Furthermore, I’m not a Linux expert. My Ubuntu experience began barely a year ago, and that’s a speck in the grand scheme of Linux things. Google is my co-pilot, and I learn by breaking things.
Next, there is the real possibility of screwing things up by using these tweaks. Be prepared to start over from scratch. Back up everything important. Don’t be timid, but don’t be foolhardy either. This is how we learn.
Finally, feel free to speak up. If you have a question, ask it. If you have a suggestion, make it. If you have a correction, give it. We’re all in this together.
I’m going to pitch this as if you were building an Ubuntu-only (in other words, not a dual boot) 1Ghz desktop machine, with 256Mb of memory, onboard Intel graphics to a single monitor, a standard IDE hard drive and CDROM, an integrated network connection to broadband net access and integrated sound. This is a happy medium for most run-of-the-mill desktop machines and mid-grade laptops. If your hardware varies much from this, you’ll have to knock around the inside of your system to get the best performance. (I’m speaking figuratively there. ;) ) If you’re using cutting edge hardware … it should go without saying that you’re on your own.
First, start with a clean slate. Download a copy of Killdisk and blank the drive. I say this because installing over top of an old system can occasionally confuse your machine; I’ve had it happen to me. In my experience, starting with a perfectly blank drive is the best way.
Once the drive is blank and ready, boot the Ubuntu desktop CD or a copy of Damn Small Linux — anything that will give you a live environment. We need to be able to access the hard drive before we start installing the system.
Open a terminal and enter this command.
sudo fdisk -l
This will give you a list of your attached drives and their designations. Determine which drive is your primary master, and use its designation in the next series of commands. For the example machine, I’ll use /dev/hda — which is probably the same as yours.
sudo cfdisk /dev/hda
I like cfdisk over fdisk only because it’s easier for me to spot errors. If you prefer fdisk or another partitioning tool, please feel free to use it.
Build a partition scheme like this one.
- /dev/hda1 Primary 96Mb Linux Bootable (/boot)
- /dev/hda2 Primary 2048Mb Linux (root)
- /dev/hda5 Logical 256Mb Linux Swap/Solaris (swap)
- /dev/hda4 Primary 8192Mb Linux (/home)
A couple of notes. I keep my swap partitions small. I use the same amount of space for the swap as I have available memory in the machine. I very rarely use swap space; in fact, later on I’ll turn off swapping in an effort to avoid I/O delays and eke a little more speed out of the box. How much you use is up to you, but remember that your machine is probably going to boot on less than 54Mb of memory.
For the home partition, use whatever space is left to you.
I usually build partitions this way only because I sometimes experiment with different file systems, and Grub doesn’t like to boot some file system types. If I decide at some point that I want an xfs root partition, I don’t have to think twice about it.
Don’t ask me why I set the swap partition to logical. Old habits, I guess. Once a long time ago I set everything to primary, then checked to see if it was making a difference. It wasn’t.
Write that partition table to the disk and quit cfdisk.
Now it’s time to set file systems. File systems are funny things: What works wonderfully on one machine will be a real dog on another. The reason is that some file systems are more of a burden on the processor, while others are more of a burden on the I/O channel. There’s a much better explanation here; the basic idea is to pick a file system that works best with your CPU and connecting hardware. Each file system has its fan club and each fan club will tell you how great it is, but again, it’s up to you and your hardware. Try two or three and see what’s fastest for you.
On a 1Ghz machine (and slower), ext3 is the ticket. In my experience, slow processors need simple file systems. Fast processors benefit from other, more complex file systems.
Set the boot partition to ext2 (that’s right, ext2 — not ext3) with this command.
sudo mke2fs /dev/hda1
Now initialize the swap partition with this one.
sudo mkswap /dev/hda5
Now comes the fun part. We’re going to set the file system on the root partition and the home partition to ext3 with the dir_index option enabled. It’s another little tweak that works great with older machines.
sudo mke2fs -j -O dir_index /dev/hda2 sudo mke2fs -j -O dir_index /dev/hda4
The -j option sets the file system to ext3 instead of just ext2. The -O triggers the dir_index option.
Those commands will take a little bit to finish. When they’re done, we’re ready to install.
Reboot and start up the Edgy alternate CD. At the opening menu, pick “Install a command-line system” — a server installation.
You’re on your own for most of the installation, but when you reach the partitioner, make sure you assign the partitions to the mount points shown above.
After the installation is finished, you’ll need to reboot, and if all went well you’ll be greeted with a login prompt. The first thing you should do at this point is to enable the multiverse and universe repositories, since you’re going to want them later.
Here’s the sources.list file I use; I generated it a while back with UbuntuLinux.nl’s Source-o-matic, and updated it to edgy.
# Automatically generated sources.list # http://www.ubuntulinux.nl/source-o-matic # # If you get errors about missing keys, lookup the key in this file # and run these commands (replace KEY with the key number) # # gpg --keyserver subkeys.pgp.net --recv KEY # gpg --export --armor KEY | sudo apt-key add - # Ubuntu supported packages (packages, GPG key: 437D05B5) deb http://us.archive.ubuntu.com/ubuntu edgy main restricted deb http://us.archive.ubuntu.com/ubuntu edgy-updates main restricted deb http://security.ubuntu.com/ubuntu edgy-security main restricted # Ubuntu supported packages (sources, GPG key: 437D05B5) deb-src http://us.archive.ubuntu.com/ubuntu edgy main restricted deb-src http://us.archive.ubuntu.com/ubuntu edgy-updates main restricted deb-src http://security.ubuntu.com/ubuntu edgy-security main restricted # Ubuntu community supported packages (packages, GPG key: 437D05B5) deb http://us.archive.ubuntu.com/ubuntu edgy universe multiverse deb http://us.archive.ubuntu.com/ubuntu edgy-updates universe multiverse deb http://security.ubuntu.com/ubuntu edgy-security universe multiverse # Ubuntu community supported packages (sources, GPG key: 437D05B5) deb-src http://us.archive.ubuntu.com/ubuntu edgy universe multiverse deb-src http://us.archive.ubuntu.com/ubuntu edgy-updates universe multiverse deb-src http://security.ubuntu.com/ubuntu edgy-security universe multiverse # Ubuntu commercial provided by Canonical deb http://archive.canonical.com/ubuntu edgy-commercial main # Ubuntu backports project (GPG key: 437D05B5) deb http://archive.ubuntu.com/ubuntu edgy-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu edgy-backports main restricted universe multiverse
Now update and upgrade.
sudo aptitude update && sudo aptitude -y dist-upgrade
Now let’s finish tampering with the file systems.
File system tweaks
Two more tweaks to the file system will keep your ext3 machine running fast: The journal_data_writeback option, and the noatime option. We need to set these in Grub, in fstab, and by enabling the option with tune2fs.
First, open the Grub boot menu.
sudo nano -w /boot/grub/menu.lst
Look for the two options sections, and edit them to look like this. (Important: Leave that initial hash mark in there!)
# defoptions=rootflags=data=writeback elevator=cfq
And this. (Important: Leave that initial hash mark in there!)
# altoptions=(recovery mode) single rootflags=data=writeback elevator=cfq
Under defoptions, I took out splash and quiet. First, I like to see the terminal commands scroll by, so I don’t want the quiet option. Second, there’s no splash screen to speak of, so it’s safe to take that out.
root=data=writeback is the file system option we’re going to set. elevator=cfq is another tweak that adjusts the queueing. It sometimes gives me a tiny improvement, depending on the hardware and the I/O load.
Since we’ve altered the boot options, we need to update Grub.
Now let’s alter the fstab so it expects those options. Enter this into a terminal.
sudo nano -w /etc/fstab
This part is a little tricky. Edgy assigns a smear of UUID codes to the fstab entries, which makes them a little difficult to manage. Alter your lines for /dev/hda2 and /dev/hda4 like this.
# /dev/hda2 UUID=82eaeb0f-9df6-4129-a075-d98657d2e619 / ext3 defaults,errors=remount-ro,data=writeback,noatime 0 # /dev/hda4 UUID=8725b47c-c92e-48bb-9aa7-32ee39befc35 /home ext3 defaults,data=writeback,noatime 0 2
It’s possible your UUID numbers will be different, so don’t just cut-and-paste these lines into your fstab. Add the data=writeback and noatime flags to those partitions, where you see the defaults term.
Now that both Grub and fstab are ready, we can add the actual flag to the file systems.
sudo tune2fs -o journal_data_writeback /dev/hda2 sudo tune2fs -o journal_data_writeback /dev/hda4
Excellent! Now we’re ready to move on.
Thanks to boban for this excellent tweak. Edgy’s concurrent boot settings are in the /etc/init.d/rc file. Dig through that file and look for the CONCURRENCY option.
sudo nano /etc/init.d/rc
Change it from none to shell. On reboot, it will take effect.
Edgy works its processor kernels a little different. Dapper used 386 as the default, with 686, k7, and 686-smp as options.
Edgy goes straight to 686-smp as the generic. If you have an nvidia card installed, you’ll see that your kernel went to the 386 version.
From what I’ve seen thus far, switching kernels doesn’t help out much. It’s possible that someone can offer a little more help here, but from my experience, the kernel edgy picks is just fine.
Toss out dead weight
Now let’s throw out some junk. Depending on your hardware you may or may not need some packages that Ubuntu installed by default. We can throw them out, along with their metapackages, and save a small bit of drive space — and perhaps a little boot time too.
Here’s a rough list of packages that I generally don’t use on the mythical 1Ghz desktop I described. This is another one you probably shouldn’t cut and paste. ;)
ubuntu-standard evms evms-ncurses hdparm lvm2 lvm-common mdadm ppp pppconfig pppoeconf rsync ubuntu-minimal jfsutils pcmciautils reiser4progs usbutils vim wireless-tools wpasupplicant xfsprogs
Your hardware is what determines what packages you really need. For example, if you’re working with a machine that predates USB technology, by all means throw out usbutils. If you’re on a desktop, you don’t need pcmciautils, and you probably don’t need wireless-tools or wpasupplicant. That’s up to you. Otherwise, keep them on hand or things start to break.
ubuntu-minimal and ubuntu-standard are metapackages — kind of like capsules that hold the other packages in place. If you try to take out just jfsutils, for example, ubuntu-minimal will complain. So to take out any one of those, you have to take out its metapackage too.
One last note: If you don’t want sound, throw out alsa-utils and alsa-base. And remember, if you want or like something I’ve listed here (vim fans!), feel free to keep it.
Prelink, preload and readahead
These three packages do a little looking ahead while you’re using your machine. (readahead is not part of the server installation.)
sudo aptitude install prelink preload readahead
Prelink requires a little editing to get it going.
sudo nano /etc/default/prelink
Change PRELINKING to yes, then trigger the option through cron
The default readahead settings are acceptable in Edgy; there was a tweak for the Dapper version that seems to have become the default under 6.10.
Now it’s time for a few more tweaks. vm.swappiness controls how frequently your machine swaps out to the hard drive. Setting it to 100, the highest, allows swapping to take place quite frequently. This is probably good on a machine where memory is tight.
However, the example machine is going to boot on less than 64Mb, and so long as there’s plenty of space to get the job done, there’s no need to allow swapping. Let’s set vm.swappiness to 0.
sudo nano /etc/sysctl.conf
At the bottom of that file, add this line.
Since we’re in here already, let’s tweak our network access for broadband. Copy and paste this into your sysctl.conf file. Anywhere is fine.
# Tweaks for faster broadband... net.core.rmem_default = 524288 net.core.rmem_max = 524288 net.core.wmem_default = 524288 net.core.wmem_max = 524288 net.ipv4.tcp_wmem = 4096 87380 524288 net.ipv4.tcp_rmem = 4096 87380 524288 net.ipv4.tcp_mem = 524288 524288 524288 net.ipv4.tcp_rfc1337 = 1 net.ipv4.ip_no_pmtu_disc = 0 net.ipv4.tcp_sack = 1 net.ipv4.tcp_fack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_timestamps = 1 net.ipv4.tcp_ecn = 0 net.ipv4.route.flush = 1
Now reset sysctl to accept the new options.
sudo sysctl -p
Since we’re tweaking our internet options, we might as well turn off ipv6. Open a new file with this command.
sudo nano /etc/modprobe.d/bad_list
Paste this line into it and close it.
alias net-pf-10 off
There are other ways to do this, but they seem more complicated.
This can be a rather lengthy task. The next thing to do is to disable how some services are handled on startup and shutdown, and what runlevels they perform at (if at all).
You might choose to omit this step. It can be very time-consuming (comparatively speaking), and not knowing enough about just one service can result in a broken system.
First, install sysv-rc-conf.
sudo aptitude install sysv-rc-conf
At this point, you have the ability to disable a service completely, and this is another tweak that will depend upon your hardware to finish. There is a good list of services here, and suggestions to what you can safely disable.
Next, tamper with the file names in /etc/rc.0 and /etc/rc6.d to control what is managed at startup and shutdown. In general it’s safe to put lowercase letters on the same services you disabled with sysv-rc-conf. I’m sorry there’s so little detail here, but each machine is going to be different, and too many arbitrary instructions could break your rig.
At this point, what you do with your system is a bit up in the air. Myself, I prefer Openbox and Iceweasel these days, because they keep with the speed idea, and work fantastic on older machines. (If you do use Openbox, check up on the option to autologin without a login manager, which saves some time on startup. But don’t bother with it if you feel that might be a security risk.)
On the other hand there’s nothing to keep you from installing kubuntu-desktop or ubuntu-desktop and creating a full Gnome or KDE environment. What you do this far is up to you.
There are two more things you can do with your system, and really they should be done last, when everything is in place.
First, grab that DSL or Ubuntu live CD you started with, and reboot your machine again. Open a terminal window and enter these commands.
sudo e2fsck -fD /dev/hda2 sudo e2fsck -fD /dev/hda4
This will reoptimize the root and home directories, and can take a little while to finish.
When it’s done, reboot and press escape when you see the Grub boot menu. Edit the topmost option and add this word at the end of the boot line
Press return to finish editing and then b to boot that line. Your system will reprofile itself on this boot (and this boot only), and successive boots should be faster.
That’s it. Reboot a final time and see how it goes. If you have any ideas or problems, feel free to tell about them.
P.S.: A word about ramdisks
In my experience, ramdisks can be good things, but they don’t seem to speed things up like you’d think they would. But they’re always worth a try. As an example, there’s a good thread about setting up a ramdisk for Firefox here.