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!

Yahoo going private?

In recent days the news surfaced that group of investors led by Jonathan Miller (of AOL fame) is interested in buying Yahoo and taking it off the stock exchange source: nytimes. At the same time Microsoft has made another attempt to buy Yahoo (this time hidden as 'we are only interested in the search business') for $20 billion. Of course the offer by Microsoft should not come as a surprise, as they were always interested (and determined) to take over Yahoo. It's also up to the board of directors of Yahoo to decide what they want to do with the company. Carl Icahn has now three seats on the board, and for sure will look for the most value. (At this point he should show his true colors: if he goes with the private investors, he was always looking for the best value; if, on the other hand, he goes with the Microsoft offer.... it will raise again the question: was he always working in favor of Microsoft?)
Microsoft might hit a snag with an offer made by Jonathan Miller. But, eventually I believe Microsoft will get Yahoo, one way or another. It is just a matter of time. The group of investors might cause a better price for the current share holders of Yahoo. Time will tell, but I'd put my money on Microsoft (even though I am a Linux enthusiast!)

Sunday, November 23, 2008

Kernel vulnerability found in Vista

According to this article a kernel vulnerability was found in Vista. It requires administrative rights to install a rootkit or other damaging software. The only hurdle to take is to click 'Yes' when UAC pops up and your system is hacked. According to the article:
"We have worked together with Microsoft Security Response Center in Redmond since October 2008 to locate, classify and fix this bug," Unterleitner wrote. "Microsoft will ship a fix for this exploit with the next Vista service pack."

Mind you, my intention is not to bash Microsoft. The reason I put it here is to show that apparently with something a serious as this the open source world is much more agile and quicker to respond. Fixes for problems like this usually come out within the week they are discovered. As for Microsoft: The next service pack is not to come out for at least one or two months. In my opinion, another reason why you should use Ubuntu (or any other open source Linux-based distribution)!
Vista users beware!

Tuesday, November 18, 2008

Yahoo ready for take over?

Jerry Yang has given up. He will step down as CEO of Yahoo (although he will keep a 'high position' within Yahoo) making way for his successor. Susan Decker has been mentioned in the rumor mill, and according to official notes, Yahoo is looking inside as well as outside of the company.

What's next? Obviously, with Yang out of the way, nothing should stand in the way of Microsoft to take over Yahoo. My doubt remains; was this the plan of Icahn all the way? Was Icahn always working for Microsoft? Earlier this year, he lead a group of investors trying to replace the board of directors of Yahoo, after a failed take over attempt by Microsoft. Now with Yang out of the way, Microsoft can walk right in. Fact remains, Icahn is a smart man, and he became rich investing at the right time in the right companies and of course he will look after his own interests first.

What is to become of Yahoo after it is taken over by Microsoft? Will it be destroyed, and market share goes to Microsoft Live, meaning that everybody has to convert to hotmail? Future will tell. In the mean time, I'll be checking into gmail....

Tuesday, November 11, 2008

Make Linux Harder - Better - Faster

Courtesy of LinuxHaxor, a good set of links on how to improve your Linux / Ubuntu installation.

Monday, November 10, 2008

The three musketeers: Google, Microsoft and Yahoo

Everybody has heard of the saga between the three musketeers: Google, Microsoft and Yahoo: first Microsoft wants to buy Yahoo. Yahoo refuses, and runs into the arms of Google. Google finds an ad-deal with Yahoo will cause too many (legal) problems. Together they would have had more than 80% market share of the search market. Then, Yahoo runs back to Microsoft, but Microsoft is no longer interested. Smart play by Ballmer? Let's look the line of events.

In February Microsoft goes public with an unsolicited bid on Yahoo of $31 per share or $44.6 billion. Ten days later, Mr. Jerry Yang (CEO and founder of Yahoo) refuses the offer with the message that Microsoft undervalues Yahoo. In April, Ballmer tries again, this time with an offer price of $33 per share, and gives Yahoo a three-week deadline for making a deal. Again, they are not able to make a deal, and Microsoft walks away from the table.

In August Carl Icahn shows up, as he acquires $2.5 billion of stock; enough to get him three seats on the board of Yahoo. My hunch at the time was that Microsoft was all behind it, still to get (some) influence on Yahoo in the shape of Icahn.

Last week Google decides to pull-back from the table and Yahoo is forced to go back to Microsoft, to see if there is a deal possible. Ballmer has said in September (on a Gartner technology conference in Florida, according to Marketwatch) that it still makes sense economically to make a deal with Yahoo. Is he punishing Yahoo? Is he playing a sadistic game? Will he wait until the price is right? At the moment, the stock price of Yahoo is trading around $12.

My uneducated guess is that we'll see the acquisition of Yahoo by Microsoft, where the ones to pay will be Jerry Yang and Roy Bostock (chairman Yahoo). And of course, the shareholders. And guess what? Microsoft will be laughing last.

Thursday, November 6, 2008

Obama Won!

Ok, usually I am not really involved in political discussions or opining, however, this time I am really happy Obama won. It is a fresh and young face that holds a lot of promise. It is clear that America is ready for a change. But before crying victory, he still has to show us as to what he is capable of. The tanking economy and financial market regulations, the war in Iraq and globalisation. Unfortunately, effects on the major issues like the economy are only visible in the long run. As for the tech industry, let's hope he puts America back on the map (I firmly believe that on a number of issues Europe is way ahead of the U.S.A).

Let's hope he is able to bring about change, and make the world a better place.

Sunday, November 2, 2008

Ubuntu 64-bit, Opera and flash

Finally flash seems to become something normal on Linux, and supported by most distributions. At the moment Adobe only has a flash-player for 32-bit Linux, but luckily it can also be used in a 64-bit installation using nspluginwrapper. Installing flash for Firefox is simple in Ubuntu: open Synaptic, search for flashplugin-nonfree and install it. This installs the flash-plugin, as well as nspluginwrapper for 64-bit installations. For Opera, it is a bit more work: download the plugin from the Adobe website and put it in the plugins directory. Here follow the instructions to get flash working in Opera 64-bit.

1. Go to the Adobe flashplayer download website and select the .tar.gz for Linux option. This will download the archive; we are only interested in extracting one single file. (Do not download the .deb!)

2. Extract the files from the archive.
$> tar -zxf install_flash_player_10_linux.tar.gz

3. At this point we have to copy the plugin file to the correct directory where Opera can find it.
$> cd install_flash_player_10_linux
$> sudo cp libflashplayer.so /usr/lib/opera/plugins

4. Start opera and go to YouTube where you can test your newly installed flashplayer.

You can now safely delete the directory where you extracted the archive (install_flash_player_10_linux/).

Ubuntu and Dell XPS m1530

Since a month I am the happy and proud owner of a Dell XPS m1530 laptop. Its configuration is the following:

* Processor: Intel Core 2 Duo T9300 (2.5 GHz, 6 MB L2 cache)
* Graphics: nVidia GeForce Go 8600M GT with 256 MB video memory
* Screen: 15.4-inch widescreen, 1680 x 1050 CCFL with 2.0 megapixel webcam
* RAM: 4 GB (2 x 2GB) 667 MHz DDR2
* Harddisk: 400 GB SATA 5400 RPM (Samsung)
* Wireless: Intel 4965 AGN WiFi
* Bluetooth: Dell TrueMobile 355
* Fingerprint reader
* DVD+/-RW slot-load drive
* 90W AC adapter, standard 9-cell battery

Installing Ubuntu is a breeze, all hardware is recognized and configured automatically. However, you have to set up a kernel boot parameter to avoid the cursor from going crazy. This is a well known problem, and easy to fix. For this fix, and other tips on configuration and installation of Ubuntu, I found an excellent wiki. Of course you shouldn't forget to check out Ubuntu Forums.

Grub on a separate partition

If you are like me and like to play around with different distros, while not loosing your work, you probably have a setup with several partitions. In my setup, I have Windows Vista (hey it came with the machine, not my choice!), Ubuntu 8.04.1 32 bit and Ubuntu 8.10 64-bit. I noticed that every time you install a new distro, or version of Ubuntu, the grub installation (i.e. stage2 and menu.lst) move to the last installed distro. Problems arise when you start deleting partitions that you don't use anymore. Keeping track of which menu.lst to update is quite a chore. There must be a simple solution to this. And there is, install grub on its own partition and update only the files on that partition. Mind you, this is not a bootable partition, nor does it contain images of kernels,etc.

Thanks to an excellent guide I took the big step. And it worked! Basically what you do is create a new partition and install only the grub files on it. Here's a summary of the procedure:

1. Create a new partition (using gparted, fdisk, etc)
Let's assume this partition is called /dev/sda3
2. Mount the partition on your system, for example under mnt
$> mount /dev/sda3 /mnt

3. Create a new directory called /boot on the new partition
$> cd /mnt
$> mkdir /boot

4. Copy all files from your /boot/grub to the newly created directory (with -r)
$> cp -R /boot/grub /mnt/boot

5. Use the grub tool to update the grub installation files
$> grub

grub> find /boot/grub/stage1
(hd0,2)
(hd0,5)
(hd0,6)

grub> root (hd0,2)

grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,2)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
Done.

grub> quit


In the above example you see that grub has found 3 (three) different installations of grub configuration files. Partition 3 (three) or /dev/sda3 is our target, therefore we have to use hd(0,2), because grub starts counting from 0, instead of 1.

6. Done.

Make sure you do a trial run of all operating systems to make sure they boot.

Sunday, October 26, 2008

First post

Ah, finally also I gave in to the internet frenzy. It seems these days everybody is everywhere, you'll find your friends on myspace, facebook, linkedin, twitter, to name a few. I decided to give this bloggy-thing a try, moreover to find a safe place to store my linux knowledge, experiences and setup. It might even be interesting to other people.

Well, that's it as far as my introduction goes. Hopefully next time I'll have something interesting to tell ;-)