SSD

This article describes how to set up SSDs (Solid State Drives) on Gentoo Linux. It presumes the user has obtained knowledge of setting up, partitioning, and formatting mechanical hard drives.

Rootfs
The  option on a rootfs mount should not be used. is the "TRIM" command that tells the SSD to do its magic. Having discard running constantly could potentially cause performance degradation on older SSDs. Modern SSDs use discard by default. Rather the following command can be used manually or be setup as a cron job (see below) to run twice a day, which should suffice for the rootfs:

Mount point
If you're going to have a low write directory mounted on SSD, using the  mount option will be fine in. See below. If you're going to mount a database to an SSD, you probably want timed TRIM commands rather than the discard option.

Partitioning
The utility (, version 2.24.1-r2 and up) can be used for GPT disk partitioning.

Use type to run, use  option for help. The following is an example for GPT partition table with BIOS motherboard. Type + to create a new empty GPT partition table on the SSD. Type +,, , +, +, + to create BIOS boot partition.

Next create a 2GB swap partition:

Finally create system root partition and write the changes:

Although is a tool familiar to many Linux users, other common partitioning tools exist:, , and. All of them (newer versions) handle partition alignment automatically. When in doubt whether partition is aligned, check that each partition starts on a MiB boundary (multiple of 2048 sectors). This should be 'safe' for any device (SSD or not).

LVM
LVM aligns to MiB boundaries and allows discards by default. No special configuration is required.

In order to TRIM all unused space in the VG use the utility:

Alternatively, there is a discard option in which makes LVM discard entire LV on lvremove, lvreduce, pvmove and other actions that free physical extents (PE) in a VG. However, enabling it will immediately render the system unable to undo any changes to the LV layout.

LUKS
For TRIM to work on encrypted LUKS devices, they have to be opened with the  option.

When root-device exists on LUKS, enabling TRIM depends on the Initramfs implementation. When using genkernel for creating your initramfs, pass the following kernel option:

When using dracut for creating your initramfs, pass the following kernel option:

Formatting
If you can find your erase block size, you can add some extended attributes that may help performance. For software raid, you really should know the erase block size. Consider this information when making your purchase. Regardless of whether you're using RAID or not, setting extended values is known to be beneficial. https://raid.wiki.kernel.org/index.php/RAID_setup#ext2.2C_ext3.2C_and_ext4

http://blog.nuclex-games.com/2009/12/aligning-an-ssd-on-linux/

The modern FAQ found on the Arch wiki too:

https://wiki.archlinux.org/index.php/SSD

Without knowing the erase block size

 * 1) Formatting the rootfs partition /dev/sda3:
 * 2) Using 4096 byte blocks by default aligns the SSD for writes (see [defaults] section of /etc/mke2fs.conf and also
 * 3) man mkfs.ext4 about "-b block-size" and "-T usage-type[,...]" inside it):

With knowing the erase block size | this info can be outdated

 * 1) Formatting the rootfs partition /dev/sda3:
 * 2) Using 4096 byte blocks aligns the SSD for writes;
 * 3) Using ERASE_BLOCK_SIZE / 4 as the stride and stripe width size;
 * 4) In this example, OCZ Vertex drives have 512 kibbibyte -
 * 5) Erase Block size, therefore stride/stripe-width = 512/4 = 128:

known erase block sizes

 * crucial m500 240G; stride and stripe width is 2048KB


 * SanDisk z400s; stride an stripe width is 4096KB

blkdiscard
If you are formatting a previously used device and your preferred does not support bulk discards when creating the filesystem, you can use  (from  or later) before creating the filesystem.

Mounting
Given the considerations above, either add something similar to this:

Or:

If you choose the latter, see the cron section below you don't want to manually TRIM the drive.

Once you've set up you can run the following command to have the drive mounted:

In the same way you can add discard option to the swap line in fstab too. The following example shows you how SSD disk swap can be parallelized with SATA disk swap:

Once you've set up swap in fstab you can run the following command to make swap available:

cron
Run  from cron twice a day to automatically do "discard":

#Mins Hours  Days   Months  Day of the week   command 15    1,13   *      *       *                 /sbin/fstrim -v /

There is also a semi-automatic cronjob available on GitHub called SSDcronTRIM which has the following features:


 * Distribution Independent script (developed on my Gentoo system).
 * The script decides every time depending on the disk usage how often (monthly, weekly, daily, hourly) each partition has to be trimmed.
 * Recognizes if it should install itself into /etc/cron.{monthly,weekly,daily,hourly}, or any other defined directory and if it should make an entry into crontab.
 * Checks if the kernel meets the requirements, the filesystem is able to and if the SSD supports trimming.
 * Simply install it by running it once without any option and uninstall it with the  option

Future version should implement:


 * Use of and  to let trimm only run when the disc is not busy.
 * Overgive options to fstrim (e.g. '-m 1M')
 * support for encrypted filesystem (LUKS)

fstrimDaemon
If your computer turned off when cron scheduled its job, fstrim would not be called at all. You can install fstrimDaemon to solve this problem.

Temporal files to TMPFS
When using an SSD, administrators generally want to reduce the amount of writes performed. You can mount your desired mountpoints into a TMPFS for reduce the I/O to the disk (and improve performance)

this is an example of and  on TMPFS but you must study all your actions and your convenience

Remember that all data in TMPFS will be loss after reboot or shutdown

Portage TMPDIR on TMPFS
On Gentoo, Portage is a huge source of writes, and putting these writes into system memory rather than a disk is beneficial. If you have more than 8GB of ram you may want to consider using tmpfs, which is a way to dedicate some system memory to storage on a temporary basis. It is generally advised to not use more than half of the available system memory for tmpfs.

For the next example, presume the system has 12GB of memory and the user would like to allow up to 6GBs for tmpfs. Edit and add:

After the fstab entry is set, tell Portage to use the above location to compile temporary space. This is done in :

you can explain your information on an specific gentoo's wiki article: Portage_TMPDIR_on_tmpfs

XDG cache
When running Gentoo on desktop, many programs, using X windows systems (Chromium, Firefox, Skype, etc.) are making frequent disk I/O every few seconds to cache. Default cache directory is, which is on hard drive and should be moved to tmpfs.

Create the file and add the following lines to it:

Do not forget to run env-update && source /etc/profile:

Browser profile/s and cache to RAM or HDD
Since the profile/s, browser cache*, etc. are relocated into TMPFS (RAM disk) or another mount point into an HDD, the corresponding I/O associated with using the browser is also redirected from the physical drive to RAM, thus reducing wear to the physical drive and also greatly improving browser speed and responsiveness.

You can move them with the utility

Add that users whose browser/s profile/s will get symlinked to a TMPFS or another mountpoint in the value USERS= and define the new mountpoint for the browser's profile/s and cache in the value VOLATILE=

close all the browsers, start the daemon and enable it

you can view all symlinks viewing the status of the daemon since started

More info about Profile Sync Daemon on https://wiki.archlinux.org/index.php/profile-sync-daemon