SSD: how to optimize your Solid State Drive for Linux Mint 17.3, Ubuntu 16.04 and Debian

来源:互联网 发布:vb.net 微信开发实例 编辑:程序博客网 时间:2024/05/08 04:25

原文地址: https://sites.google.com/site/easylinuxtipsproject/ssd

Below you'll find a complete how-to for optimizing your SSD for Ubuntu 16.04, Linux Mint 17.3 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 ison another page.

Contents

  1. 1Avoid exaggerated measures
    1. 1.1Alignment is not necessary anymore
  2. 2BIOS and UEFI: set it to AHCI
  3. 3Check for updated firmware
  4. 4Avoid quick wear: reduce write actions
  5. 5Optional: reserve some space for overprovisioning
  6. 6During installation: select EXT4
  7. 7After the installation: noatime
  8. 8Still relevant for Ubuntu 16.04 and Linux Mint 17.3: automatic TRIM by rc.local, by cron or by discard
    1. 8.1Preferred method: by rc.local
      1. 8.1.1Disable the superfluous weekly cron job for TRIM
    2. 8.2Only for computers that are always on: daily by cron
      1. 8.2.1Disable the superfluous weekly cron job for TRIM
    3. 8.3Not advised: by discard
  9. 9How to execute TRIM manually
  10. 10Limit swap wear
  11. 11Almost ready after reboot
  12. 12Limit the write actions of Firefox
  13. 13Limit the write actions of Chrome and Chromium
  14. 14Check whether the scheduler is set to deadline
  15. 15Do NOT enable hibernation
  16. 16Also for an SSD: prevent fragmentation, and DO NOT defrag
  17. 17Dual boot? Don't let Windows kill your SSD
  18. 18Enjoy your SSD carefree for years and years
  19. 19Want more tips?

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 practice". 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...

Alignment is not necessary anymore

1.1. A common misunderstanding is, that the partitions on the SSD should be properly aligned first. That used to be true years ago, but no longer.

In the current versions of Ubuntu and Linux Mint, and in Debian since Wheezy, all tools automatically align filesystems and partitions to the optimal 4096 byte page size. So there's no need to do anything for alignment on an SSD.

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):

https://sites.google.com/site/easylinuxtipsproject/ssd/SSD-BIOS-1.JPG?attredirects=0

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):

https://sites.google.com/site/easylinuxtipsproject/ssd/BIOS-SSD-3.JPG?attredirects=0

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 cancreate a bootable CD, much like Ubuntu and Linux Mint do.

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 spinning hard disk!

Optional: reserve some space 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 tonot 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. Modern SSD's usually have some built-in unallocated space for overprovisioning anyway, which isn't accessible to the user. 

But to be on the safe side, I still advise to reserve about seven percent for unallocated space. With a maximum of 10 GB, because more would be unnecessary in almost any case. Reason: commercial pressure might induce SSD manufacturers to be too stingy with built-in "useless" overprovisioning space....

Seven percent with a maximum of 10 GB, is not a big loss of storage capacity. And it's beneficial for wear reduction on the very long term. What's more, on the short term it can be useful when your partitions are very full, because then your SSD won't slow down so much.

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

https://sites.google.com/site/easylinuxtipsproject/ssd/Screenshot-SSD-overprovisioning-5.jpg?attredirects=0

I classify overprovisioning as optional, because it's not as important as the other measures that I advise and because it costs you storage space. Yet on my own SSD's I always apply this.

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 16.04 and Linux Mint 17.3: 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 don't. 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 16.04 and in Linux Mint 17.3 TRIM is enabled automatically, when you install Ubuntu 16.04 or Linux Mint 17.3 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 for every automatically mounted EXT4 partition.

Note: only for partitions that are mounted by default! Butnot 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 /
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 /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 16.04 and Linux Mint 17.3, 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://launchpad.net/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 16.04 and Linux Mint 17.3, 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.

(continued in the column on the right)


This website is being sponsored by Google Ads.

Are you using an ad blocker? Then you're also blocking my earnings from advertisements....

If you wish to support my website, you can configure your ad blocker to make an exception for this website.

Thanks in advance....


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.

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....

Note: on a few SSD models (specifically two models from Crucial), executing this command when there's high disk activity (I/O activity), might cause problems. So only apply it when there's not much activity going on. Preferably with all other applications closed.

The above terminal command is enough when you have only one Ubuntu or Mint 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 ofextreme RAM load, your Linux has to be able to "swap".

Linux's inclination to use the swap, is determined by a setting. The lower the setting number, the more system load is required before your Linux 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 tap the F12 key, in order to open the developers' console. Then tap the F1 key, in order to open the settings.

In the settings window you tick: Disable cache (while DevTools is open).

Unfortunately, this only works when the developers' console is open.... A workaround might be, to always open one extra tab in which you keep the developers' console opened. This should also have effect on the other, "normal" tabs.

Another possibility is, to launch Chrome from the terminal with the following command:

google-chrome-stable --disk-cache-size=1 --media-cache-size=1

For Chromium the command is:

chromium-browser --disk-cache-size=1 --media-cache-size=1

Note: a value of 0 has no effect! But 1 byte should be satisfactory as well....

Now proceed to the next item.

Check whether the scheduler is set to deadline

14. By default, Ubuntu and Linux Mint 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.

But because it's so important for the performance of your SSD, it's wise to check whether this setting is indeed as it should be.

You can check your current scheduler as follows: use copy/paste to transfer the following blue command line to the terminal:

cat /sys/block/sda/queue/scheduler

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

Press Enter.

The output should be:
noop [deadline] cfq

Which means: deadline is active, but noop and cfq are also supported. Is the outcome different? Then change it as follows:

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

b. Then 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"

c. Save the modified file and close it.

d. 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.

e. Reboot your computer.

f. Proceed to the next item.

Note: when you have only an SSD in your computer and no platter disk as well, some how-to's suggest that you may experience a slight performance benefit by choosingnoop for scheduler, instead of deadline. This is not true, however. Deadline is always the best choice.

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 preservinga 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, operating system 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...
0 0
原创粉丝点击