How to make Ubuntu extremely fast

Old hardware? Want a faster boot up? Need to free some system resources? Want snappier applications? This is for you.  Note, I wouldn’t suggest doing anything within this if it doesn’t make sense to you.

Boot Process

1. Remove Network Manager if you do not need it “sudo apt-get remove network-manager”. If possible give yourself a static IP in /etc/network/interfaces like so:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
network 192.168.1.100
broadcast 192.168.0.255
gateway 192.168.1.1

Having a static IP helps with boot time as your machine doesn’t have to communicate with the router/dhcp server as much to obtain an address.

2. Also remove firestarter or whatever graphical firewall frontend you’re using. Learn to control iptables at boot up and shutdown. It’ll be much snappier.  Some have been critical of this step, but firestarter is used quite frequently in ubuntu and it runs an additional startup process before the desktop environment is loaded.  Doing straight iptables is much faster, plus you’ll learn something anyways.

3. Install bum, “sudo apt-get install bum” and run it with root access. Shut off all unnecessary services. If you’re not sure about a service research it before shutting it off. Also, install sysv-rc-conf. Run the application as root. This will allow you to control, in an easy way, what services start at which run level. It’s like bum, but more detailed. Be very careful with which services you are removing from which run-level. If you don’t know what you’re doing here, research it or don’t touch it. After you do this you may want to reboot to make sure you didn’t break anything.

4. Turn off usplash in grub. (Mind you, you’re bootup won’t be as pretty as the splash will go away).

  • vim /boot/grub/menu.lst
  • on the kernel line delete the words “splash” and “quiet”
  • Reboot to see the changes.

I remove “quiet” simply to show what’s going on.  It does not have to be removed.

5. If you have a dual core processor, you can decrease your boot time with concurrency.

  • sudo vim /etc/init.d/rc
  • and find the line CONCURRENCY=none and change it to: CONCURRENCY=shell
  • Reboot to see the changes. (tired of rebooting yet?)
  • automounting encrypted drives done with dm-crypt/luks will not work with concurrency.

6. Remove some TTYs

I could easily do this by editing /etc/inittab and then commenting the extra TTYs there. With the new upstart mechanism in place, things are a little different.

You have to edit /etc/default/console-setup file. This file defines how many ttys should you get.

Change ACTIVE_CONSOLES=”/dev/tty[1-6]” to the number of consoles you want. Lets say, 3 ttys, then change it to “/dev/tty[1-3]“.

And then goto /etc/event.d/ and change the ttyx files that you DONOT want. Edit them and comment lines starting with “start on runlevel”. So, in this case, you’ll comment the start line in tty4..tty6 files.

Rebooting shoud minimize the number of consoles for you. Worked for me!! Good luck, NOTE: Even though you’ve reduced the tty number, X is still on Alt-F7. Again, go ahead and reboot to make sure you didn’t break anything.

Tune Your Hard drive

Speed up your ext3 file system

The following tweaks assume that you are using an ext3 filesystem for your Ubuntu OS and they will offer a noticeable performance boost! However, there is also a bad side of them… if you don’t have an UPS and your system will power off accidentally or because of a power loss, YOU WILL LOSE IMPORTANT DATA! (don’t say you haven’t been warned)


Open a terminal (Applications -> Accessories -> Terminal) and type:

CODE
sudo vim /etc/fstab


WARNING: The following is just an example! Do NOT copy the lines into your /etc/fstab file! Just REPLACE the options marked with underline with the ones marked with bold!

From this:

# /dev/sda1
UUID=19f70288-7340-40c0-82d1-ee4b218fee1d / ext3 relatime,errors=remount-ro 0 1

To this:

# /dev/sda1
UUID=19f70288-7340-40c0-82d1-ee4b218fee1d / ext3 noatime,nodiratime,errors=remount-ro,data=writeback 0 1

Save and close. Now type the following command in the terminal:

CODE
sudo vim /boot/grub/menu.lst


And add the following option…

rootflags=data=writeback

…to the end of the following lines:

# defoptions=quiet splash vga=795 (by default, Ubuntu doesn’t have the “vga=795? option on this line. It appears if you did the second tweak from the first step (see above)).

# altoptions=(recovery mode) single

Save and close, and paste the following command in the terminal:

CODE
sudo update-grub


Type now the following command in order to manually change your filesystem “on-the-fly” into writeback.

CODE
sudo tune2fs -o journal_data_writeback /dev/sdb2


ATTENTION: Please note that /dev/sdb2 is MY root (/) partition. If you have the root (/) partition in another place (for example /dev/sda1 or /dev/sda2) change it accordingly. Please look in /etc/fstab for this!

That’s all, now reboot your system and when you get back, you should feel an increased speed in video, image or audio usage.

Tune your swappiness

If you have been running Linux systems for some time and you have used applications like ‘top’ to see what’s going on in your machine, then you’ve probably wondered: Where has all my memory gone? You should know that the largest place it is being used in is the disk cache, as the cached memory is free and it can be replaced anytime if a newly started application needs that memory. Linux systems are made like this to use so much memory for disk cache because the RAM is wasted if it is not used and if something needs the same data again, then there is a very good chance to be in the cache memory.

Open a terminal (Applications -> Accessories -> Terminal) and paste the following code:

CODE
sudo vim /etc/sysctl.conf


Now add the following line at the end of this file:

CODE
vm.swappiness=10


The number at the end of this line can be between 0 and 100. At 100 the Linux kernel will prefer to find inactive pages and swap them out, while value 0 gives something close to the old behavior where applications that wanted memory could shrink the cache to a tiny fraction of RAM. Save, close and reboot.

Preload and Prelink

prelink

Any executable that makes heavy use of shared libraries can benefit from prelinking. Prelinking resolves addresses of shared libraries in advance this reduces number of relocations.

Prelink is also useful in the context of security since we can tell prelink to make libraries load at random addresses until next run of prelink. This is useful since libraries won’t load at fixed addresses on every system.

You can install prelink by issuing following command.

sudo apt-get -y install prelink

Change a line inside the configuration file /etc/default/prelink from

PRELINKING=unknown

to

PRELINKING=yes

We will do our first prelinking by executing following command

sudo /etc/cron.daily/prelink

Thats it you don’t have to do anything else. Prelink daemon will run periodically to optimize your newly installed executables.

preload

Preload is a little application that monitors files of frequently used applications and and loads them in to the memory when system is idle. This usually results in lesser startup times for those applications. Install preload by executing following command.

sudo apt-get -y install preload

New Applications

Ok time to install a faster window manager and set of applications:

Add this repo in /etc/apt/sources.list:

#openbox https://launchpad.net/~k-belding/+archive
deb http://ppa.launchpad.net/k-belding/ubuntu hardy main
deb-src http://ppa.launchpad.net/k-belding/ubuntu hardy main

and then:

sudo aptitude update && sudo aptitude install openbox pypanel gmrun obmenu obconf nitrogen gtk-chtheme sakura scrot kazehakase sylpheed rtorrent irssi finch decibel-audio-player xfburn mirage abiword gnumeric leafpad epdfview xarchiver pcmanfm ivman

For an explination of each:

  • openbox is an alternative window manager that we’ll be using as our desktop environment. It’s snappier than Fluxbox since it was rewritten to no longer be based off blackbox code.
  • pypanel - since open box comes with no panel, this is an extremely light weight one, it can be configured in ~/.pypanelrc. You’ll need to add this to .config/openbox/autostart.sh with the line: pypanel &
  • gmrun - will give you a small run dialog upon running
  • obmenu - graphical openbox menu editting app
  • obconf - graphical openbox theme changer, among other options
  • nitrogen - lightweight application to change wallpapers
  • gtk-chtheme - will allow you to change gtk themes. Icon themes and fonts can be specified in .gtkrc-2.0
  • sakura - a light weight tabbed terminal. Easier to configure than aterm, xterm and the like.
  • scrot - a command line screenshot tool
  • kazehakase - a lightweight browser based on the gecko engine (A heads up about the hardy package: you can’t view the preference menu, it’ll crash. You can control most things through it’s config files and about:config)
  • sylpheed - a light weight email application
  • rtorrent - a command line torrent app
  • irssi - command line irc
  • finch - the command line version of finch
  • decibel-audio-player - a light weight gtk based audio app
  • xfburn - a burning application from the xfce suite
  • mirage - an extremely light weight image viewer
  • abiword and gnumeric - lighter office apps when compared to open office.
  • leafpad - extremely lightweight notepad app
  • epdfview - lightweight pdf viewer
  • xarchiver - lightweight archiving and compression tool to replace file-roller with.
  • pcmanfm - tabbed, lightweight file manager.
  • ivman - a behind the scenes auto-mounter. You’ll need to add this to .config/openbox/autostart.sh with the line: ivman &

Here are some great reads on how to configure openbox:

  1. http://icculus.org/openbox/index.php/Main_Page
  2. http://wiki.archlinux.org/index.php/Openbox
  3. http://gentoo-wiki.com/HOWTO_Openbox

And that’s it. Log into openbox and get to configuring things the way you want it.

Use Readahead

This guide asks you to use the command-line to issue some commands, and uses the readahead-list and readahead-watch applications to profile a bootup. Changes to the system are easily reversible and the worst negative impact would be a reduction in login speed (the irony!). Of course, since you will be doing some things with root access, failure to correctly type in some commands may lead to permanent damage to your software or data. These changes are unsupported by Ubuntu developers. You probably shouldn’t try this unless you have more than 512MB RAM.

PART 1: Profile Login Sequence

First, we need to ask readahead to monitor a login sequence and make note of all the files read during this period. Advanced users may point out that during bootup, there is a GRUB argument “profile” that causes Ubuntu to optimize bootup. We will need to essentially manually replicate what this boot option does, but save the output to a different file.

First, let’s store our readahead list into a ~/.readahead directory.

Code:
mkdir ~/.readahead

Now, log out, and press CTRL+ALT+F1 to log into a terminal. Start the profiler:

Code:
sudo readahead-watch -o ~/.readahead/gnome.root /

This will grind the disk for a while (up to a few minutes) then it will return you to a command prompt. The profiler is now in the background watching all actions. Now, without logging out, go to your GDM prompt (ALT+F8 ) and log in normally.

after you are fully logged in, press CTRL+ALT+F1 to go back to your terminal, then run:

Code:
sudo killall readahead-watchsudo chown jdong:jdong ~/.readahead -R

Replace jdong:jdong with your user and group name. Now, we need to go prune this list a bit. Especially if you have large files on your desktop (like a 1GB AVI), the login sequence may touch it, causing readahead to think it should load the whole thing into memory! In a terminal, run:

Code:
cat ~/.readahead/gnome.root | xargs -i ls -lk {} | sort -rn -k +5 | less

This will display all the files readahead wants to cache, sorted by largest file first. The 5th column (before date) is the size of the file in KB. Make sure there’s nothing glaringly large. If it’s bigger than 10,000KB or so, it’s probably not worth preloading. You can remove unwanted files from the preload list by opening ~/.readahead/gnome.root in your favorite editor, and deleting its line.

If you have home on a different partition as root, you should repeat Part 1 for each partition, replacing gnome.root with a different name, and replacing the mountpoint / with each interested mountpoint.

PART 2: Hooking this into the login sequence.

Next, we need to tell Ubuntu to do this readahead on every login. I am going to use /etc/X11/Xsession.d for this, but if you have another preferred way to execute things before everything loads, be my guest!

Create a file called /etc/X11/Xsession.d/00readahead and put this in it:

Code:
for list in ~/.readahead/*; do  readahead-list $list &done

wait

Save the file. Now, you can reboot to try it out. You will notice the login
“hang” at the orange screen while the disk works without much grinding, then once that is done the bootup should soar as if it were a fully cached login. This brings my login session to around 30 seconds, a notable improvement.

PART 3: Hook into bootup sequence

Often times, we don’t log in immediately when the prompt comes up. We might be getting a cup of coffee, or an entire lab might be turned on before students arrive. It makes sense to cache a login as a part of bootup. Open up /etc/rc.local in your favorite text editor, and before the exit 0 statement, add:

Code:
for list in /home/jdong/.readahead/*; do  readahead-list $listdone

Note you need to hard-code a particular user in there, and this time we don’t background it. (We could, but there is not much motivation to)

Now, reboot, and wait for all disk activity to stop before logging in. This
time, I get a login speed of 19 seconds.

You might have two common questions at this point:

1. How much time does it take to call readahead again on files that have been cached once already? About 0.05 seconds to call readahead on the same list a second time

2. How much overhead does it add to bootup if the background readahead was still going, and you tried to log in? About 2 seconds on my setup

Conclusion

In my case, applying this readahead hack lead to a 10-second improvement in login speed in the worst-case scenario, and a remarkable doubling in login speed when the system idles at the login prompt for a few seconds.

This is a pretty appreciable improvement and it would be nice if a nicer version of this hack can be added to Ubuntu. The basic idea should be fairly simple to adapt to an /etc/readahead/readahead.gnome file representative of the default system and hooked by an Xsession.d script.

Many more applications come to mind as taking a long time to load while the disk grinds (Firefox? Openoffice? Eclipse?). You can use a procedure very similar to this to write a “wrapper script” that first performs a readahead-list call on a list, then call the application with the original arguments. I’d be interested to hear of any improvements gained by that method.

Undoing readahead

Remove, remove, remove! Delete the ~/.readahead directory, delete /etc/X11/Xsession.d/00readahead, and delete the line you added to /etc/rc.local

All Done

Your system should be a 100 times more snappier.

Related Posts

Tags: , , ,

20 Responses to “How to make Ubuntu extremely fast”

  1. cwillu Says:

    It would be wise to warn your readers that setting ext3 to writeback will cause applications that use efficient (and normally safe) approaches to storing their data to unrecoverably lose data if the machine crashes at a bad time (if the power goes out, for instance). This include firefox, search tools like tracker and beagle, media library applications, and so forth.

    More thorough explanations are available:
    http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/
    https://bugzilla.mozilla.org/show_bug.cgi?id=421482#c45
    http://www.sqlite.org/atomiccommit.html

  2. Greyed Says:

    Also the suggestion of noatime and nodiratime it just horrible. This can cause hard-to-track problems with applications that look at atime. The default, as shown in the “before” example, is relatime. relatime only updates the atime on changes/modifies of the file. Since the OS is already changing/modifying the file and setting the mtime accordingly there’s really no practical impact of not setting atime then. IE, it’s a sensible noatime and should be left well enough alone.

  3. Sivanandhan, P. Says:

    Can someone tell me how removing “quiet” from kernel parameters increase booting speed ?

  4. Thomas Stromberg Says:

    I’m not sure how avoiding firestarter would help your bootup at all. So far as I know, they just write out rules when they are changed. I think this post screams for proper data and analysis, as there seems to be some snake oil remedies in here.

  5. bAsem Says:

    can u please tell me how to automount a partition in hardy .. coz i use virtualbox and it needs the partitions to be mounted to load the virtual environment

    and i dun want to do it manually each time ,, :) thanks alot and thanks alot for a really usefull tuto

  6. Jason Says:

    What is the point to this boot up speed thing? Isn’t the best part about Linux not having to reboot? I do it once every 90 days or so. A little extra time isn’t hurting anything!

  7. Alex Says:

    Hi Sivanandhan, P

    I have no idea how removing “quiet” would help. But the other way round, yeah, putting it there could save some console I/O operations I guess.

  8. ttux Says:

    The best improvement ever: compile your own kernel with only your hardware and as built-in.

    An other great improvement: do not use ubuntu but a better distro such as archlinux :-)

  9. Vadim P. Says:

    “how to gimp ubuntu so without features it’s fast” is how this looks to me.

    Would not recommend to anyone at all except people who are highly experienced with Linux.

  10. ttux Says:

    If you have enough RAM, you can as well choose to not have swap, you won’t use it anyway.

  11. starenka Says:

    Cheers for *preload*. It will cost me less tea pots to start zend & eclipse :))

  12. Nathan Says:

    To everybody giving the author a hard time, get a life. If you don’t like his methods then just move along. Not everything here is going to appeal to every person in every situation. Just pick and choose what would work for you. And to the person that said they boot their computer only every 90 days, you must never have owned a laptop.

  13. kaloskalyre Says:

    hey-
    just tried a few of these tips

    setting concurrency to ’shell’ prevented Ubuntu from automounting my (encrypted) home directory and caused fsck to fail every time i rebooted, luckily i printed out your instructions so i could undo that

    using readahead and preload did noticeably improve my system’s speed, thank you :)

    didn’t try anything else

  14. mh Says:

    can the commands
    * sudo vim /etc/init.d/rc
    * and find the line CONCURRENCY=none and change it to: CONCURRENCY=shell
    * Reboot to see the changes. (tired of rebooting yet?)

    in any way adversly affect the boot when I have a hd with encrypted lvm?

  15. admin Says:

    automounting encrypted drives done with dm-crypt/luks will not work with concurrency.

  16. rhw Says:

    I would not do any of the things mentioned here. I had a Feisty install that I “tweaked” like this and I ended up with nothing but data loss and instability. The speed up you get with these tweaks is not even noticible during normal every day use. It’s akin to the overclockers that squeeze 400 MHz out of a processor to get a couple hundred points more in a benchmark, and end up with overheating and stability problems and no real performance gain in daily use. Linux is not Windows. It doesn’t need to be tweaked!

  17. admin Says:

    The entire point of linux is that you can change whatever you want, how you want. And sometimes depending on the quality of distro, or various release of a certain distro, it REQUIRES it to be tweaked. So don’t say “linux doesn’t need to be tweaked”, that’s part of the reason it’s as popular as it is, is because you can tweak it and change it as you see fit.

  18. inode_horses Says:

    On my system I don’t have to add rootflags=data=writeback or rootflags=data=journal to my menu.lst.

    I just did sudo tune2fs -o journal_data_writeback or sudo tune2fs -o journal_data to /dev/sdX.

  19. David Says:

    The bit about prelink is perfectly safe. IMHO prelinking should be done automatically. We have a 64 bit address space. We are not going to use it up. Prelinking does not buy a huge amount. I was a performance engineer for 2 years on an embedded distro. I found it bought you about 4% improvement.

  20. Abhishek Says:

    Great tute!
    I knew about many of these tweaks but some were completely new, thanks.

    Things I won’t try at all are: Boot Process 1,4 and Speed up your ext3 file system. The ‘Speed up your ext3 file system’ has some very dangerous outcomes (i.e., data loss) if your ubuntu crashes when starting applications etc., I know coz I have tried something similar before.

    The things regarding bum, sysv-rc-conf, TTYs, prelink, openbox, readahead etc. are great and very informative and worth trying IMHO (thats what I’m gonna do now ;-)).

    Thanks for the how to.

Leave a Reply

You must be logged in to post a comment.