So you’ve bought an SSD to give your everyday computing device a performance boost? Well done.
The good news is, if you’re running Linux, there’s a handful of things you can do to make the most of your new super-powered block storage device. My results below speak for themselves. The bad news is, if you’re just a gadget consumer who has to have the latest and greatest, then simply buying it, fitting it and reinstalling the OS / cloning your previous drive is not going to cut it. It’s more common sense than out-and-out rocket science, but whatever your OS, you can use my guide to give you ideas on what you can do to improve both performance and possibly the longevity of your device. Being relatively new to the consumer market, the longevity of solid state block storage devices is yet to be seen. At least you can do your bit to reduce the number of writes going to the device and (one would think) extend its life.
I chose to buy two relatively small capacity Intel SSD’s, connected each one to its own SATA controller on the system board and mount / on one and /home on the other. I don’t see the point in buying large capacity SSD’s when it’s the performance you’re after rather than huge capacity to store your documents, photos, mp3, movie and software collections on – Thats what relatively cheap 2TB USB HDD’s and Cloud Storage providers like DropBox and Ubuntu One are for. Oh and buy two of those two external HDD’s too because nobody wants to see 2TB of their data go irretrievably down the pan.
Incidentally, if you do lose data there is a nice previous blog entry on data forensics that will help you get it back. Search for forensics at the top or follow this link for that…
Anyway, here’s the comparison of HDD performance to whet your appetite.
single hard disk in Lenovo IdeaCentre Q180
New dual SSD’s in HP dc7900 SFF PC
Tuning your SSD powered system…
Make sure the partitions are aligned. This means that when a block is written to the filesystem, there are far fewer boundaries crossed on the ssd with each block written.
Much is written on the web about how to achieve this, I found the easiest way was to create a small ext2 /boot partition on the front of one drive, swap on the front of the other, and create my big / and /home partitions at the end of the disks (I have two remember) when using the manual partitioning tool gparted during installation. By doing this, when i divided my starting sector number (returned by fdisk -l) by 512, i found the number was perfectly divisable – which is indicative of properly aligned partitions. Job done then.
For each ssd in your computer, prepend noatime and discard to the options, leaving errors=remount-ro or defaults on the end.
/dev/sda / ext4 noatime,discard,errors=remount-ro 0 1
Change the scheduler from noop to deadline.
Add the following line for each SSD in your system:
echo deadline >/sys/block/sda/queue/scheduler
Make it do this each time you reboot
As root, vi /etc/rc.local and add these above the exit 0 line at the end of the file
echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch
GRUB Boot loader
vi /etc/default/grub and change the following line…
GRUB_CMDLINE_LINUX_DEFAULT=”elevator=deadline quiet splash”
sudo update-grub
Reduce how aggressive swap is on the system. A linux system with 2GB or more RAM will hardly ever swap.
echo 0 > /proc/sys/vm/swappiness
sudo vi /etc/sysctl.conf
change vm.swappiness=1
vm.vfs_cache_pressure=50
Move tmp areas to memory instead of ssd. You’ll lose the contents of these temporary filesystems between boots, but on a desktop that may not be important.
In your /etc/fstab, add the following:
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=0755 0 0
Move firefox cache (you’ll loose this between boots)
in firefox, type about:config and right click and create a new variable
browser.cache.disk.parent_directory
set it to /tmp
Boot from a live usb stick so the disks aren’t mounted, and as root, deactivate the journals on your ext4 partitions of your internal ssd’s e.g.
sudo tune2fs -O ^has_journal /dev/sda1
Add TRIM command to /etc/rc.local for each SSD i.e.
Above the line exit 0, add the following
fstrim -v /
fstrim -v /home (only if your /home is mounted on a second SSD)
For computers that are always on, add trim command to /etc/cron.daily/trim
#!/bin/sh
fstrim -v / && fstrim -v /home
chmod +x /etc/cron.daily/trim
BIOS Settings
Set SATA mode to AHCI. It will probably be set to IDE. You’ll need to hunt for this setting is it varies between BIOS types.
SSD Firmware
Use lshw to identify your SSD and download the latest firmware from the manufacturer. For Intel SSDs, go here
That’s it. I’ll add other tips to this list as and when I think of them or see them on the net. You could reboot using a live usb and delete the residual files left behind in the tmp directories that you’ll be mounting in RAM from here on, but that’s up to you. If you do, DO NOT remove the directories themselves or the system won’t boot. If you do remove them, then fix it by booting using a live usb stick, mount the / partition into say, /ssd and mkdir the directories you deleted in /ssd/var/tmp and /ssd/tmp. Be aware though that /tmp and /var/tmp have special permissions set on them. chmod 777, followed by chmod +t to set the sticky bit -drwxrwxrwt (sticky bit set – with execution) on them.