Optimize Debian/Ubuntu for SSD

Original post: http://askubuntu.com/questions/1400/how-do-i-optimize-the-os-for-ssds

I have successfully used several different techniques to improve the way Ubuntu uses the storage device, whether that be solid state or traditional drives. For SSDs you are looking to minimise the number of times the drive is written too, as reads should not add wear to the drive.

1) Manage the swap file

If you do not hibernate your computer and you have ample RAM memory to run all your applications, then in theory you do not need a swap partition. In case that you have a mix of SSD and hard drives, place your swap partition on the hard drives only.

2) No Writes for Read Timestamps (suitable for SSD’s and hard drives)

Mounting your partitions with the options noatime and nodiratime will stop timestamp writes when you read files and folders. These timestamp writes are not generally required unless you use a local mail server client such as mutt.

Edit your /etc/fstab configuration file (carefully – take a backup to be sure as breaking your fstab configuration can prevent you system from working):


#backup your fstab file
cp /etc/fstab ~/fstab-backup
#open the file in your favorite editor (with root permissions)
gksudo gedit /etc/fstab

Edit the mounting options for your partitions by adding the text noatime and nodiratime to the lines defining your root (/) and other partitions if you have them such as (/home).
Note: if you have a /home partition, start with that just changing that partition if you are concerned about breaking something


# / was on /dev/sda2 during installation
UUID=587e0dc5-2db1-4cd9-9792-a5459a7bcfd2 / ext4 noatime,nodiratime,errors=remount-ro 0 1

# /home was on /dev/sda3 during installation
UUID=2c919dc4-24de-474f-8da0-14c7e1240ab8 /home ext4 noatime,nodiratime,defaults 0 2

Enabling trim

In case your ssd supports TRIM (all intel and samsung ssds do) you can enable TRIM by adding the discard option to your fstab file so the final fstab file looks like this:


# / was on /dev/sda2 during installation
UUID=587e0dc5-2db1-4cd9-9792-a5459a7bcfd2 / ext4 discard,noatime,nodiratime,errors=remount-ro 0 1

# /home was on /dev/sda3 during installation
UUID=2c919dc4-24de-474f-8da0-14c7e1240ab8 /home ext4 discard,noatime,nodiratime,defaults 0 2

These changes are effective after a reboot

3) Minimising writes from the OS and applications

Assuming that you are not running a mission critical production-server, most people do not look at logs should something go wrong (especially as serious errors are rare for most Ubuntu users). Therefore you can configure Ubuntu to write all logs to ram instead of the ssd.

Note: only make the following changes when you have installed all software you are going to use (especially things like Apache web server), otherwise you may experience some issues with missing directories in /var/log

Open /etc/fstab with an editor (assuming you have backed up the /etc/fstab file)


gksudo gedit /etc/fstab

Add the following lines at the end of the fstab file and save:


# Uncomment these after all server based applications installed - eg. apache
#tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
#tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
#tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
#tmpfs /var/log/apt tmpfs defaults,noatime 0 0
# none /var/cache unionfs dirs=/tmp:/var/cache=ro 0 0

Alignment:

What is often pointed out is the right alignment of the partition. This should be equal to the block size of the SSD. Play safe and make your partitions aligned to MiB boundaries. Note that you can’t do this with the Ubuntu installer’s partition tool (which uses MB not MiB), but you can boot the live CD, use Gparted (which uses MiB), then click Install to use the partitions you set up.

The right scheduler:

A important point is the scheduler which should be noop. You can set this scheduler via kernelparameter elevator=noop or via a entry in rc.local:


echo noop > /sys/block/sda/queue/scheduler

Unbranded Firefox in Debian

Mozilla Firefox is a widely used web browser in many GNU/Linux distibution, including Debian OS. Debian uses a slightly patched version of Firefox and due to the brand/name restrictions isn’t allowed to call their version Firefox anymore. Therefore, Debian re-brands the Firefox browser and calls it Iceweasel. (Same restrictions apply to Thunderbird which is called Icedove)

Iceweasel is Firefox, only with different name and logo. It performs exactly like Firefox and the extensions/add-ons are 100% compatible.

Manually Installing Firefox

Download Firefox

Download the latest version of the unbranded Firefox from Mozilla’s Website:
Link on their Website to 32bit builds: http://www.mozilla.org/en-US/firefox/all/
For 64bit builds for Linux goto: http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/

Install Firefox

#copy firefox tarball to /opt

sudo cp firefox-*.tar.bz2 /opt

#change to /opt directory

cd /opt

#extract tarball

sudo tar -xvf firefox-*.tar.bz2

#remove the tarball

sudo rm firefox-*.tar.bz2

Create Symbolic Link for Startup

If you previously had Iceweasel installed the file /usr/bin/firefox might already exist. On further inspection it’s just a script:


#!/bin/sh

FIREFOX="$(which $0)"
[ -x "$FIREFOX.real" ] && exec "$FIREFOX.real" "$@"

exec iceweasel "$@"

Basically it means if a file called firefox.real exists the shell is going to execute the firefox.real binary otherwise it will start iceweasel. Therefore create a symbolic link to /usr/bin/firefox.real


sudo ln -s /opt/firefox/firefox /usr/bin/firefox.real

Source Code Formatter for Blogspot

Add the following CSS Style to your Blogger template


pre.source-code {
font-family : Andale Mono, Lucida Console, Monaco, fixed, monospace;
color : #000;
background-color : #eee;
font-size : 12px;
border : 1px dashed #999999;
line-height : 14px;
padding : 5px;
overflow : auto;
width : auto;
text-indent : 0px;
}

surround your code with the following tags to add the source-code formatter:




chris@blogspot.com:~$ who

chris    tty7         2010-09-09 7:52 AM

For a long time I thought about documenting my technical adventures. Since I was a child I’ve been tinkering with computers and related technologies from mobile phones to game consoles to laptops. Challenging problems are inevitable and so I spend a considerable amount of time looking for nifty tricks and solutions to issues I enctounter. I thought about documenting my findings and solutions in a wiki or blog but never actually realized it. Instead, I wrote short how-tos and saved them locally in text-files. I hope that by sharing my tutorials I can help people facing the same problems. (^_^)

Thank you for reading my posts.