Reduce login time in Ubuntu/Linux

It has been well-documented that Ubuntu’s readahead system during boot significantly cuts down on boot time by reducing hard disk seeking via precaching commonly-used files during bootup. This feature, however, only lasts up to the GDM screen.

Recently I found out that this use of readahead can be further extended to improve the login time - the time it takes to reach the desktop after the GDM login screen.

!!! You probably shouldn’t try this unless you have more than 512MB RAM.!!!

Part 1 : Monitor login sequence

First, we need to ask readahead to monitor a login sequence and make note of all the files read during this period. The idea obviously is to begin reading these files as soon as you reach the GDM screen.

Let's store the readahead list somewhere.
mkdir ~/.readahead

Now, log out(CTRL+ALT+BACKSPACE), and press CTRL+ALT+F1 to log into a terminal.(Do not login from the GDM screen) Start the profiler now.

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

This will grind the disk for a while (up to a few minutes, so have patience and dont think you are screwed and try to abort it :) 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 (CTRL+ALT+F7 ) and log in normally.

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

sudo killall readahead-watch
sudo chown neo:neo ~/.readahead -R

Replace neo:neo 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:

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

This will output all the files readahead wants to cache, sorted by largest file first into the readahead_list file. Open the readahead_list file using your favorite editor. 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. Remove such unwanted files from the preload list by opening ~/.readahead/gnome.root and deleting its line.

gedit ~/.readahead/gnome.root

Part 2 : Hooking this into the login sequence

Next, we need to tell Ubuntu to do this readahead on every login. There are many ways one can do this. Let's use /etc/X11/Xsession.d.

Create a file called /etc/X11/Xsession.d/00readahead.

sudo gedit /etc/X11/Xsession.d/00readahead

Put the following in the file :

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


Save the file. Now you can reboot to test if this works.

Part 3 : Hook into boot sequence

Often times, we don’t log in immediately when the prompt comes up. 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:

Note : Replace neo in the first line by your username.

for list in /home/neo/.readahead/*; do
readahead-list $list

Now, reboot, and wait for all disk activity to stop before logging in. You should feel really nice :)

Undoing This :

Not much to do! Just delete ~./readahead directory, /etc/X11/Xsession.d/00readahead and remove the added lines from /etc/rc.local.

This improved my login time drastically. Hopefully it will improve your's as well.

Linux : Convert Real Media Files to mp3/ogg

The first thing you want to do when converting audio files is to convert them into .wav files. Mplayer can dump almost anything that it plays (and it can play almost anything) to raw .wav format.

mplayer -quiet -vo null -vc dummy -ao:pcmheader:file=".wav file" "inputfile"

To mp3 :

Lame is a command-line tool which can convert .wav to .mp3

lame input.wav output.mp3

To ogg :

oggnec input.wav

That's it!!! No need to search over net for free tools. No patch, registration key blah blah ... Yo LINUX !!!

Antix Mepis!!!

Once again its been a long time since my last post. I had almost forgotten that I had a blog of my own. I guess I had nothing much to share.

I think a lot of people who have recently bought new PCs or laptops have quite an old machine at their homes. Atleast I have, and it's a real mess. Running windows for so long has taken its toll too :) Every time I return home for holz, I have to deal with plenty of viruses and spywares.

I really got fed up with all this this time round and so decided to install the beautiful linux on my 800MHz P3 with 128MB RAM. Yeah, it's really old :) I grabbed my gutsy CD at once and tried to boot from the live CD, forgetting that it requires a minimum of 256 MB of RAM. Also, it came to me that my system wont be able to run Gutsy or for that matter any commonly used distro these days. So I searched for distros that could run on my PC, preferentially a debian based one coz i have got quite used to Ubuntu now. And thus I stumbled upon Antix Mepis.

Antix is a fast, lightweight and easy to install linux live CD distribution based on MEPIS. It almost succeeds in providing a fully functional and flexible operating system for both newbies as well as experienced users of linux. It runs even on 64 MB P2 systems. I downloaded the 300MB iso image and installed right away. And it was worth it. It's as if my old PC has come back to life!!! With all device drivers and codecs(!) preloaded, it has very less to complain about. And with linux comes the power of customization, which I found the most useful.

And now, having installed rhythmbox and a few more utilities, even my mom doesnt really face any problem operating it. Hail LINUX and dont throw away your old machines, use ANTIX instead :)