分享

Install and optimize an SSD for Ubuntu 14.04

 dzh1121 2015-02-08
These are the steps I took to install and optimize my new SSD on my Ubuntu 14.04 64 bit system. The / (root) and /home directories go to the SSD.  The rest go to the HDD, which is mounted in /media/Data/.

Use EXT4 file system

SSDs work better with the ext4 files system, than with the NTFS.


Enable TRIM

The TRIM command let an OS know which SSD blocks are not being used and can be cleared.

Back up the fstab file, in case something goes wrong:
# cp /etc/fstab ~/fstab.bk

Edit the fstab file:
#sudo gedit /etc/fstab

Add the option "discard" after ext4 for all the SSD partitions (except swap):
UUID=0ee549f0-1946-4136-8aa4-c5219a568981 /               ext4    discard,errors=remount-ro   0       1
# /home was on /dev/sda2 during installation.  SSD
UUID=8f23cbcd-9d4d-4233-bb62-443918549111 /home           ext4    discard,defaults        0       2

Adding noatime and nodiratime

noatime disables atime updates on file system while nodiratime disables atime updates on directory system. This reduces unnecessary writes to the SSD.

Edit the fstab file:
#sudo gedit /etc/fstab

Add noatime,nodiratime after ext4 for all the SSD partitions (except swap):

UUID=0ee549f0-1946-4136-8aa4-c5219a568981 /         ext4   discard,noatime,nodiratime,errors=remount-ro   0       1
# /home was on /dev/sda2 during installation.  SSD
UUID=8f23cbcd-9d4d-4233-bb62-443918549111 /home       ext4  discard,noatime,nodiratime,defaults        0       2

Make sure I have the option "defaults" for the HDD.  This way I do not need root rights to write/delete on it.
# /media/Data was on /dev/sdb1 during installation.  1TB HDD
UUID=7742c6ed-84fc-42f1-9d5d-3134051b49f9 /media/Data     ext4    defaults        0       2

TMPFS

I decided to use tmpfs (which practically creates a RAM disk) to store some temporary files.  Once the system is restarted, everything in tmpfs will be gone.   This however may cause a problem, if for example I want to edit a huge video file. 

These are some recommended settings to add at the end of /etc/fstab:
# temporary directories
tmpfs /tmp tmpfs defaults,noatime,mode=1777  0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0
# log directories 
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/lock tmpfs defaults,noatime,mode=0755 0 0
tmpfs   /dev/shm        tmpfs   defaults      0 0

Edit the fstab file:
#sudo gedit /etc/fstab

I decided to use only the following settings.  I placed them at the end of /etc/fstab:
# SSD optimization, send these temporary files to tmpfs
tmpfs /tmp tmpfs defaults,noatime,mode=1777  0 0

/var/tmp holds temporary files to be preserved between reboots, so I decided to exclude it from tmpfs.
About /var/spool and /var/lock, I decided not to risk it.  I had some problem with HPLIP printing.


So this is my final /etc/fstab file:
# / was on /dev/sda1 during installation.  SSD
UUID=0ee549f0-1946-4136-8aa4-c5219a568981 /               ext4    discard,noatime,nodiratime,errors=remount-ro   0       1
# /home was on /dev/sda2 during installation.  SSD
UUID=8f23cbcd-9d4d-4233-bb62-443918549111 /home           ext4    discard,noatime,nodiratime,defaults        0       2
# /media/Data was on /dev/sdb1 during installation.  1TB HDD
UUID=7742c6ed-84fc-42f1-9d5d-3134051b49f9 /media/Data     ext4    defaults        0       2
# swap was on /dev/sda3 during installation.  SSD
UUID=48821585-bd13-4994-8a5d-45dfa6aae589 none            swap    sw              0       0
# SSD optimization, send these temporary files to tmpfs
tmpfs /tmp tmpfs defaults,noatime,mode=1777  0 0

Disable hibernation


Hibernation will put a lot of writes to your SSD and is not desirable for SSD health.
#sudo gedit /usr/share/polkit-1/actions/org.freedesktop.upower.policy

Look for
<allow_active>yes</allow_active>
There are two instances, one for hibernation, and another one for suspend, so make sure you change the correct one.  Change it from “yes” to “no”:
<allow_active>no</allow_active>

Move the Downloads, Videos, Pictures and Music directories to the HDD

From terminal I run these commands to move the Downloads directory :
mv Downloads /media/Data/Downloads
ln -s /media/Data/Downloads Downloads

Now if I run:
ls -ld Downloads

It should return:
Downloads -> /media/Data/Downloads
I did the same for Videos, Pictures and Music directories.


Set a low value for swappiness

The default swappiness value is 60, while the recommended value for desktop with lots of RAM is 10 (accepted values are 0-100).  To reduce swap usage to the minimum, set it close to 1:
gksudo gedit /etc/sysctl.conf
Then edit or add command:
vm.swappiness = 3
If you want to check the swappiness value of the system run:
$ cat /proc/sys/vm/swappiness

I/O Scheduler

For SSDs, the "noop" or the "deadline" I/O schedulers are recommended over the traditional CFQ.  In Ubuntu 14.04 the default scheduler is the Deadline (in previous version the default was the CFQ).  Still there is a recommended setting for the deadline/SSD combination that needs to be added into the /etc/rc.local file:
echo 1 > /sys/block/sda/queue/iosched/fifo_batch


So just to be safe, I defined the deadline scheduler for my sda SSD drive:
sudo gedit /etc/rc.local

Then I put the following lines before the exit 0.
echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch

To check what is the active scheduler for a device (sdX) run this in a terminal:
cat /sys/block/sdX/queue/scheduler

In my system the result is:
$ cat /sys/block/sda/queue/scheduler
noop [deadline] cfq

Move browser cache on the HDD

Most tutorials recommend moving browser cache to RAM.  This makes the browser super fast, but has the drawback that after reboot the cache is cleared, so the browser becomes slow again.  I want to keep the cache, so I will move it to the HDD.

This is the procedure to move the Firefox cache to the HDD:
  • In the address bar type "about:config".  
  • Right-click anywhere and select New –> String.  
  • Add ‘browser.cache.disk.parent_directory’. 
  • Edit the variable and point it to a directory on a non-SSD drive.  I entered:  "/media/Data/system/firefox_cache".

BIOS/UEFI settings

Make sure the AHCI feature is activated for SATA (instead of IDE).

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多