Pages

07 March 2012

96. Optimising, trimming and making your solid state drive last longer on linux

There's an excellent and informative guide here:
http://apcmag.com/how-to-maximise-ssd-performance-with-linux.htm

Please read it. I've tried it on my SSD and it didn't crash my system. In fact, it even seems snappier, but that might be subjective.

While the guide above talks about making Solid State Drives (SSD) last longer and work faster, it equally applies to other solid state media such as USB sticks.

Here we'll apply that guide to a USB stick with debian we installed as shown in this guide: http://verahill.blogspot.com.au/2012/02/installing-debian-on-usb-stick-live-usb.html

--START HERE --
Mount your USB stick as you would any other -- the wonderful things about *NIX is that all configuration options are set in files which you can easily edit.

/etc/fstab
Before editing, it looks like this

proc            /proc           proc    defaults        0       0
UUID=8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca /               ext4    errors=remount-ro 0       1
UUID=e3305fbe-8e4e-4d0e-9975-0db692f87d32 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0
We'll edit to

  • enable TRIM by adding discard.
    From the manual: "discard/nodiscard - Controls  whether  ext4  should issue discard/TRIM commands to the underlying block device when blocks are freed.  This is useful for SSD devices and sparse/thinly-provisioned LUNs, but it is off by default until sufficient testing has been done."
  • noatime.
    From the man: "Do not update inode access times on this filesystem (e.g., for faster access on the news spool to speed up news servers)."
  • nodiratime
    Same as noatime, for directories
  • move some temporary /var files to the RAM instead of disk
  • the last line puts all log files (/var/log/) in RAM as well. If you do want logs to persist between boots, comment it out
  • 1777 = chmod +trwx, 0755= u+rwx g+rw o+rw
  • I've kept the swap since I might want to use my stick on underpowered machines, but you really probably shouldn't
  • A good source of information on mount options is here: http://www.tuxfiles.org/linuxhelp/fstab.html


proc            /proc           proc    defaults        0       0
UUID=8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca /               ext4 noatime,nodiratime,discard,errors=remount-ro 0       1
UUID=e3305fbe-8e4e-4d0e-9975-0db692f87d32 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatme,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0

/etc/default/grub 
To set a system-wide scheduler policy for disk I/O we can edit grub and define elevator as noop, deadline or anticipatory.

Change e.g.
GRUB_CMDLINE_LINUX_DEFAULT="text splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="text splash elevator=deadline"
If you want to know more about schedulers, you can look here: http://www.cyberciti.biz/faq/linux-change-io-scheduler-for-harddisk/


We need to do update grub, and that's a bit trickier, but still not too difficult.
My USB stick is mount at /media/8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/


sudo mount -o bind /dev 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/dev/
sudo mount -o bind /sys 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/sys/
sudo mount -o bind /proc 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/proc/
sudo chroot 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/
root@beryllium:/# update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-1-686-pae
Found initrd image: /boot/initrd.img-3.2.0-1-686-pae
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
grep: input file `/boot/grub/grub.cfg.new' is also the output
done

And exit the chroot jail (type exit)


/etc/rc.local
Add a line to the end
echo 0>/proc/sys/vm/swappiness
to prevent use of swap until the RAM is full.

You're now done.


For an SSD drive you can just boot into your system and make the changes as above, but without fiddling with mounting /dev, /sys, /proc and doing chroot.

No comments:

Post a Comment