Home Home > 2015 > 02 > 06 > SSD configuration for openSUSE
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

SSD configuration for openSUSE

February 6th, 2015 by

As you already know, there are mechanic disks and also SSD. There is the rumor that SSDs last for 5 years or up to 5 years. Read the openSUSE wiki page for more information about openSUSE and SSD.

Here I’ll describe what I did to my SSD.

RULE 1: Partitioning

The first step is creating the right partitions. First of all, create the root partition (about 15-20GB is enough). Then create the home partition (/home). Finally leave about 7% of the disk unallocated. This will help your disk during write process. The right filesystem is ext4.

If you have new computer, then you should have a partition /boot/efi. You don’t have to do any of the following configuration for that partition.

BE CAREFUL: Don’t create a swap partition. If you already have enough memory (4GB), you don’t need it. Swap memory is “destroying” your SSD. Finally, be careful of the file system, since openSUSE 13.2 uses BTRFS as default filesystem. Snapper will create snapshots, something that you don’t need.

RULE 2: fstab

Open fstab and make some changes there:

sudo nano /etc/fstab

Delete relatime (if any) and add noatime

Your fstab will look like

/dev/sdaX     /          ext4 noatime,acl,user_xattr 0 1
/dev/sdaY    /home ext4 noatime,acl,user_xattr 0 2

 

Now, move everything to RAM. You can do that by adding the following lines to fstab.

tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0

To restore the folder structure within /var/log at each reboot, you add some lines to /etc/rc.local.

sudo nano /etc/rc.d/boot.local

Add the following 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

RULE 3: Browsers

You can limit the write actions of Firefox as follows.
1. 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.

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

The write actions of Google Chrome and Chromium can be limited as follows.
1. Launch Chrome / Chromium.
2. 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.

RULE 4: SWAP

As described at RULE 1, you shouldn’t add a swap partition. If you did (or did by automatic installation), you should disable it.

First of all, check the status:

cat /proc/sys/vm/swappiness

If the result is 60, then you should reduce to 1.

sudo nano /etc/sysctl.conf

and at the end of the file, add the following lines

# Sharply reduce swap inclination
vm.swappiness=1

RULE 5: HIBERNATION

Hibernation causes a huge amount of write actions, which is very bad for an SSD. Make sure it’s disabled, by removing the package pm-utils.

sudo zypper rm pm-utils

RULE 6: TRIM

The TRIM technology is like defragment on windows. It makes the disk faster. You can use 3 ways of running it. Usually, the command is fstrim -v / but when run it, I failed. So that’s why I added sudo, just to be sure.

1. As alias at .bashrc and run when you want.

Create an alias for both ext4 mounted partitions.

$ sudo /usr/sbin/fstrim -v /
$ sudo /usr/sbin/fstrim -v /home

2. Add the commands to /etc/rc.d/boot.local and run on each boot.

Just open the /etc/rc.d/boot.local

sudo nano /etc/rc.d/boot.local

and add the following line

sudo /usr/sbin/fstrim -v / && sudo /usr/sbin/fstrim -v /home

3. If you run a server or something (your system is always on), then you have to use cron.

sudo nano /etc/cron.daily/trim

Then add the following lines

#!/bin/sh
sudo /usr/sbin/fstrim -v / && sudo /usr/sbin/fstrim -v /home

and finally make it executable

sudo chmod +x /etc/cron.daily/trim

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

RULE 7: I/O SCEDULER TO DEADLINE

By default, openSUSE still uses 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 to Deadline, which is good for both SSD’s and conventional platter hard disks.

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

Check your current scheduler as follows:

cat /sys/block/sda/queue/scheduler

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

The output will probably be:

noop deadline [cfq]

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

Now type:

sudo nano /etc/default/grub

Find the line: GRUB_CMDLINE_LINUX_DEFAULT=

This line may look like this (example):
GRUB_CMDLINE_LINUX_DEFAULT=” resume=/dev/sda1 splash=silent quiet showopts”

And add the option elevator=deadline.

Example:
GRUB_CMDLINE_LINUX_DEFAULT=” resume=/dev/sda1 splash=silent quiet showopts elevator=deadline”

Save the modified file and close it.

Now update Grub for this change. In the terminal:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Both comments and pings are currently closed.

4 Responses to “SSD configuration for openSUSE”

  1. ali

    and after all to care of ssd you can move it from your system
    or remove your os
    or turn down your ssytem forever
    and be sure your ssd never be die 😉
    disable hibernate not good…
    disable cahce not good…
    only make cache lower and slower…
    vm.swappiness=1 is good for example

  2. Frank

    Hello:

    I think that some applications need to take into account the changes that occur in their files.

    If it gets ‘noatime’ changes in the inode is not going to produce, but if we put realtime, change only if the file is changed, if it is not, It would behave like noatime ; i think that for applications that need to be on the basis of the dates and the access time of files, i think that realtime is a better option.

    Even i do not know many of the improvements that can bring btrfs in configurations of SSD drives; but I think that these are some, To be able to rid some of the changes that are made in EXT4; by now not know them, but my fstab configuration for an SSD in BTRFS, that used for tests with VirtualBox is this:

    UUID d8c57867-8bad-41DB-85CF-219b41Eddd22 /home/frank/VBox_ssd btrfs discard realtime ssd 0 0

    Thank you for your article .

    I look forward to reading more about this topic.

    Greetings

    PD. Sorry if my English is not correct.

  3. First keeping a small swap partition is still recommended for performance usage.
    relatime is still a good choice as explained in previous comment
    Removing swap partition kill automatically the hibernation possibility.
    Your log in tmpfs good be and idea, but if there’s a problem it will be hard to diagnose whatever.

    And you forget to add the most advisable idea : check and apply any mfg recommended firmware!
    Mfg have fixed numerous crash or prematurely dying ssd during the last few years.

    Before buying an ssd, try to discover (often hidden informations) the limit of write the model propose. You could be surpized 🙂 Some are good, other really bad. The last Samsung 850 1To for example wouldn’t survive 1.5 year at the pace I use my laptop… Crucial M550 or older Corsair GT3 doesn’t seems to suffer….

    My last advise is also the following, if you use encryption luks over your ssd, by default there’s no trim/discard available by default on openSUSE. Be it a good idea for security, cause empty blocks will never get aligned, I’m still not sure it is a good or wise default for ssd.

    In my case, every 1.5 years I totally secure erase the ssd, and restore my system on them afterwards.

  4. Barry Weaver

    Efstathios:

    Thank you for the great article. I would like to point out an alternative mechanism to schedule fstrim (#6). The util-linux package has a systemd timer in it for fstrim [1]. It is relatively new, so it may not be an option in all versions but it is available in openSUSE 13.2.

    All that is required for for the timer be enabled and active with systemctl is:
    $ systemctl enable fstrim.timer
    $ systemctl start fstrim.timer

    [1] https://github.com/karelzak/util-linux/blob/master/sys-utils/fstrim.timer