What steps should be taken before/during/after installation of Ubuntu on a Solid State Drive to optimize performance and ensure maximum durability of the drive?
I have successfully used several different techniques to improve the way Ubuntu uses the storage device, whether that be solid state or traditional drive.
For SSD's 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.
If 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. The reason this is generally a bad idea, is because every read will produce a write when updating the timestamps. This decreases the life of the SSD.
Edit your /etc/fstab configuration file (carefully - take a backup to be sure as breaking your fstab configuration can prevent you system from working):
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 (/home) - Note: if you have a /home partition, start with that just changing that partition if you are concerned about breaking something
You will need to reboot your machine before these changes take effect
3) Minimising writes from the OS and applications
Assuming that you are not running a mission critical product 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 so all logs get written to RAM memory rather than 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
For background to this approach, see prolonging the life of your flash drive on ubuntu-eee.com
Open /etc/fstab with an editor (assuming you have backed up the /etc/fstab file)
Add the following lines at the end of the fstab file and save:
You will need to reboot your machine before these changes take effect
Generally I wouldn't bother - the worries about SSD life are overblown. You can read this detailed article about why you really shouldn't worry. In short the circuitry inside modern SSDs manages wear-levelling for you, and they know how to do it far better than you.
In the article is a calculation of the life of an SSD that is receiving writes at a continuous rate of 80M/s. The life is 51 years. That is based on 2007 technology - SSD life will be longer now. And you almost certainly don't write to your SSD at 80M/s 24 hours a day.
However performance degradation over time can be a problem, and TRIM is the solution. There are two options
You have to enable automatic TRIM yourself . (Basically you add the
You can occasionally do it manually (or in a cron job) using fstrim. If you just have one partition then all you need to do is:
Note that fstrim is only available in 11.10 and newer. For older systems you will need the
If you're wondering, the problem that TRIM solves, as described by Wikipedia, is:
There are several points:
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 wich should be
I would recommend
To put tmp on a ramdisk can increase the life time of the ssd.
To use this put the following line in you fstab:
Generally if you want to dive deeper into this topic I would recommend this excellent wiki-article.
Fast tuning course for your SSD on Ubuntu:
Arch wiki mentions few preferable options for SSD file system - one of them is unstable, others are ext* ones. I assume ext4 is one of the best picks.
Few important things here are:
Consider switching from the default scheduler, which under most Linux distro's is cfq (completely fair queuing), to the noop or deadline scheduler for an SSD. Using the noop scheduler, for example, simply processes requests in the order they are received, without giving any consideration to where the data physically resides on the disk. This option is thought to be advantageous for SSDs since seek times are identical for all sectors on the SSD.
Add following to /etc/rc.local:
4) enable automatic TRIM
If your SSD supports it, you should also enable automatic TRIM (as described here)
TRIM allows an operating system to inform an SSD which blocks of data are no longer considered in use and can be wiped internally. Trimming enables the SSD to handle garbage collection overhead, which would otherwise significantly slow down future write operations to the involved blocks, in advance.1
In Ubuntu 14.04 a new feature has been added to the util-linux package that regularly trims SSDs automatically, but only Intel and Samsung SSDs have TRIM enabled by default, because some cheap SSDs can even brick themselves when running TRIM.2 The contents of
Ok "long story short":
This will create a ramdrive for your temp files, which will lower the ageing. Also add
I would not add this line to your fstab, var/tmp folder is meant to survive reboots, and that could cause issues for you.
When I configure new system I leave all the tmp folder commented out this way if anything happens I can check the logs and stuff. Then once I have the main system setup I will un-comment them, but I never add the above line, here is what I use:
And if I am having any issues with my system I comment those out to be able to check everything even after a reboot or forced reboot after a lockup.
Also you don't need nodiratime, noatime option takes care of both by itself.
As for TRIM, if your hw/sw support it, it's a must, I do not use discard in fstab. I create a daily cron, because my PC is always on, by doing this:
Then add this to file and save (If you dont have a seperate /home partition on ssd, or have other parts that are on ssd you should get the idea how to modify this:
Then make the file executable by:
I also edit my rc.local like so:
Add this above "exit 0" and below the last #:
You can copy and paste from here so there is no errors, to the layman it looks out of whack, it is not.
I have also read that leaving 10% of your ssd drive unformatted can help extend life, that remains to be seen. I have not read that much into this so I can't vouch if it makes sense to do so.
This is the best all around guide, he did not skim around Google for a day and then come up with a guide, you should check it out HERE
There are some good info How to tweak and optimize SSD for Ubuntu, Linux Mint from http://namhuy.net/1563/how-to-tweak-and-optimize-ssd-for-ubuntu-linux-mint.html you might be interested in
To install preload on Ubuntu, Linux Mint or debian based distributions
Turn off your swap
To change swappiness setting:
And add this line into sysctl.conf file.
UPS is required.In the
Find the configuration file daemon, usually
It is clear that
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.
Edit fstab file
Add discard to your ssd drives or partitions, after ext4
noatime and nodiratime are mount options in linux for linux file system. noatime disables atime updates on file system, and nodiratime will disables atime updates on directory system. By adding noatime and nodiratime will greatly reduce ssd load means performance gains.
Edit fstab file
Add noatime,nodiratime to your ssd drives or partitions, after ext4
I suggest to place only those things which are read at boot time on the SSD any maybe applications which require much time to load.Data and logs and other uncritical things I would locate on a normal HDD.Also you could setup your ubuntu to only load a big initramfs from SSD at boot time and not write back changes to ssd.This has the benefit, that changes to this partition are not persistent which is sth like a protection for your boot system.Therefor you would need much more RAM of course.
I would e.g. place the partitions /, /etc, /usr, /boot, /lib 32/64 on SSD while sth like
/opt, /bin, /sbin, /root, /home and even swap (increase RAM!!!) on HDD
For backups there are many ways, simplest of which is (r)sync plus cron job.