Tombuntu

Setting up Ubuntu on an SSD

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 degradation 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.

Even more

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 reliability 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.

Archived Comments

SamD

The ‘mount –bind’ trick is a new and valuable item for me. Thanks much for a good article.

goodchild

Thanks!

Mattia

Thank you for the useful tips :P

Jeff C

If you have a program that makes use of access times for functionality (like mutt) you can set the filesystem to mount relatime. This will update the access time only if the last access time is less recent than the modified time; kind of a compromise between functionality and performance.

Hendy Irawan

The default mount option ‘relatime’ has many of the benefits of ‘noatime’ without the downsides.

I would suggest against using the ‘noatime’ option.

Adding ‘discard’ is good, even on non-SSDs.
BTW the ‘discard’ option is also available for the swap partition, which I recommend also enabling.

jza

Actually “noatime” should have almost no impact. The written data is extremely small and does not have a perceivable change in system performance or the lifetime of the disk.

Just imagine how much Windows writes and reads all the time, and these disks are designed to tolerate that.

//O.F.

“Swap on the SSD would be faster, but would also shorten the SSD’s life.”

You have 2.000.000 hours of SSD life with a OCZ Agility 3. I don’t think you can noticable shorten this.

Thank you for this helpful tutorial.

//O.F.

DC

As well, the *only* partitions on an SSD must be Linux filesystems that support TRIM (and Swap, which is TRIM enabled by default).

Putting a non-TRIM filesystem like NTFS or FAT will permanently eat SSD free blocks whenever a write is done and will never, ever release deleted file blocks for reuse (which is what TRIM does).

Greg

I’m running Ubuntu Server 10.04 on a Crucial 128 GB mSATA m4 SSD. I’m getting “busy” errors from mount when the system shuts down. Both / and /tmp busy.

Here’s /etc/fstab:

proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda5 during installation
UUID=1d2c4b59-f015-4dfb-8c98-4d06001f063b / ext4 errors=remount-ro,relatime,discard 0 1
# /boot was on /dev/sda1 during installation
UUID=5e150db1-d025-4300-b94f-3dfe1191eab6 /boot ext4 defaults 0 2
# /home was on /dev/sda7 during installation
UUID=1428124f-57a0-455f-837c-b7f5c16227f5 /home ext4 defaults,relatime,discard 0 2
# swap was on /dev/sda6 during installation
UUID=8c3afc3f-6227-4954-9f1b-dd55c6f93c6f none swap sw 0 0
# SSD so avoid temp
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

Can someone tell me how to fix this ?

Thank you.

Alex

Thanks a lot for these tips!

Do I need to use the noatime,discard options for my SWAP partition?

anon

Pretty much every ssd manufacture inputs wear-leveling randomization on thir SSD controllers. This extends the life of the ssd distributing the writes among the electric transistors evenly so to prevent one transistor from being used more than another.

Oscar Frank

Enable TRIM

TRIM (Trim command let an OS know which SSD blocks are not being used and can be cleared)

Back up fstab first in case something wrong happen.
# cp /etc/fstab ~/fstab.bk

Edit fstab file
# nano /etc/fstab

Add discard to your ssd drives or partitions, after ext4
UUID=bef10b86-494d-41c6-aa46-af72cfba90fd / ext4 discard,errors=remount-ro 0 1

http://namhuy.net/1563/how-to-tweak-and-optimize-ssd-for-ubuntu-linux-mint.html

Respond via email