Ubuntu SSD Tweak

From richud.com
Jump to navigation Jump to search

Tweak fstab

Do I have TRIM support?

To find out if you have TRIM support (not enabled or disabled), do this, it should say TRIM supported.

$ sudo hdparm -I /dev/sda | grep TRIM 
	   *	Data Set Management TRIM supported (limit unknown)

Mount tmp in RAM via fstab

With sudo nano -w /etc/fstab, add line (nodiratime isnt needed as noatime susperceeds it)

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
  • Note, Add 'noatime' mount option to stop file access time stamping
  • Note, Add 'discard' mount option to SSD drive IF your drive supports TRIM (if not it is ignored anyway)
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /  ext4 defaults,discard,noatime 0 0

After rebooting you should see something like this from dmesg

$ dmesg | grep "discard"
[    2.943009] EXT4-fs (sda1): re-mounted. Opts: discard,errors=remount-ro

Note, even in Ubuntu 12.04 you need to set this fstab mount option (I have seen written that you dont, but this appears to be not the case)

If TRIM is working, then the following should be 0, (assuming / is mount point of the SSD, i.e. /dev/sda mounted on /)

  • Note, If just enabling and rebooting it probably wont be 0 the first time you do it.
$ sudo fstrim -v /
/: 0 bytes were trimmed

Keep retrying it every few minutes when computer is in use, it should always be 0.

Tweak filesystem to stop it writing stuff

From a Live CD to keep it clean

Removing /var/log assumes you don't need logging after a reboot, which for a desktop seems fairly sensible.

Empty entirely the /tmp folder, but dont delete it, if you do by mistake remember it needs everyone to have full access to it when created. (This will still let the system work if incorrect/missing tmpfs entry in fstab)

#Clear tmp
rm -rf /tmp/*
rm -rf /var/tmp
rm -rf /var/log
#Chrome cache etc uses this by default
rm -rf /home/xxxxx/.cache

Link stuff back to /tmp

ln -s /tmp /var/log
ln -s /tmp /var/tmp
ln -s /tmp /home/xxxxx/.cache

Tweak scheduler

udev way

Create (or edit)



# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop"
# set cfq scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="deadline"

Grub way

sudo nano -w /etc/default/grub, edit

old SSD with no trim


new SSD with trim and decent scheduler


Then run this to generate a new grub.cfg with elevator settings in.

sudo update-grub

As a one liner;

sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="elevator=noop"/g' /etc/default/grub && sudo update-grub