###dm-cache
export SSD_DRIVE=/dev/sdb2
export SSD_DEVICE=sdb
Place SWAP on another disk
/dev/sdb1 - /boot, 512MB
/dev/sdb2 - /, up to emaining capacity
##Step 1: Disable Journaling on ext4
#for i in `ls /dev/$SSD_DEVICE* |sed -e 's/.*\([1-9]\)$/\1/'|grep "[[:digit:]]"` ;do
#I NEED ONLY THE /DEV/SDB1 AT THIS TIME, BECAUSE OF LUKS
for i in 1;do
sudo mkfs.ext4 /dev/$SSD_DEVICE$i;
sudo tune2fs -O "^has_journal" /dev/$SSD_DEVICE$i;
sudo tune2fs -o discard /dev/$SSD_DEVICE$i;
read X
done
Optionally if LUKS is used:
sudo cryptsetup luksFormat -c aes-xts-plain64 -s 512 /dev/sdb2
sudo cryptsetup --allow-discards luksOpen /dev/sdb2 180_crypt
sudo mkfs.ext4 /dev/mapper/180_crypt
sudo tune2fs -O "^has_journal" /dev/mapper/180_crypt
sudo tune2fs -o discard /dev/mapper/180_crypt
Update properly /etc/crypttab and /etc/fstab::
/etc/fstab: UUID=1a103652-7056-4948-81f5-83f44b6966f8 /mnt/2nd_hdd ext4 noatime,discard,defaults 0 0
/etc/crypttab: 180_crypt UUID=f909bf0f-8905-492e-957c-858e9095fe0e none luks,discard
##Step 2: Enable TRIM and Disable Excessive File Metadata
sudo hdparm -I /dev/$SSD_DEVICE | grep "TRIM supported"
Add: "noatime,discard" to mount options::
Bkp & find uuid:: sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) #Backup fstab sudo blkid $SSD_DRIVE #Find UUID
Trim from cronjob::
#!/bin/sh
LOG=/var/log/trim.log
for mount in / /boot /home; do # ALL SSD PARTITIONS
echo "*** $(date -R), $mount ***" > ${LOG}
fstrim -v $mount > ${LOG}
done
sudo chmod +x /etc/cron.daily/trim
##Step 3: The Temp Directory and Logs
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
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
##Step 4: Scheduler
echo deadline > /sys/block/SSD_DEVICE/queue/scheduler
or
#vi /etc/udev/rules.d/60-schedulers.rules
# Handle the scheduler choice according to the type of disk detected
# system default : set cfq scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1",
ATTR{queue/scheduler}="cfq"
# SSD specific : set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0",
ATTR{queue/scheduler}="deadline"
##Step 5: Tune Swapping Behaviour
By default Ubuntu creates a swap partition according to your memory size.
Note that most modern desktops with more than 2 Gb of memory will very rarely use swap. The notable exception is systems which make use of the hibernate feature.
The following is recommended tweak for SSDs using a swap partition that will reduce the "swappiness" of the system thus avoiding writes to swap.
The value we will setup is the percentage of free memory before the system will start to use swap. We will set it to 0 so that system fills up full memory before swapping.
sudo sh -c "echo 0 > /proc/sys/vm/swappiness"
To make it persistent across reboot, we need to modify /etc/sysctl.conf to add that key :
sudo gedit /etc/sysctl.conf
/etc/sysctl.conf
...
vm.swappiness=0
##Step 6: Tune Firefox
The anti-phishing features of Firefox generates a big amount of data and may cause it to become slow to start or exit, and might also affect the browsing speed since Firefox apparently contacts google for every http request.
You can disable this feature by turning off the following options under Edit / Preferences / Security :
Block reported attack sites
Block reported web forgeries
It can also be done under about:config page by setting these booleans to false :
Close firefox and remove existing entries:
# rm -i ~/.mozilla/firefox/*.default/urlclassifier*
##Step 7: Place Browser Cache into RAM
sudo add-apt-repository ppa:graysky/utils
sudo apt-get update
sudo apt-get install profile-sync-daemon
USERS="yourlogin"
profile-sync-daemon parse
profile-sync-daemon parse |grep firefox
##Step 8: Encrypted disks (Option)
# vi /etc/default/grub
...
#GRUB_CMDLINE_LINUX="allow-discards root_trim=yes"
...
sudo update-grub
# vi /etc/crypttab
#Add discard option: var UUID=01234567-89ab-cdef-0123-456789abcdef none luks,discard
On most setups you will have to rebuild your initramfs with update-initramfs -u (Debian and derivatives) or dracut -f (Redhat and derivatives) and reboot the machine after touching the configuration options of LVM or dm-crypt.
sudo update-initramfs -u -k all
After the rebbot check, whether discard is enabled::
##Step 9: Enabling TRIM support on LVM
We have to enable the option issue_discards in the LVM configuration.
# [...]
devices {
# [...]
issue_discards = 1
# [...]
}
# [...]
##Step X: If you get some System Freeze (Option)
In case your system is showing some type of freeze, it may come from the fact that your SSD disk is not compatible with Linux NCQ (SATA Native Command Queueing), which is enabled by default.
This should not be the case with modern SSD, but it happens with some old generation or no-name ones.
To disable NCQ,you need to add the kernel parameter libata.force=noncq.
...
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash libata.force=noncq"
...
sudo reboot