SSD: how to optimize your Solid State Drive for Linux Mint and Ubuntu


Back to the home page


Below you'll find a complete how-to for optimizing your SSD for Linux Mint 21.x and for Ubuntu 22.04.x. So that you'll be able to enjoy your SSD for many years!

Contents of this page:

General advice: avoid exaggeration

1. First a word of caution: don't exaggerate! There's a lot of exaggeration to be found on the web on this issue; you see people who take all kinds of extreme and complicated precautions. That's not very sensible.

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, a minimum of 10 years should be a reasonable expectation. Considerably longer than an old-fashioned spinning platter hard disk, anyway...

Below I'll start by mentioning the things I recommend to do. The things that I warn against, are described after that.

BIOS and UEFI: make sure it's set to AHCI

2. A Solid State Disk, or rather Drive (SSD), is usually only recognized properly by the BIOS or UEFI, when in the BIOS/UEFI the feature AHCI has been activated for SATA (instead of IDE). On modern computers AHCI is the default, so that's fine. But on old machines the default might be 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 an older 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 that older 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? In relatively modern computers that's probably no problem: the BIOS/UEFI will then usually detect the SSD automatically, and automatically select 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 DVD, much like you can do with an iso file of Linux Mint or Ubuntu.

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 by write actions. Especially the oldest generations of SSD's were vulnerable in that aspect, but to a (much) lesser degree that's still the case for the newer SSD 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 spinning platter disk.

Note: These directions are only meant for a Solid State Drive (SSD), not for an old-fashioned conventional spinning hard disk!

During installation: select EXT4

5. 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! Mainly because it's not as mature as EXT4 yet, but also because it might (under certain circumstances) cause more write actions than EXT4 does.

Set the automatic TRIM job to daily

6. The cleaning action TRIM is recommended for the good performance of your SSD in the long run. Otherwise it might become slow after some time.

That's even true for new SSD's: although new SSD's nowadays usually have some form of garbage collection integrated into their firmware, it's always better to execute a regular TRIM as well.

Note: Very old SSD's from before 2010 usually don't support TRIM.

In Linux Mint and Ubuntu automatic TRIM is enabled by default, when you install them on an SSD. Namely by a weekly "job". But in many (most?) cases, once a week isn't frequent enough: waiting an entire week before recoverable disk space becomes usable again, is simply too long.

You can switch your system to automatic daily trimming as follows:

a. Copy/paste the following command line into the terminal, in order to create a new folder:

sudo mkdir -v /etc/systemd/system/fstrim.timer.d

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

b. Copy/paste the following command line into the terminal, in order to create a new file in that new folder:

sudo touch /etc/systemd/system/fstrim.timer.d/override.conf

Press Enter.

c. Copy/paste the following command line into the terminal, in order to edit the new file:

xed admin:///etc/systemd/system/fstrim.timer.d/override.conf

(Note: The three consecutive slashes aren't a typo, but intentional! For Ubuntu: type gedit instead of xed.)

Press Enter.

d. Now copy/paste this blue text into that empty text document:

[Timer]
OnCalendar=
OnCalendar=daily


Note: The double entry for OnCalendar is no mistake but intentional!

Save the modified file and close it.

e. Reboot your computer.

f. Confirm that you've successfully edited trim's configuration by executing this terminal command:

systemctl cat fstrim.timer

Your output should look approximately like this:

# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container

[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/fstrim.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=daily


Let's take a closer look at this output. The first part shows the default setting (weekly), the second part shows the overriding setting that you've applied. That overriding setting contains two elements: first the existing OnCalendar setting (weekly) is being deleted by specifying nothing after the = sign, and then a new OnCalendar setting is being applied (daily).

If you ever want to check whether fstrim has actually happened, and when it happened, you can use this terminal command:

journalctl | grep fstrim.service

If you're done with this step, you can continue with item 8.

How to undo (back to a weekly job)

6.1. Want to undo? It's easy to change the daily job back to a weekly job, namely as follows:

a. Copy/paste the following command line into the terminal, in order to remove the overriding settings:

sudo rm -v /etc/systemd/system/fstrim.timer.d/override.conf

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

b. Reboot your computer.

How to execute TRIM manually

7. You can execute TRIM manually as well. You can use a single terminal command that will execute TRIM on all mounted partitions that support it:

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

Type (use copy/paste):

sudo fstrim -av

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. 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 (1): it's possible that manually executing fstrim with -av doesn't work. In that case, use this command:

sudo fstrim -v /

Note (2): on a few SSD models (specifically two models from Crucial), executing a manual fstrim 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.

Now proceed to the next item.

Limiting swap wear: turn on zswap

8. You'll often achieve both a considerable speed gain and a reduction of disk writes, by turning on zswap. This is especially so on older machines, but on modern machines there will also be a speed gain, although it'll be smaller.

The kernel feature called zswap provides a compressed RAM cache for swap pages. Pages which would otherwise be swapped out to disk are instead compressed and stored into a memory pool in RAM.

Once the pool is full or the RAM is exhausted, the least recently used page is decompressed and written to disk, as if it had not been intercepted at all. After that page has been dumped into the swap file or partition, the compressed version in the pool will be freed.

By default, zswap is switched off. When switched on, it uses up to 20 percent of the RAM memory by default (don't increase that above 40, because higher percentages might have negative consequences).

The price you pay for turning on zswap, is twofold:

- Your processor (CPU) is being taxed more heavily, because it'll have to compress and decompress more;

- When the system has filled the RAM swap, it'll start swapping on the hard drive as well. With a burden on the available RAM: the chunk of memory that has been sacrificed for the RAM swap.

That's why I advise to turn on zswap only in combination with a swappiness that has been reduced to 30 (see item 8.1 on this page).

You can switch on zswap as follows (with superior fast threefold compression, by means of lz4 and z3fold):

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

b. Copy/paste the following command line into the terminal:

xed admin:///etc/default/grub

Press Enter. You'll be asked for your password twice, which is normal.

(the three consecutive slashes are intended and no typo!)

c. Find the following line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Now you're going to add some parameters to that line. This is the easiest way: simply replace the entire line by the following blue line (this is one long line, don't chop it up and use copy/paste to transfer it):


Machines with only 4 GB RAM or less (40 % zswap):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.max_pool_percent=40 zswap.zpool=z3fold zswap.compressor=lz4"

(if you want to type this line yourself: note that the "l" in "lz4" is a lowercase letter L)

Save the modified file and close it.


Machines with more than 4 GB RAM (default 20 % zswap):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4"

(if you want to type this line yourself: note that the "l" in "lz4" is a lowercase letter L)

Save the modified file and close it.

d. Copy/paste the following command line into the terminal, in order to execute the modification:

sudo update-grub

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

(if you type the command: note the dash between update and grub)

e. The module for the z3fold feature isn't included in the initramfs at boot time, so it won't be loaded automatically. As z3fold (threefold compression) is simply better than the default zbud (twofold compression), change that like this:

Copy/paste the following command line into the terminal:

xed admin:///etc/initramfs-tools/modules

Press Enter.

f. In the bottom of the text of that file, create a new line with z3fold in it, so that it becomes:

# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax: module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
z3fold


Save the changes and close the text editor.

g. Then in the terminal (use copy/paste to transfer the command to the terminal!):

sudo update-initramfs -u

Press Enter.

h. Reboot.

i. Now you can check whether the change has been implemented with this command (use copy/paste):

dmesg | grep zswap

It should report in its final line: zswap: loaded using pool lz4/z3fold.

j. The percentage of your RAM that zswap uses, can be checked with the following command:

cat /sys/module/zswap/parameters/max_pool_percent

It should report 20, which is the default, or 40. As said already: don't increase that above 40, because higher percentages might have negative consequences.

Warning: there's also RAM swap feature called zRam. Don't install that, because it's counterproductive in combination with zswap!

When zswap is enabled: decrease swap use

8.1. On the hard disk there's a separate file or partition for virtual memory, called the swap. When Mint uses the swap too much, the computer slows down. At least when zswap has been enabled (see item 8 on this page).

Note: Don't fully disable the disk swap, no matter how much RAM your computer has! Not only because zswap needs it, but also because disabling it is a bad idea in general: it's counterproductive to do so and might degrade the performance of your system.

Mint's inclination to use the swap, is determined by a value called "swappiness". The lower the value, the longer it takes before Mint starts using the swap.

On a scale of 0-200, the default value is 60. Which is too high for normal desktop use; the optimal compromise is probably something like 30. Decreasing the default value somewhat on a desktop computer, has no negative side effects.

Now the how-to for setting the swappiness to a more reasonable level, namely 30:

a. First check your current swappiness value. Type in the terminal (use copy/paste):

cat /proc/sys/vm/swappiness

Press Enter.

The result will probably be 60.

b. To change the swappiness into a more sensible setting, type in the terminal (use copy/paste to avoid typos):

xed admin:///etc/sysctl.conf

Press Enter. Note that you'll be asked twice for your password.

Now a text file opens. Scroll to the bottom of that text file and add your swappiness parameter to override the default. For that, copy/paste the following two blue lines into the text file:

# Decrease swap usage to a more reasonable level
vm.swappiness=30

c. Save and close the text file. Then reboot your computer.

d. After the reboot, check the new swappiness setting:

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

- Type (use copy/paste):

cat /proc/sys/vm/swappiness

Press Enter.

Now it should be 30.

Limiting the disk write actions of Firefox

9. You can limit the disk write actions of Firefox, by putting the Firefox network cache into the RAM and by disabling sessionstore. Like this:

Putting the Firefox network cache into the RAM

9.1. By moving the Firefox network cache from your hard disk to the RAM, you diminish the amount of disk writes. This'll probably make your Firefox noticeably faster as well. The price you pay is small: it'll only "cost" you 512 MB of your RAM.

Note: Don't do this when your computer has only 2 GB of RAM or less! Because with very little RAM, even 512 MB can't be missed.

Proceed like this:

a. Type in the URL bar of Firefox:
about:config
Press Enter.

b. Now you're being presented with a warning. Ignore it and click on the button "I accept the risk!".

c. Copy/paste the following into the filter bar (search bar):
browser.cache.disk.enable

Toggle its value to false by double-clicking it: this will disable "cache to disk" entirely.

d. Now you're going to make sure that "cache to RAM" is enabled (it is by default, but it may have been changed earlier). Copy/paste the following into the filter bar (search bar):
browser.cache.memory.enable

This should already be set to true; if not, toggle it to true by double-clicking it.

e. Then you're going to determine how much memory can be used as RAM cache. Copy/paste this into the filter bar (search bar):
browser.cache.memory.capacity
That entry should exist already (if not, create it now).

The current integer value will probably be -1, which automates the maximum size of the RAM cache dependent on the available amount of RAM. So far so good, but this automation usually creates a cache that's far too small....

So set it to 524288 (KB, which equals a maximum of 512 MB). That's usually enough for all amounts of RAM. But if you have RAM to spare, I recommend 1048576, which equals a maximum of 1 GB.

f. Close Firefox and launch it again. You're done! Check it like this:

Type in the URL bar:
about:cache
Press Enter.

By the way: you'll then also see a mention of an "appcache" which might still be present on the disk, but there's absolutely no need to move that (much less frequently used) cache to the RAM as well.

Note: This is a user preference. Repeat this hack in each user account.

Disabling sessionstore

9.2. Firefox has a session restore feature, which remembers what pages were opened if Firefox experiences an unexpected shutdown (read: crashes). This feature is neat, but causes many disk writes. Too many for an SSD. Disable it like this:

a. Type in the URL bar of Firefox:

about:config

Press Enter.

b. Now you're being presented with a warning. Ignore it and click on the button "I accept the risk!".

c. Type the following keyword into the filter bar: sessionstore

d. Double-click on the item called browser.sessionstore.interval. The default interval is 15000, which means 15 seconds. Add three zeros to the existing value, so that it becomes: 15000000 and click the OK button.

e. Close Firefox and launch it again. Now you've practically disabled the session restore feature.

Note (1): Leave the other cache and sessionstore settings as they are: usually, the less invasive a hack is, the better. Because this reduces the risk of unexpected unwanted side effects.

Note (2): This is a user preference. Repeat this hack in each user account.

Limiting the disk write actions of Chrome

10. The disk write actions of Google Chrome can be limited as follows.

a. Click on the three dots (vertical line) in the upper right of the Chrome window - Settings.

b. Section Privacy and security - Cookies and site data
Preload pages for faster browsing and searching: disable it.

c. Close Chrome and launch it again.

This way, you've disabled the "preload" feature, which can cause a lot of extra network traffic and also a lot of writes.

Now proceed to the next item.

(obsoleted)

11. This item has become obsolete.

Optional: set noatime

12. By setting "noatime", you disable the "access time stamp", that the operating system puts on a file whenever it's being read by the operating system. For an SSD "noatime" might be better, because it reduces the disk writes somewhat.

Although noatime doesn't make a big difference (which is why setting it has been labeled as optional), it has hardly any negative side effects: only in very rare use cases which almost nobody will ever encounter.

The easiest way to set noatime for your SSD, is this:

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

b. Then use copy/paste for transferring the following line into the terminal (don't try to type it: a typo can have serious consequences!):

sudo sed -i 's/ errors=remount-ro/ noatime,errors=remount-ro/' /etc/fstab

Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.

Note: Do you have a separate partition for /home? Then you need to execute this command as well (use copy/paste, don't type):

sudo sed -i 's/ defaults/ noatime,defaults/' /etc/fstab

Prevent fragmentation, and DO NOT defrag

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

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 disappearance of mechanical seek time in SSDs is a significant improvement.

But mechanical seek time only makes up a part of the 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 in this pdf file.

Dual boot or Virtual Machine? Don't let Windows kill your SSD

14. Do you have a dual boot with Windows? Then don't let Windows kill your SSD by defragmenting it: disable scheduled automatic defragmentation.

Defragmentation will kill your SSD in a very short time, because of the multitude of write actions that it causes. Windows should recognize an SSD by itself and then refrain from automatic defragmenting, but this SSD recognition has been known to fail in several cases. So make 100 % sure that Windows doesn't defragment your SSD automatically, by disabling that feature. Also in a Virtual Machine with Windows!

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

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

For the sake of completeness I mention below some (unfortunately) popular misconceptions about tuning SSD's:

Five pitfalls concerning SSD's


Unnecessary: alignment

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

In all versions of Ubuntu, Linux Mint and Debian, 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.

Unnecessary: overprovisioning

16.2. Over-provisioning (with or without a dash) is an outdated technique that was widely 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 considerable part of the SSD, which then remains unallocated space (unused capacity).

That outdated method took a sizeable slice out of the total storage capacity, which made nobody happy....

However, in the newer generations of SSD's (let's say since about 2014) the technology and firmware have improved so much, that such huge losses of storage capacity aren't needed any longer. Modern SSD's usually have some built-in unallocated space for overprovisioning anyway, which isn't accessible to the user.

So overprovisioning shouldn't be necessary anymore.

Strongly discouraged: TRIM by rc.local

16.3. You can also add the TRIM command to /etc/rc.local. Then this command will be executed automatically on system boot. Years ago, this was a good solution that hardly slowed the boot process down.

However, things have changed: nowadays there's a boot process called systemd. For systemd it may cause a huge boot delay (minutes!) when you put the fstrim command in /etc/rc.local. So that's why I strongly discourage this method.

Strongly discouraged: TRIM by discard

16.4. Unfortunately, another widely used method for automatic TRIM is to add the option discard to the partition lines in /etc/fstab. This is a heavily exaggerated measure with a high performance toll, and therefore not a good method!

The disadvantage of the discard method is namely, that it might regularly cause the system to slow down. Because it forces the system to apply TRIM instantly on every individual file deletion, which is resource-intensive, exaggerated and quite unnecessary. That's why I strongly discourage this method.

Strongly discouraged: hibernation

16.5. Hibernation (suspend-to-disk) causes a huge amount of write actions, which is bad for an SSD. In Linux Mint and Ubuntu, it's disabled by default. Don't enable it!

Want more tips?

17. Do you want more tips and tweaks? There's a lot more of them on this website!

For example:

Speed up your Linux Mint!

Clean your Linux Mint safely

Avoid 10 fatal mistakes


To the content of this website applies a Creative Commons license.

Back to the home page

Disclaimer