K.Mandla's blog of Linux experiences

Howto: Set up Edgy for speed

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.

Start clean

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.

Partitioning

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.

File systems

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.

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.

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.

Installation

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.

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!)

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.

sudo 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.

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.

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.

Processor-specific kernel

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. 😉

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

sudo /etc/cron.daily/prelink

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.

sysctl.conf

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.

vm.swappiness=0

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.

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.

Services

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

Invoke it.

sudo 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.

Almost done

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.

Last steps

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

profile

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.

All done

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.

Post navigation

45 thoughts on “Howto: Set up Edgy for speed”

You can pickup a little speed boast by making the the swap partition the last partition on the hard drive. This area of the hard drive has the highest read/write speed. This will likely vary from drive to drive. Best is a seperate drive for swap, last partition, and on the fastest drive.

Good idea. Right now I’m running on machines that either can’t hold or just don’t support a second hard drive, but you’re absolutely right. It’s a great idea for Windows machines too, and something I used to do reguarly when I set up a WinXP build. Thanks!

If I give uname -a to my little 750Mhz laptop, I get “2.6.17-10-generic #2 SMP” in the output. linux-686-smp in the Edgy packages says “Obsoleted by: linux-image-generic.” And linux-generic, which is installed as the default, is a container for linux-image-generic and linux-restricted-modules-generic.

So I’m a bit bewildered, but it seems to me that the logic is reversed from Dapper, where it started with the 386, with the option to move to 686, k7, 686-smp and so forth. Now it seems we start with smp support and can move down if need be.

Most of these tweaks — I think setting the dir_index option is the only holdout — could be done on a preinstalled system, too. And you could probably set dir_index in a live CD environment, although I haven’t tried that. Cheers!

Interesting Guide. I’m not sure what did it, though, but my system started mounting itself read only after I followed the instructions here; I had to go into Grub and change the “ro” to “rw” to make my system usable again.

Hi Trekkie. I’m not sure why that would have happened. You’ve probably already checked, but make sure your menu.lst file is correct, and that you ran sudo update-grub after you set the file system. If the file system is set to journal_data_writeback but grub didn’t get the data=writeback rootflag, grub might think it has found an error, and might set the file system as read-only.

My only other suggestion is to check your fstab and make sure there’s no typo in the line for your root drive. Cheers!

Hello. Thanks for the great info on the site. I am a relative ubuntu/linux newbie..so be gentle. 🙂
I have performed all of the steps above. However. I am still stuck with a login prompt and password. I then login and nothing happens. I guess I do not know how to get in from the doslike prompt back to kde/xfce etc.
I tried to install xfce, but the installation told me that I ran out of room. I think its trying to install all of the files into the root directory. Once I installed xfce I tried the command “sudo /etc/init.d/xfce start and I also tried kde start and gdm start. nothing happens other than an error saying that its not installed.

I am installing 6.1 on an HP n3270 notebook computer, 248mb ram(6 to video), 12 GB HD, DVD-ROM. I want to be able to browse the internet, basic word processing, and anything else it does would be a bonus. Any advice you can give is greatly appreciated. Thanks!

Hi Greg. After the text login prompt (which will probably be somewhat lost in the startup garble, if you set the concurrency to shell), enter startx and the X window system should begin.

XFCE is usually started with the command startxfce4, but if your XFCE installation ran out of room, you’re probably missing parts of it, so I don’t know if I would try it.

sudo /etc/init.d/gdm start and /sudo /etc/init.d/kdm start are only going to work if you installed GDM or KDM, which, if it were me, I would avoid on a machine of that era. They come with a lot of bulk, and slow things down in my experience.

If you run into problems, post a thread on the Ubuntu forums and PM me there, and I’ll do what I can to help. It’s a little more expedient there, and there’s the added benefit of higher traffic. Cheers and thanks!

I’d stress that this # will have to stay in front of that line (VERY unusual behaviour for *nix conf file!) – had some hard times with it, trying to figure out why it’s not working. I just assumed You had made a typo not removing it from there 🙂

Hi CanOsoup. If it’s really old, it might not boot from the CD drive; check in the BIOS to see if it will support it.

And if it’s an old machine you might want to try the live CD on something newer. The live CD generally needs around 256Mb to get started, and if your old computer has less than that, it might struggle.

Really neat guide…works for the most part just like it seems it should. The only issue I’ve had at all has been the fact that Ubuntu just LOVES to install Gnome in it’s entirety the moment I want to install something merely Gnomish, such as Banshee.

I initially did this on my wife’s laptop…got things to a workable condition, seems a bit snappier. I don’t really know enough to start weeding out services and such.

As I worked, though, I realized that what you’ve started here is really similar to the nLite project for windows, in reverse. Instead of stripping down, you are building up from an established base. Oh well, enough of my blathering.

Hi, this is an excellent guide. I am also a newbie, so please tolerate! I am woundering if this guide would similarly applies to installation of a Simply Mepis linux system. I already have this intalled on my old (1MHz) computer as a dual boot system. However, I know that I’d have to reinstall from a live CD, because it seems my system has some flaws in it.
Would you advise please?
Thanks in advance.

Hi Mahmood! Thank you! Yes, I think this will work on Mepis; if I remember right, Mepis is based on Ubuntu, so most of it should apply. I haven’t used Mepis before, so some things might be different, but you will know better than me. 🙂

In fact, most of it will work with any distro. I use the filesystems, partitioning and e2fsck tweak with my Arch systems. However, there are some things that are specific to Debian/Ubuntu/etc. (like concurrency=shell), so you should look closely.

Setting up SWAP as the last partition of the drive will SLOW YOUR SYSTEM DOWN. The reason is with constant angular velocity drives (like hard drives) sectors are numbered starting from the outside of the disk.

Sector 0 on a CDROM maybe on the inside, but CDROM’s are constant linear velocity drives (variable rpm) so it doesn’t matter anyways.

So if you want your SWAP partition to be in the fastest part of the disk it should be closer to sector 0.

What apps do you use on those slow computers? You look like an interesting fellow 🙂

My experience with openbox is that it isn’t so fast on my p1 as fluxbox, icewm, ratpoison, .. Still ofcourse openbox looks good, definately with a transparent pypanel, nice for making screenshots. Can you actually use the 75mhz enjoyably with openbox? I wonder..

Hi gunnix. I think for the day or so I played with that 75Mhz machine, I tinkered with Openbox and Xfe, and maybe a terminal program or two.

In retrospect, knowing a little more now, I think I would use something like Lowarch over Ubuntu, and stick with exceedingly lightweight apps like Dillo, or terminal based apps for anything else.

The 75Mhz machine was mostly an experiment, to see if an old, old computer could handle a new distro. It worked, but there was space for improvement. If I had been willing to put a little more time and effort into I probably could have come up with something “keepable.” 😀

Very impressive collection. I would also be interested in tweaks to apply to a running system. (What does dir_index actually do? I can’t figure out the real benefit) Also, consider the network optimizations to allow for a 256 window size, as some connections will choke with 512 and actually be slower.

Hi Myst. I’m going to borrow from the Gentoo Prelinking Guide, which does a fantastic job explaining, in brief, what prelinking does.

“Most common applications make use of shared libraries. These shared libraries need to be loaded into memory at runtime and the various symbol references need to be resolved. For most small programs this dynamic linking is very quick. But for programs written in C++ and that have many library dependencies, the dynamic linking can take a fair amount of time.

“On most systems, libraries are not changed very often and when a program is run, the operations taken to link the program are the same every time. Prelink takes advantage of this by carrying out the linking and storing it in the executable, in effect prelinking it.

“Prelinking can cut the startup times of applications. For example, a typical KDE program’s loading time can be cut by as much as 50%. The only maintenance required is re-running prelink every time a library is upgraded for a pre-linked executable.”

Take a look at that guide if you want more information, or you want to fine-tune your prelinking process. Cheers!

Hello anybody,
first: good work!
I have a question about the network: How can one set up networkcards as speedy as possible. i run ubuntu 6.06 on a dell latitude c600 with onboard network 100MBit but it seems that it go only for 10 MBit/s.
On the other hand, in my office we got some brand new dell notebooks with that nasty vista; no word’s about that but network is unbelievable fast! that breaks all limits – how goes that?
Again: thanks for your great work here.
Ice

hamamelis: That’s interesting. I’d never thought much about the UUIDs being transferred when the drive is ghosted. Is that the way it’s supposed to work? I was under the impression that the UUIDs were unique to each drive, but I guess that doesn’t have to be the case.

Ice: I’ve never heard of network cards being choked by Linux unless they were Broadcom wireless cards, which were forced to run at 11b speeds because of firmware issues. I suppose it could be a similar problem. What kind of a card is it?

@K.Mandala: The network is the build-in thing from my Dell Latitide C600 Notebook. It runs under windows with 100MBit but under ubuntu it isn’t that fast. No idea how to benchmark that but copy of large files from / to my (win2003-) servers shows the lack of performance.

@Sindhudweep Sarkar: I know very well how to calculate it.

I don’t know how to understand the output of tcpdump: it writes as an intro something like ‘link-type EN10MB (Ethernet)’. Shouldn’t it be EN100MB or am i wrong?

I got it, some restarts later. Don’t know how, but the last big filetransfers worked very fine. The windows taskmanager on the server even showed a networkload of 66% for some time, mostly 50%. This on an 100 MBit Ethernet network.
tcpdump allways shows the link-type EN10MB.
Which tool would be best to test a network?
Thanks to K.Mandla and Sindhudweep Sarkar for their help!
Again: Very good work.

Thanks for this great Howto and summarising all these tweaks. Did you know, that beside the “noatime”-Option, there’s also “nodiratime” and further more “nobh” for ext2/3/4-filesystems.

“noatime” disables, that every last access time for files is stored, and “nodiratime” does that for directories, as far as I know. For non-Server or home-use-system there are, imho, no disadvantages only improvements, when using this options.

“nobh” (also for /etc/fstab) I found in the kernel documentation, it says:
(found in /(kernel)/Documentation/filesystems/ext3.txt)

By the way, I read that ext2 is thus old much faster than ext3, because of no journal function. So maybe it’s a good idead, to make e.g. /tmp as an extra ext2-partition. (directories with non-important data)

Also excited about ext4dev with its “extents” feature. 🙂

One last thing I found:
For ext3/ext4dev there’s the “commit=(seconds)” option. In default it’s 5 seconds (commit=5), you can change that to commit=100 e.g. It’s not good for unstable systems, because with a crash, you maybe have more data loss. But I thingk it improves performance. There’s also a paragragh in the ext3-Kernel-documentation.

Thanks again for this howto! I guess you can add safely the “nodiratime” option. Have a look at the other options.

I was looking into nodiratime, and it looks like if you flag ext2/3(/4?) with noatime, you automatically get nodiratime too. I’m going by the discussion here, where the source code seems to show as much.

“You can pickup a little speed boast by making the the swap partition the last partition on the hard drive. This area of the hard drive has the highest read/write speed. This will likely vary from drive to drive. Best is a seperate drive for swap, last partition, and on the fastest drive.”

Isn’t it the other way around? The disk is round so the center turns faster. You’d want swap at the begining or center of the hard disk.

If the disk is constant angular velocity (ie there is no shear between the inside and outside of the disk) then all portions of the platter go through the same amount of revolutions.

In the case of a 5400 rpm drive, every particle on the plater rotates about the axis 10800pi radians every minute.

The linear speed varies in a constant angular drive, so ideally you’d want the swap to be on the outside so it’s real fast. You might also want to have the /boot on the outside too.

One needs to be careful however, since sectors are indexed starting from the outside on constant angular velocity drives. Sector 0 /is/ the outside of the disk. This is different than constant linear velocity drives like cds and dvds where the first sector is actually on the inside of the disk. I hope that helps.