-
Notifications
You must be signed in to change notification settings - Fork 19
SSD Configuration on Linux
Solid State Drives (SSDs) are becoming more affordable and are now a standard part of most desktop computers of worth. In order to better maintain your SSD and get the best performance out of it, more configuration needs to be done.
Please refer to the references section for a more detailed explanation of why such tweaking is needed and how it effects your system and SSD.
For the article, we will assume your SSD partition is $SSD_DRIVE
. If you with to copy and paste the code, just write the following line in your terminal:
export SSD_DRIVE=/dev/sda1
where /dec/sda1
is your SSD partition.
The ext4 file system takes complete advantage of SSDs, just make sure you turn off journaling. If you use a recent version of a disk utility such as GParted or a LiveCD from a newly release distro, you don't need to worry about sector alignment (first partition starts at sector 2048 and all partitions starts are divisible by 8).
Also, you may want to have your swap partition on a regular spinning disk not your SSD.
sudo tune2fs -O ^has_journal $SSD_DRIVE
sudo tune2fs -o discard $SSD_DRIVE
Before editing your /etc/fstab
file, you need to know the UUID of your $SSD_DRIVE
. Also, we would want to backup the fstab file just in case.
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) #Backup fstab
sudo blkid $SSD_DRIVE #Find UUID
To enable TRIM, we need to edit the fstab to include the discard
option and disable access time tracking by using the noatime
option (which also implies nodiratime
). Your SSD fstab configuration should look like the following line, but with a different UUID:
UUID=a6ed37e6-ee89-4621-bd35-a5e9466275ac / ext4 noatime,discard,errors=remount-ro 0 1
To reduce writing to the SSD, we will be using tmpfs
(i.e. RAM-disk) to store the system cache and temp directory. You can use the same for logs /var/log
, however, I like to keep my logs between reboots so I will use the regular disk for that. Add the following lines to the /etc/fstab
.
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
To maximize performance, you should change the I/O queue scheduler from the kernel's CFQ (Completely Fair Queuing) to deadline (preferred) or NOOP. Lets say your $SSD_DRIVE
is /dev/sdX1/ (where X is the letter of your device). To update the scheduler, you should add the following line to /etc/rc.local
above the exit 0
line (after replacing X with your device letter):
echo deadline > /sys/block/sdX/queue/scheduler