I recently purchased a new solid state drive (SSD) to replace my current hard drive (HDD). Since SSDs work so much differently than HDDs, it’s worth while to make some optimizations in Ubuntu for them. SSDs are much faster than HDDs, but have a limited number of writes before they wear out. This makes balancing performance with the life of your SSD also a big concern for how you tune your system.
I’ve written a post on this topic before for the older SSD in my netbook.
Partitioning and bind mounts
I partitioned my 60 GB SSD into a 10 GB / partition, and a 50 GB /home partition, both using the default ext4 filesystem. I kept my old HDD home partition mounted at /media/oldhome.
I wanted to put some of my large and infrequently accessed files, like virtual machines and videos, on the more spacious HDD. I also wanted to make accessing these files from my home directory seamless. One way to do this would be to symlink folders from the SSD to the HDD. However, I found that this wouldn’t be fully seamless for some applications that don’t follow symlinks.
Bind mounts are a better solution. They allow a directory in a filesystem to be mounted in additional locations, similarly to symlinks but fully transparent to applications. To test bind mounting my videos directory, I ran mount with the bind option, and specified the source directory (on the HDD), and the mount point (which must already exist):
mount --bind /media/oldhome/tom/Videos /home/tom/Videos
To make my bind mounts permanent, I added them to my /etc/fstab file in this format:
/media/oldhome/tom/Videos /home/tom/Videos none bind 0 0
If you need to add a path with a space in it, replace the space with \040 to escape it. If you make a mistake and one of the bind mounts fails, Ubuntu will allow you to skip it and continue booting. So far the bind mount approach seems to work perfectly.
Mount options for SSDs
Any recent SSD should have the TRIM command available, which prevents performance degredation by allowing the OS to notify the SSD of which blocks are unused. The ext4 filesystem uses TRIM when the discard option is set.
The noatime option reduces writes to the SSD by not writing access time updates whenever a file is read. This improves performance and increases the life of the SSD.
I set these two mount options though /etc/fstab for both my SSD partitions by adding discard and noatime to the list of options for / and /home like this:
UUID=193af662-d7a0-47fb-b3f7-141ae3d19227 / ext4 errors=remount-ro,noatime,discard 0 1
Disk head scheduler for SSDs
A disk scheduler optimizes the order of disk requests by considering the position of the hard drive’s read/write head. An SSD needs no such optimization, so it’s best to use the noop (no-operation) scheduler.
I switched to the noop scheduler for my SSD by adding the to following line to /etc/rc.local (replace sdb with your own SSD’s device node name):
echo noop > /sys/block/sdb/queue/scheduler
Swap and swappiness
I kept my swap partition on the old HDD. Swap on the SSD would be faster, but would also shorten the SSD’s life.
My system has plenty of memory, so I also reduced the swappiness value to 0 to tell Ubuntu to only swap when absolutely necessary. I did this by adding the line vm.swappiness=0 to /etc/sysctl.conf.
There are many more ways to tune Ubuntu for SSDs. A few things I haven’t done are: partition alignment (Ubuntu’s partitioner now seems to take care of this automatically), disabling journalling (I’d prefer reliablity over slightly reduced SSD life), and mounting /tmp or browser cache in memory (I’d prefer to save the memory). The Arch Linux Wiki has a comprehensive page on SSDs, and here’s another article that goes more in-depth in some of the things I mentioned here.