Categories
Linux

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.