Joined
·
1,537 Posts
Having recently gone through the process of configuring an SSD for optimal use in Linux, I thought I'd post the steps I took for anyone in a similar situation
One of the main concerns with SSD's is that excessive writes may cause premature failure of the drive, so steps are taken to decrease the number of writes.
File System
The two most common file system types used with SSD's are Ext2 and Ext4. The difference between the two is journalling, Ext2 doesn't include journalling whereas Ext4, being the newest version, does.
What is journalling you may ask?
Journalling file systems keep track of the changes that are to be made to the hard disk in an area called the 'journal' before the changes are written to the disk. Error detection and recovery on a journalled file system is far greater than a file system without journalling; if an unexpected crash happens, the journal can be consulted to check for consistency.
Which File System Should I Use?
As we want to reduce the number of writes to the SSD, a file system without journalling would be the obvious choice, for example, Ext2. The only problem with Ext2, is that it lacks full TRIM support (TRIM discussed later in guide). Ext4 on the other hand, has full TRIM support, and has the option to turn the journal off.
Note: Without the journal, the hard drive will be more susceptible to errors after an unexpected freeze or shut down.
Disabling the Journal on Ext4:
To do this, you need to boot from a live CD/USB.
Open a terminal window and run:
Quote:
Enable TRIM
TRIM is a command of an OS that handles functions such as garbage collection to prevent performance degradation over time.
Ext2 supports TRIM, but can only be operated manually whereas Ext4 supports it fully.
Enabling TRIM:
For starters make sure you're SSD supports TRIM (usually found on the manufacturers website), and you're OS supports TRIM too. TRIM is supported in Linux kernel 2.6.33 and later.
To check your kernel:
Quote:
Quote:
Look for 'ext4' and after it there should either be 'defaults' or 'errors=remount...'. Before that, add the word 'discard' so it looks like:
Quote:
Important:
Not required if Linux Kernel is 2.6.33 or greater.
Ext2 file systems to not support online TRIM, in other words, it need to be mounted as read-only.
IF you're using an older kernel, the SSD will need to be TRIM'd manually, using software called 'hdparm'
To manually TRIM the SSD, start by downloading the latest hdparm from here.
After downloading, extract the tar.gz file.
Open a terminal window in the extracted folder and run:
Quote:
Quote:
Quote:
In the terminal window:
Quote:
If not all required packages are required, an error will appear outlining what packages are required, install them and repeat the above.
Swap File
The swap file is an area of the hard drive the OS will use when it runs low on memory. How much the swap file is used is based on the 'swappiness', a number between 0 and 100. The higher the number, the more aggressively the OS will use the swap file. As we want to reduce the number of writes to the SSD, minimal use of the swap file would be best.
To edit swappiness:
Quote:
At the bottom of the file, on a new line, add:
Quote:
Noatime Option
By default, Linux will update all files and directories with a last access time, we want to disable this using the 'noatime' option.
Open your /etc/fstab file again:
Quote:
Quote:
The disk scheduler handles how data is written to disk, the default disk scheduler will write files to disk based on their physical location, but since the write times on an SSD are not dependent on location, we want them to be written in the order they are received. We can do this using the 'noop' disk scheduler.
Enabling the 'noop' Disk Scheduler:
Quote:
I've still got a bit to add when I have a little more time to spare.

One of the main concerns with SSD's is that excessive writes may cause premature failure of the drive, so steps are taken to decrease the number of writes.
File System
The two most common file system types used with SSD's are Ext2 and Ext4. The difference between the two is journalling, Ext2 doesn't include journalling whereas Ext4, being the newest version, does.
What is journalling you may ask?
Journalling file systems keep track of the changes that are to be made to the hard disk in an area called the 'journal' before the changes are written to the disk. Error detection and recovery on a journalled file system is far greater than a file system without journalling; if an unexpected crash happens, the journal can be consulted to check for consistency.
Which File System Should I Use?
As we want to reduce the number of writes to the SSD, a file system without journalling would be the obvious choice, for example, Ext2. The only problem with Ext2, is that it lacks full TRIM support (TRIM discussed later in guide). Ext4 on the other hand, has full TRIM support, and has the option to turn the journal off.
Note: Without the journal, the hard drive will be more susceptible to errors after an unexpected freeze or shut down.
Disabling the Journal on Ext4:
To do this, you need to boot from a live CD/USB.
Open a terminal window and run:
Quote:
# = the number of the drive you want to remove the journal from, mine for example was 'sda5'.sudo tune2fs -O ^has_journal /dev/sda#
Enable TRIM
TRIM is a command of an OS that handles functions such as garbage collection to prevent performance degradation over time.
Ext2 supports TRIM, but can only be operated manually whereas Ext4 supports it fully.
Enabling TRIM:
For starters make sure you're SSD supports TRIM (usually found on the manufacturers website), and you're OS supports TRIM too. TRIM is supported in Linux kernel 2.6.33 and later.
To check your kernel:
Quote:
Open Your /etc/fstab Fileuname -a
Quote:
(Assuming gedit is your text editor)sudo gedit /etc/fstab
Look for 'ext4' and after it there should either be 'defaults' or 'errors=remount...'. Before that, add the word 'discard' so it looks like:
Quote:
Manual TRIMdiscard,errors=remount
Important:
Not required if Linux Kernel is 2.6.33 or greater.
Ext2 file systems to not support online TRIM, in other words, it need to be mounted as read-only.
IF you're using an older kernel, the SSD will need to be TRIM'd manually, using software called 'hdparm'
To manually TRIM the SSD, start by downloading the latest hdparm from here.
After downloading, extract the tar.gz file.
Open a terminal window in the extracted folder and run:
Quote:
Then:sudo make
Quote:
Navigate to:sudo make install
Quote:
Right click, and then 'open in terminal', alternatively navigate to the folder using the 'CD' command.your download location/hdparm-9.37/wiper
In the terminal window:
Quote:
'#' being the number of the hard drive you want to TRIM.sudo bash wiper.sh --commit /dev/sda#
If not all required packages are required, an error will appear outlining what packages are required, install them and repeat the above.
Swap File
The swap file is an area of the hard drive the OS will use when it runs low on memory. How much the swap file is used is based on the 'swappiness', a number between 0 and 100. The higher the number, the more aggressively the OS will use the swap file. As we want to reduce the number of writes to the SSD, minimal use of the swap file would be best.
To edit swappiness:
Quote:
Look for 'vm.swappiness', if its not there:sudo gedit /etc/sysctl.conf
At the bottom of the file, on a new line, add:
Quote:
Choose a low number, ideally less than 10, in my example I've chosen 1.vm.swappiness=1
Noatime Option
By default, Linux will update all files and directories with a last access time, we want to disable this using the 'noatime' option.
Open your /etc/fstab file again:
Quote:
And where 'discard' was added previously, add 'noatime' before it:sudo gedit /etc/fstab
Quote:
Disk Schedulernoatime,discard,errors=remount
The disk scheduler handles how data is written to disk, the default disk scheduler will write files to disk based on their physical location, but since the write times on an SSD are not dependent on location, we want them to be written in the order they are received. We can do this using the 'noop' disk scheduler.
Enabling the 'noop' Disk Scheduler:
Quote:
I hope this has been useful to anyone will Linux and an SSDsudo echo noop > /sys/block/sda/queue/scheduler
