Saturday, September 3, 2011

Optimizing Ubuntu 11.04 for SSD

I recently upgraded my Dell XPS and installed a Crucial m4 64Gb SSD. In the occasion of starting with a fresh new disk I also installed Ubuntu 11.04. Being nervous about having too many write actions on the disk (even though that shouldn't be a problem with today's SSDs) I decided to make some changes to the configuration to reduce the number of disk actions.

WARNING: Be careful when making these changes as they can result in stopping your machine from booting!

DISCLAIMER: I will NOT be responsible for any damages or an inaccessible machine! You do this at your own risk, no guarantee is given.


1. Create /tmp/ in a memory RAM-disk.

The /tmp/ directory on any linux installation is primarily used for - yes - temporary files. Programs frequently create and delete files they need for temporary caching, communicating between sub-processes and other various reasons. It is safe to move /tmp/ to ram since the OS will clean the /tmp/ directory upon boot anyway - we will save ourselves a bit of time during boot.

To make this change edit the file /etc/fstab as a root user:


john@doe:$> sudo emacs /etc/fstab


Add the following line without touching any other part of the file:


tmpfs /tmp tmpfs nodev,noexec,nosuid 0 0


Make sure there are the white spaces between the different words.


2. Mount volumes on SSD using the noatime option.

By default Ubuntu writes the last accessed time attribute to files. This means that for every file access Ubuntu writes to disk (read and write!). The noatime option forces Ubuntu to no longer write the last read/write access time to the file. Edit your fstab file by replacing relatime with noatime in fstab:


john@doe:$> sudo emacs /etc/fstab


N.B. You may find out that some applications like mail agents may no longer see that files have changed; in that case use relatime: it will force Ubuntu to write the last access time only during writes to the files and no longer during read.


3. Move Firefox cache to RAM

Firefox puts its cache in your home directory by default. By moving this cache to /tmp/ you can speed up Firefox and reduce disk writes.

Enter 'about:config' in the Firefox address bar (without the quotes). Right click and create a new string with value 'browser.cache.disk.parent_directory'. Set the value to '/tmp'.


4. Move Chromium cache to RAM

Chromium has the same problem - it's cache is in your home directory. This means a lot of reads/writes to your disk during surfing. Unfortunately it is not as easy as with Firefox to move the cache to a different directory. In the following steps I will outline how I solved this on my machine. At this point I assume /tmp is in memory and not on disk (see the first change).

Create a directory in /tmp/ for chromium's cache
(as a normal user)

john@doe:$> mkdir -p /tmp/chromium


Make a symbolic link from the users home dir to /tmp/chromium (check man ln to see the syntax and use of the command)
(as a normal user)


john@doe:$> rm ~/.cache/chromium/Default
john@doe:$> ln -s /tmp/chromium ~/.cache/chromium/Default


Now we are going to prepare the machine:

1) create the directory /media/cache (once)
2) on startup (boot) copy the cache in /media/cache to /tmp/
3) on shutdown copy the cache from /tmp/chromium to /media/cache/


john@doe:$> mkdir -p /media/cache


Now we are going to create a file in /etc/rc6.d that will be executed upon shutdown of the system. It is called K02chromium. The first letter K stands for Kill. The two digits that follow are used for determining the order in which the scripts in that directory are executed during shutdown. The higher number gives a higher priority. The text after that is free and can be anything.

Do the following as root (sudo -i)


john@doe:$> sudo -i

root@doe:$> emacs /etc/rc6.d/K02chromium


Insert the following snippet:

#!/bin/bash

# use rsync to synchronize the temp dir with the backup dir (/media/cache)
# options: a all, r recursive, P progress, o keep owner
# --delete removes any files from the destination that are no longer there
rsync -arPo --delete /tmp/chromium /media/cache/


As root make the file executable:

root@doe:$> chmod +x K02chromium


Modify the file /etc/rc.local. This file is executed upon boot. Insert the following lines before 'exit 0':


# To make sure on startup the cache is copied to /tmp add to /etc/rc.local the following
# use rsync to synchronize the backup dir (physical) with the temp dir (also physical - do not use link)

rsync -arPo --delete /media/cache/chromium /tmp/


Save the file and your done!


Wednesday, March 16, 2011

Flash on Chrome on Ubuntu 10.04

If you are like me and almost blindly click on 'Update Now' when system updates are available in Ubuntu, you may have run into the same problem I had with Chrome. I am running Ubuntu 10.04, 64-bit and use Chrome as my primary browser (from Synaptic). After the automatic updates of a few weeks ago flash stopped working and Chrome would ask me everytime 'Flash is out of date - Run this time only or Update'. But the update it was linking to on the Adobe website wouldn't work for whatever reason.

Luckily the ubuntuforums.org came to the rescue. Using a Firefox plugin called Flash-Aid you can update the Flash player semi-automatically. This plugin is published on the Mozilla website.

To install this plugin do the following:

1. Start Firefox (since it is a plugin for Firefox, this won't work in Chrome)
2. Go to: Flash-Aid
3. Follow the instructions
4. After the execution of the script restart your browser(s) and Bob's your uncle!

Wednesday, July 29, 2009

Cellphone pictures

I am not sure if it ever happened to you, the situation where you want to take the ultimate picture and your camera battery is empty. You then resort to using your cellphone, since all mobile phones these days have a camera built in. So this is what happened to me: on vacation I wanted to take some pictures only to find out my battery was empty (and of course I didn't have any spare ones for my digital camera). I decided to use my Nokia 3500c to make the pictures. At home, however, how can you transfer them to your computer? Since I don't have a memory card in the cellphone, the USB cable won't see the images (only PIM info). Then I decided to use bluetooth for transferring the pictures from the phone. The following blogpost describes the exact command line instructions to download the pictures from the phone.
Bluetooth transfer

Saturday, June 6, 2009

The C++ Lands


Just had to post this image that I found in a usenet group (comp.lang.c++). Courtesy to whoever made this picture!
Original URL

Monday, February 9, 2009

Converting avi to DVD format

In this blogpost I would like to explain how an existing avi file (in XVID or DIVX format) can be converted to DVD format, ready to be burned to disc. This for people who still have an old DVD player which cannot read DIVX and XVID movies.

First thing to do is to convert the XVID film into a format usable for DVD playback. The DVD standard typically uses MPEG-2 for video and AAC for audio. It is possible other formats are also supported, but I stuck to these formats.

The conversion to MPEG-2 can be done with ffmpeg an open source tool that is able to convert a lot of video files. The command line is as follows:

$>ffmpeg -i film.avi -target pal-dvd film.mpg

This will convert the file film.avi into film.mpg with the standard DVD format (resolution and framerate) for PAL televisions. For NTSC (USA) it is enough to change the 'pal' part into 'ntsc'.
After the file has been converted, it can be massaged to be put on a DVD disc. For this we need to create the directory structure that consists of the directories AUDIO_TS and VIDEO_TS. The directory AUDIO_TS is typically empty on a DVD, but the VIDEO_TS directory contains the files of type VOB and IFO that contain the video and audio in chunks of 1 GB. For creating this directory layout and the correct files, dvdauthor is a good tool. Dvdauthor requires an xml file that contains a description of the structure of the dvd layout. It is very powerful and allows for a lot of customization. In this example I keep it simple with one single file that has 4 chapters:

<dvdauthor dest="DVD">
 <vmgm />
  <titleset>
   <titles>
    <pgc>
     <vob file="film.mpg" chapters="0,15:00,30:00,45:00,1:00:00"/>
   </pgc>
  </titles>
 </titleset>
</dvdauthor>

Save this file as film.xml to the same directory as where film.mpg resides. With dvdauthor now the layout will be created as follows:

$>dvdauthor -x film.xml

This command will create a directory DVD with inside the directories AUDIO_TS and VIDEO_TS. The VIDEO_TS directory will contain the VOB files that contain the video and audio. This structure can then be burned to disc using tools like K3B.

PS: both tools can be installed in Ubuntu using:
$>sudo apt-get install ffmpeg dvdauthor

PS2: There are other tools with which you can accomplish the same job:

Sunday, January 18, 2009

Ubuntu's harddisk killing bug fixed

On slashdot it is mentioned that the famous harddisk killing bug for laptops has been finally fixed. This bug causes laptop harddisks to park and unpark the heads very frequently (as often as every 15 seconds) causing early wearing out of the harddisk. For months fixes have been floating around (do a google for Load_Cycle_Count Ubuntu) but until now it was never really fixed in the distribution. At the moment the fix is in testing for 8.04, 8.10 and 9.04 and should be in the repositories soon.

Saturday, December 6, 2008

Graphical layout of dependencies between static libraries

Back to linux! This week at work I got introduced into a new tool that helps resolve dependencies between static libraries. To organize your C++ code better, it might be a good idea to develop static libraries, which are linked to the executable. In our situation we had several static libraries that had interrelationships that caused linkage problems. It is a known fact that g++ (ld) has a strong dependency on the order of the static libraries on the command line. Other compiler/linkers such as IBM xlc and Microsoft Visual Studio compiler are less if at all sensitive to this. And so it also caused problems when linking our libraries with the program. Some libraries had to be repeated on the command line for the linker to resolve all the symbols.
Again, the power of the linux command line came to the rescue this time. There is a tool called lorder that is able to generate output showing which static libraries depend on each other. It uses nm that outputs the symbols in the static library. The program lorder will list for each static library on which other library it (directly) depends. This output is then massaged a bit such that it can be used with dot (a tool that is able to generate a graph from a text input file). Dot can write its output to .png, .jpg, .svg and even .pdf files! So, by using lorder, five lines of script to convert the output of lorder into the correct format for dot, and dot itself, a graph was created showing the interdependencies between the static libraries. A picture says more than a 1000 words. And, also in this case, we found some cycles in the graph, causing the linkage problems!