分享

Solid State Drive (SSD): optimize it for Ubuntu 14.04, Linux Mint 17.1 and Debian

 dzh1121 2015-02-08
this is the link


Below you'll find a complete how-to for optimizing your SSD for Ubuntu 14.04, Linux Mint 17.1 and Debian. So that you'll be able to enjoy your SSD for many years!

Note: this how-to is only for Ubuntu, Linux Mint and Debian; the how-to for openSUSE is on another page.


Avoid exaggerated measures

1. First a word of caution: don't exaggerate! There's a lot of exaggeration to be found on the web on this issue.

On the one hand you have people who don't take any special measures for SSD's at all, and on the other hand you see people who take all kinds of extreme and complicated precautions. Neither side is behaving sensibly.

This how-to is meant to be a "best practise". It'll show you how to achieve a very good result by applying just a few rather simple measures. With those, you'll be able to enjoy your SSD carefree, for years and years to come!

Taking into account the long warranty periods that the manufacturers are giving, probably for more than five years (10 years should be a reasonable expectation). Considerably longer than an ordinary platter hard disk, anyway...

BIOS and UEFI: set it to AHCI

2. A Solid State Disk, or rather Drive (SSD), is sometimes only recognized properly by the BIOS or UEFI, when in the BIOS/UEFI the feature AHCI has been activated for SATA (instead of IDE).

This feature may be hard to find in the BIOS/UEFI, because there's absolutely no standardization at all in menu structures for BIOS and UEFI (sigh....).

That's why I've made two screen shots of the BIOS of my computer, in which you can see this particular feature. Hopefully it'll help you to find it in your own BIOS/UEFI.... The motherboard of my computer is, by the way, an MSI H61MA-E35 (B3).

Note: doesn't the BIOS or UEFI of your computer offer the option to switch to AHCI? Then the BIOS/UEFI might possibly detect the SSD automatically and automatically choose the right BIOS settings for it.

First of all, in the BIOS of my computer I go to the tab Advanced, and there I expand the section Integrated Peripherals (click on the image below to enlarge it):


Then, under the header "SATA Configuration", I change IDE into AHCI Mode. Namely for SATA Mode.

Then, under the header "External SATA 6GB/s Configuration", I also change IDE into AHCI. Namely for External SATA 6gb/s Controller Mode.

See the image below (click on it to enlarge it):


Check for updated firmware

3. Check the website of the SSD manufacturer, whether there's an updated version available of the firmware for your SSD. If so, apply it.

For most SSD's it doesn't matter that you're running Linux, because many manufacturers offer such firmware updates by means of an iso file with which you can create a bootable CD, much like Ubuntu does.

In the first year after purchase, repeat this check every month or so.

Avoid quick wear: reduce write actions

4. A Solid State Drive is worn down relatively quickly by write actions. Especially the oldest generations of SSD's were vulnerable in that aspect, but to a lesser degree that's still the case for the newer generations.

Below you'll find some tips on keeping wear down to a reasonable minimum, by limiting the write actions. Within reason, because a modern SSD is already pretty wear-resistant by default.

When you apply my tips, a lifespan of more than 10 years should be a normal expectation for your SSD. Which is considerably longer than the average lifespan of an old-fashioned platter disk.

Note: these directions are only meant for a Solid State Drive (SSD), not for an ordinary conventional hard disk!

Reserve seven percent for overprovisioning

5. Over-provisioning (with or without a dash) is a technique that's being used to improve the performance and life span of an SSD. I won't explain it here, but it boils down to not formatting a part of the SSD, which then remains unallocated space (unused capacity).

General opinion used to be, that it's wise to reserve as much as 28 percent of the storage capacity of an SSD for such unallocated space. That's of course a huge slice out of the total storage capacity, which makes nobody happy....

However, in the newer generations of SSD's the technology and firmware have improved so much, that such huge losses of storage capacity aren't needed anymore. Not for normal use, anyway.

But to be on the safe side, I still advise to reserve about seven percent for unallocated space. For normal use, that's a reasonable minimum.

See the screenshot below, in which the seven percent unallocated space has been highlighted (click on the image to enlarge it):


During installation: select EXT4

6. The best file system (formatting) for an SSD, is the usual default EXT4. So you don't have to choose anything different in this respect.

The journaling that comes with EXT4 causes some write activity, but not very much. Plus journaling is a very important feature for system crash recovery, so you don't want to disable it.

Note: don't select the BTRFS file system! Because under certain circumstances, BTRFS causes a huge amount of write actions.

After the installation: noatime

7. With "noatime" in /etc/fstab, you disable the write action "access time stamp", that the operating system puts on a file whenever it's being read by the operating system. For an SSD "noatime" is much better.

You can do that as follows:

a. First make sure that you have installed the applications gksu and leafpad:

Launch a terminal window.
(You can launch a terminal window like this: *Click*)

Type (or copy/paste):
sudo apt-get install gksu leafpad

Press Enter and submit your password. Please note that the password will remain invisible, not even asterisks will show, which is normal.

b. Then type in the terminal (use copy/paste):
gksudo leafpad /etc/fstab

Press Enter.

c. Now add "noatime" to the line for your root partition and your other Linux partitions. Not to the line for the swap partition!

An adapted line may look like this:
UUID=f0ae2c59-83d2-42e7-81c4-2e870b6b255d   /   ext4 noatime,errors=remount-ro   0   1

Note: this is one line, not two! It might appear to be two lines (dependent on your screen size), because of the length of the line.

d. Save the modified text file and close it.

e. Now proceed to the next item.

Still relevant for Ubuntu 14.04 and Linux Mint 17.1: automatic TRIM by rc.local, by cron or by discard

8. The cleaning action TRIM is necessary for the good performance of your SSD in the long run. Otherwise it'll become very slow after some time.

All modern SSD's support TRIM, but older SSD's from before 2010 usually not. So for an older SSD you'll want to check this on the website of the manufacturer.

It's easiest to let the system perform an automatic TRIM. That can be done in several ways.

Note: in Ubuntu 14.04 and in Linux Mint 17.1 TRIM is enabled automatically, when you install Ubuntu 14.04 or Linux Mint 17.1 on an SSD. Namely by a "cron job".

But this doesn't happen automatically for all SSD's. Furthermore, in most cases "cron" is not the optimal method for TRIM anyway, so I advise you to read on.


Preferred method: by rc.local

8.1. You can add the TRIM command to /etc/rc.local. Then this command will be executed automatically on system boot. This hardly slows the boot process down.

This is the method that I prefer, because in most cases recoverable disk space then becomes fully usable again rather quickly.

You can do that as follows:

a. First make sure that you have installed the applications gksu and leafpad.

b. Then type in the terminal (use copy/paste):
gksudo leafpad /etc/rc.local

Press Enter.

c. Above the line exit 0 in that file, you now add the TRIM command
fstrim -v for every automatically mounted EXT4 partition.

Note: not for partitions that aren't mounted by default! And also not for the swap partition, as that's already being trimmed automatically by the system by default, during the boot process.

An example is most clarifying. When your Ubuntu or Linux Mint is on one single partition, so you have only the root partition / , then your rc.local should look like this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
fstrim -v /
exit 0


If you have a separate home partition (although that's not very useful), then you add the following line as well, above exit 0:
fstrim -v /home

Note: if you have a separate partition for /boot/efi, don't add a trim command line for that in rc.local. It's useless, as that partition is seldom being written to. And it may even cause malfunctions.

d. Save the modified file and close it.

e. Reboot your computer.

Disable the superfluous weekly cron job for TRIM

8.1.1. In Ubuntu 14.04 and Linux Mint 17.1, disable the now superfluous weekly cron job for TRIM:

Copy/paste the following command line into the terminal:
sudo mv -v /etc/cron.weekly/fstrim /fstrim

Press Enter.

With that command you've transferred the script file fstrim to the root directory, thus disabling it.

Now proceed to item 9 in the column on the right.

Only for computers that are always on: daily by cron

8.2. For computers that are always on (24 hours a day, seven days a week), a TRIM action that's being executed when booting, is of course not useful.

In such a case you're better off with a "timer", i.e. with cron. Trimming daily is better than weekly, because then you don't have to wait so long before recoverable disk space becomes fully usable again.

You can schedule a daily trimming as follows:

a. First make sure that you have installed the applications gksu and leafpad.

b. Then type in the terminal (use copy/paste):
gksudo leafpad /etc/cron.daily/trim

Press Enter.

c. Copy/paste the following blue text into that empty text file:

#!/bin/sh
# call fstrim-all to trim all mounted file systems which support it
set -e
#
# This only runs on Intel and Samsung SSDs by default, as some SSDs with
# faulty firmware may encounter data loss when running fstrim under high I/O
# load (e. g.  https:///bugs/1259829). You can append the
# --no-model-check option here to disable the vendor check and run fstrim on
# all SSD drives Like this (remove the hash):
#exec fstrim-all --no-model-check
exec fstrim-all


Save the text file.

d. Now copy/paste the following command into the terminal, in order to make the file executable:
sudo chmod +x /etc/cron.daily/trim

Press Enter. Type your password when prompted; this remains entirely invisible, not even dots will show, this is normal. Press Enter again.

e. Reboot your computer.

Ubuntu or Linux Mint will now perform the daily cron job automatically, at 06:25, or (when the computer isn't on at that time), automatically at a later time on the same day.

Disable the superfluous weekly cron job for TRIM

8.2.1. In Ubuntu 14.04 and Linux Mint 17.1, disable the now superfluous weekly cron job for TRIM:

Copy/paste the following command line into the terminal:
sudo mv -v /etc/cron.weekly/fstrim /fstrim

Press Enter.

With that command you've transferred the script file fstrim to the root directory, thus disabling it.

Now proceed to item 9 in the column on the right.

Not advised: by discard

8.3. Another widely used method for automatic TRIM is to add the option discard to /etc/fstab, for the line for your root partition and for possible other Linux partitions that are being mentioned there.

Note:
do not add it to the line for the swap partition, as that's already being trimmed automatically by the system by default, during the boot process!

The disadvantage of this method is, that it may cause the system to slow down. Because it forces the system to apply TRIM instantly on every file deletion. That's why this method is not my favourite.

Note: as already mentioned, old SSD's made before 2010 usually don't support TRIM. In that case it's of course not useful to apply the option discard in fstab.

If you want to do it anyway, then this is how:

a. First make sure that you have installed the applications gksu and leafpad.

b. Then type in the terminal (use copy/paste):
gksudo leafpad /etc/fstab

Press Enter.

c. Now add "discard" to the line for your root partition and your other Linux partitions that are being mentioned in this file. Not to the line for the swap partition!

An adapted line may look like this:
UUID=f0ae2c59-83d2-42e7-81c4-2e870b6b255d   /   ext4 discard,errors=remount-ro   0   1

Note: if you have a separate partition for /boot/efi, don't add a trim command for that partition in fstab. It's useless, as that partition is seldom being written to. And it may even cause malfunctions.

d. Save the modified text file and close it.

e. Reboot your computer.

f. Now proceed to item 9 in the column on the right.


How to execute TRIM manually

9. You can execute TRIM manually as well, namely as follows:

Launch a terminal window.
(You can launch a terminal window like this: *Click*)

Type (use copy/paste):
sudo fstrim -v /

Press Enter. Type your password when prompted; this remains entirely invisible, not even dots will show, this is normal. Press Enter again.

This operation may last for minutes; it then looks as if the terminal has frozen. That's not true, however; simply wait patiently....

The above terminal command is enough when you have only one Ubuntu partition and a swap partition (because for the swap it's unnecessary; the system takes care of that automatically).

When you have more mounted EXT4 partitions, you'll have to adapt the command line accordingly. For example, if you have a separate home partition (although that's not very useful), then the command is:
fstrim -v /home

Now proceed to the next item.

Limit swap wear

10. With the action described below, you limit the use of the swap partition (the virtual memory on the SSD). Without disabling it entirely, because that would go too far: in case of extreme RAM load, Ubuntu has to be able to "swap".

Ubuntu's inclination to use the swap, is determined by a setting. The lower the setting number, the more system load is required before Ubuntu starts using the swap.

On a scale of 0-100, the default setting is 60. Which is much too high for normal desktop use, and only fit for servers. For SSD's, it's just crazy.

A detailed explanation can be found here (link dead? Then download this pdf file with the same content).

Now the how-to:

a. First make sure that you have installed the applications gksu and leafpad.

b. Now check your current swappiness setting. Type in the terminal (use copy/paste):
cat /proc/sys/vm/swappiness

Press Enter.

The result will probably be 60.

c. Now type in the terminal (use copy/paste):
gksudo leafpad /etc/sysctl.conf

Press Enter.

d. Add the following blue lines, at the very end of the existing text in that file (use copy/paste to avoid errors):
# Sharply reduce swap inclination
vm.swappiness=1

e. Save the file and close it.

f. Now proceed to the next item.

Almost ready after reboot

11. Reboot your computer.

Your SSD is almost ready now, but not quite. So after the reboot, proceed to the next item.

Limit the write actions of Firefox

12. You can limit the write actions of Firefox as follows.

a. Set the cache to 0:
Firefox menu button (with the three dashes on it) - Preferences - Advanced
Tab Network
section "Cached Web Content": tick Override automatic cache management and set the cache to 0 MB.

b. If you have installed Oracle Java, limit the write actions of the Java plugin:
launch the Java Control Panel - Tab General:
Temporary Internet Files - Settings...
Remove the tick for: Keep temporary files on my computer.

Limit the write actions of Chrome and Chromium

13. The write actions of Google Chrome and Chromium can be limited as follows.

- Launch Chrome / Chromium.

- Now press the F12 key, in order to open the developers' console. In that window you click on the gear wheel in the bottom right, in order to open the settings. See the screenshot below (click on it to enlarge it):


In the settings window you tick: Disable cache.

Press F12 again to close the developers' console. You're done with Chrome / Chromium.

Note: user preference, so repeat in each user account.

Now proceed to the next item.

Ubuntu 12.04 and Linux Mint 13: change the scheduler to deadline

14. By default, Ubuntu 14.04 and Linux Mint 17.1 use the I/O scheduler Deadline, which is good for both SSD's and conventional platter hard disks. So for the scheduler, you don't have to change anything in Ubuntu 14.04 or Linux Mint 17.1.

But Ubuntu 12.04 and Linux Mint 13 by default still use the "old" I/O scheduler CFQ, which is only fine for conventional hard disks but not for SSD's, which are being slowed down. So it's wise when you have an SSD in your machine, to change the scheduler in Ubuntu 12.04 or Linux Mint 13 to Deadline.

You can realize this by changing the boot parameters of Grub. You can do that as follows.

a. First make sure that you have installed the applications gksu and leafpad.

b. Then check your current scheduler as follows. Use copy/paste to transfer the following command line to the terminal:
cat /sys/block/sda/queue/scheduler

(if your drive isn't sda, change the line accordingly)

Press Enter.

In Ubuntu 12.04, the output will probably be:
noop deadline [cfq]

Which means: cfq is active, but noop and deadline are also supported.

c. Now type (use copy/paste):
gksudo leafpad /etc/default/grub

Press Enter.

Find this line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

And replace it by this line:
GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline quiet splash"

d. Save the modified file and close it.

e. Now update Grub for this change. In the terminal (use copy/paste):
sudo update-grub

Press Enter. Type your password when prompted; this remains entirely invisible, not even dots will show, this is normal. Press Enter again.

f. Reboot your computer.

g. Proceed to the next item.

Note: when you have only an SSD in your computer and no platter disk as well, then you may experience a slight performance benefit by choosing noop for scheduler, instead of deadline.

Do NOT enable hibernation

15. Hibernation causes a huge amount of write actions, which is very bad for an SSD. Make sure it's disabled! (item 8, left column)

This is especially relevant for Linux Mint, because in Linux Mint hibernation is unfortunately enabled by default...

Also for an SSD: prevent fragmentation, and DO NOT defrag

16. For an SSD, fragmentation of the file system is a smaller problem than for ordinary rotating hard disks. But it's nevertheless still a problem, so it's useful to prevent fragmentation as much as possible on an SSD, too. You can achieve that by preserving a minimum of 20 % free space on each partition (item 4, left column).

Prevention is all the more important, as defragmenting is out of the question anyway: your SSD would wear rapidly, because of the many write actions it causes.

The reason that fragmentation is also a problem for an SSD, is this:

The mechanical seek time of an SSD is always 0, regardless of the fragmentation. That's a big difference with rotating hard disks, on which the seek time increases as fragmentation grows. This is a significant improvement.

But mechanical seek time only makes up a part of total access time, or I/O time, of any single input/output request made to the disk.

I/O time is the time a computer system takes to complete a request cycle. All the way from application, OS and driver down to disk hardware, memory cells, and then back again.

Zero mechanical seek time certainly does not mean zero I/O time. No matter how fast an SSD is, its I/O time can never be zero. File system fragmentation increases I/O time in an SSD, even when the mechanical seek time is zero.

To put it another way: the performance degradation as a result of fragmentation is not caused by the storage device alone (whether there's a mechanical moving part or not), but it's also a problem concerning the system as a whole.

The task for the system becomes heavier, when there are more files to be chopped up and more pieces of files to be glued together. The heavier the task, the longer the processing time.

A good and elaborate explanation of this fact can be found here. Website down? Here's a pdf file.

Dual boot? Don't let Windows kill your SSD

17. Do you have a dual boot with Windows? Then don't let Windows kill your SSD by defragmenting it.

Defragmentation will kill your SSD in a very short time, because of the multitude of write actions that it causes.

Within Linux you don't have this problem, because Linux filesystems hardly fragment in the first place and so don't need to be defragmented anyway.

Enjoy your SSD carefree for years and years

18. Now you'll be able to enjoy your SSD carefree!

As already said in the start of this how-to: taking into account the long warranty periods that the manufacturers are giving, your SSD will probably last for more than five years (10 years should be a reasonable expectation).

Considerably longer than an ordinary platter hard disk generally lasts, anyway...

Optional (advanced users): temporary files and logs

19. This is an advanced system hack, and much less important than the other tweaks. So you can safely skip it, if you don't feel up to it.

You can further reduce the number of write actions to the SSD, by moving the temporary files and the log files of the system to a temporary virtual file system in the RAM memory. That virtual file system will be destroyed when you reboot.

For the temporary files, there are no significant disadvantages to that, except that your RAM memory size must be large enough (preferably at least 4 GB).

Also your system log files won't be there permanently. There is a small risk that an application will fail mysteriously, because it has no access to previously created log files. In practice this risk is very small. In three years of intensive use of computers with an SSD, it never happened to me.

a. First make sure that you have installed the applications gksu and leafpad.

b. Then type in the terminal (use copy/paste):
gksudo leafpad /etc/fstab

Press Enter.

c. Add the following blue lines, at the very end of the existing text in that file (use copy/paste to avoid errors):

#
# Modification for SSD
tmpfs      /var/log        tmpfs      defaults,noatime        0    0
tmpfs      /tmp          tmpfs      defaults,noatime,mode=1777    0    0


d. Save the file and close it.

e. To restore the folder structure within /var/log at each reboot, you add some lines to /etc/rc.local, just above the "exit 0" line.

Type (use copy/paste):
gksudo leafpad /etc/rc.local

Press Enter.

f. Add the following blue lines, just above the line "exit 0" in that file (use copy/paste to avoid errors):

#
# Modification for SSD
for dir in apparmor apt cups dist-upgrade fsck gdm installer samba unattended-upgrades ;
do

           if [ ! -e /var/log/$dir ] ; then
                   mkdir /var/log/$dir
           fi
done

g. Close the file and save it.

Note: your system not only has the folder /tmp, but also the folder /var/tmp. Don't put this last folder in the RAM memory, because /var/tmp is meant for temporary files that have to be available after reboot. I issue this warning because some other manuals for SSD's, wrongly advise to include /var/tmp in the RAM as well....

h. Reboot your computer.

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

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多