Two days ago I replaced my hard drive in laptop with a new solid state drive, and switched to the new Ubuntu 14.04LTS release. As everyone knows, frequent write operations slowly kill that kind of drives. Below I would like to show you a few tips how to tune your ubuntu to be more ssd-friendly, and enjoy the long life of your expensive drives.
- Turn off swapping
Nowadays RAM memory is cheap, 8 or 16Gb of installed chips are not any kind of luxury. Even buying more chips and installing them is not any sort of budget-ruining operation, so basically everyone can afford it and turn off disc swaping, which generates tons of write operations on it.
Tu turn off swaping, or drastically limit it, we need to change a system parameter which determines how high system load should be to enable disk swaping. The smaller this number is, the more load is needed to start swaping. You can check your current setting by typing in your console something like this:
To change this setting permanently, you need to type at the end of /etc/sysctl.conf file:
vm.swappiness = 1
If you change the value in the first line to 0, you will turn off swaping completely (not only limit it as in the example above).
- Turning off access time stamp(information that is written every time you access a file on your drive).
In order to do this, you need to add a noatime parameter to each mounted drive in /etc/fstab file. It should look similar to this example below:
UUID=86a5fc7a-efb8-41a7-b208-23827fc8fe4f / ext4 noatime,errors=remount-ro 0 1
- Turn on TRIM
Every SSD drive should be regularly cleaned (trimmed). If a disc is not trimmed, in the long run it starts to work slowlier and slowlier… To do so, we will use the fstrim command. In order to trim your disc manually, you need to type in your console:
fstrim -v /
which causes trim for the main file system. If you have your disc partitioned to more than one partition, you have to run the trim command for each of them. In my case, I have two partitions – one mounted as root / and second one as /home, it looks like this:
fstrim -v /
fstrim -v /home
I would recommend adding this command into /etc/rc.local file, so it will run each time you turn on your computer.
If your computer is always on (e.g. server), you can add these commands to a cron-job. In order to do so, you will need to edit the /etc/crontab file, and add lines similar to:
10 12 * * * root fstrim -v / && fstrim -v /home
These lines mean that we will run fstrim command for / and /home, every day at 12:10 am.
On my laptop I assigned this command to the cronjob, because I want to boot my system faster, and 12:10 am is a time, when I almost always have it turned on. So trim will be proceeded every day
- Do not use hibernation on your system
Yes, hibernation causes tons and tons of write operations onto your drive, so be aware of it.
For me, it was not a big deal, because my laptop is now booting in something around 3 or 4 seconds, so it is totally acceptable for me not to hibernate it.
- Do not run defragmentation process on your SSD drive! This will kill your drive!
- Move your temporary files (/tmp) and system logs (/var/log) to a virtual file system stored in RAM.
We can create a virtual drive in the operational memory and mount it at boot time into /tmp and /var/log. By doing this, we take some write load off of the ssd drive. The one and only failure of this solution is that we will lost all system logs every time we reboot our machine. But hey! Who cares about logs on workspace, right ?
What we need to do is to add the lines below into the /etc/fstab file:
tmpfs /var/log tmpfs defaults,noatime 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
Next, to restore directory structure at every boot, we need to add to our /etc/rc.local the following code (at the end of the file):
for dir in apparmor apt cups dist-upgrade fsck gdm installer samba unattended-upgrades ;
if [ ! -e /var/log/$dir ] ; then
- Limit FireFox cache writes
To do so, you need in your FireFox go to Edit->Preferences->Advanced then Tab network and set Cached Web Content to 0.
There are lots of information on the Internet about tuning your system to use the ssd drives, but most of them are simply going too far (level obsession;). I think that doing a few simple tweaks in your system, which will eliminate the main sources of heavy write-operations, is enough to be able to happily enjoy the long life of your SSD drive.