Ir al contenido principal

Enable TRIM On SSD (Solid-State Drives) In Ubuntu For Better Performance



kingston ssd 120gb v200


TRIM allows the OS to "inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally". Without using TRIM, the SSD speed decreases after a while so if you have a solid-state drive that supports TRIM, you should enable it so your SSD remains fast over time.

This isn't easy to benchmark because the performance decreases over time so you'd neet to check the SSD speed constantly for a few months to see exactly how the SSD is affected when TRIM is not enabled. But if your SSD read / write speed decreases a lot over time and you haven't enabled TRIM, this may be way.

Some articles mention using online discard - enabling TRIM by adding the "discard" option to /etc/fstab -, but there are many who say this isn't a good idea for most solid-state drives and you'll get a pretty significant performance hit when trying to delete a large number of small files. So below I'll let you know how to use both of these methods: online discard (not recommended) and the recommended way: using fstrim and a cron (anacron) job.

Note: the instructions below have been tested in Ubuntu, but they may (most probably) work with other Linux distributions as well.

Before enabling TRIM, you must make sure:
  • you're using the Linux Kernel 2.6.33 or newer
  • your SSD supports TRIM
  • the partition(s) are EXT4 or BTRFS*

* Since not many people are using BTRFS, this post will only cover enabling TRIM on EXT4 partitions.

If you're unsure if your SSD supports TRIM, you can run the following command:
sudo hdparm -I /dev/sda | grep "TRIM supported"

Where "/dev/sda" is the solid-state drive (it may be /dev/sdb, /dev/sdc, etc. for you), and the command should return something like this: "Data Set Management TRIM supported (limit 8 blocks)" (if there's no output, your SSD doesn't support TRIM).  If you don't know what to use here, you can get a list of hard disks and their partitions by using the following command:
sudo fdisk -l


Enable TRIM for solid-state drives (SSD) in Linux


Using online discard (fstab) - not recommended


If the conditions above are met, you can proceed to enable TRIM for your SSD. If you want to use the online discard option (not recommended!), open /etc/fstab as root with a text editor:
gksu gedit /etc/fstab

And add the "discard" option (separated by a comma and no space!) to the SSD partitions you want to enable TRIM for. Here's an example:
<file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb1 during installation
UUID=1cd2fc4f-7d99-4c7a-8ea7-6f9a2d5e5960 /               ext4    discard,errors=remount-ro 0       1


Using a daily cron job - recommended


Using a daily cron job, the SSD trimming will occur once every day.

To use a daily cron job (so the trimming will occur once a day) for TRIM (fstrim), open /etc/cron.daily/trim as root with a text editor (/etc/cron.daily/trim doesn't exist so this will create the file):
gksu gedit /etc/cron.daily/trim
 and paste this:
#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

The last two commands in the code above perform the actual trimming for the root (/) and home (/home) partition and you need to edit them: here, add the SSD partitions for which you want to enable the daily TRIM job (usually, you must add "/" if the root partition is on the SSD and "/home" if you've set up a separate home partition).

Before saving the file, you can check if the fstrim command works:
sudo fstrim -v /

The output should look similar to this:
andrei@ubuntu-desktop:~$ sudo fstrim -v /
/: 8158715904 bytes were trimmed

Once you've added your SSD partitions, save the file and make it executable using the following command:
sudo chmod +x /etc/cron.daily/trim

Ubuntu executes the daily cron (we're using anacron, so even if your computer is turned off at that time, the job will still be performed later on) jobs at around 06:25 so each day after that time, you can check the /var/log/trim.log log file to see the fstrim output.


For encrypted partitions


If you're using an encrypted partition, you'll have to perform some extra steps for this to work (not tested because I don't have any encrypted partitions!): edit /etc/default/grub as root:
gksu gedit /etc/default/grub

And add the following options under GRUB_CMDLINE_LINUX="" (it should be around line 12 in that file):
"allow-discards root_trim=yes"

After editing the file, it should look like this:

GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="allow-discards root_trim=yes"

Then, save the file and update GRUB:
sudo update-grub

Now edit /etc/crypttab as root:
gksu gedit /etc/crypttab

And add the "discard" option for the SSD partitions, like this (example):
#<target name>    <source device>            <key file>  <options>
var  UUID=01234567-89ab-cdef-0123-456789abcdef  none  luks,discard

And finally, run the following command:
sudo update-initramfs -u -k all


The above instructions (except for the encrypted partition part, which I can't test) have been tested on Ubuntu 12.10 and 13.04 (SSD: KINGSTON SVP200S 120 GB).

Entradas populares de este blog

Ultrastar Deluxe

El Karaoke para Linux La llegada de la Navidad significa reuniones con familiares y amigos, lo que nos lleva a buscar formas de entretenimiento. Una de ellas es el karaoke , y como no podría ser de otra manera en GNU/Linux tenemos nuestra opción Open Source, se trata de UltraStar Deluxe (para mí la mejor opción), que está basado en el primer Ultrastar aunque bastante más completo y fácil de usar. Esta aplicación es un clon libre de Singstar con el que podrás cantar cualquier canción e incluso crear la tuya propia. Si estáis interesados en instalarlo puedes añadir el repositorio para Ubuntu o bajarlo desde la página oficial en caso de usar otra distribución. sudo add-apt-repository ppa:tobydox/ultrastardx sudo apt-get update sudo apt-get install ultrastar-deluxe Una vez instalado sólo quedará añadir canciones . Como no podía ser de otra manera, existe una comunidad muy activa que nos proporciona gran cantidad de material listo para ser usado, una de ellas es Ultrastar

Descargar Packet Tracer 5.2 [Windows y Linux]

Packet Tracer 5.2 [Windows y Linux] Packet Tracer es la herramienta de aprendizaje y simulación de redes interactiva para los instructores y alumnos de Cisco CCNA. Esta herramienta les permite a los usuarios crear topologías de red, configurar dispositivos, insertar paquetes y simular una red con múltiples representaciones visuales. Packet Tracer se enfoca en apoyar mejor los protocolos de redes que se enseñan en el currículum de CCNA. Este producto tiene el propósito de ser usado como un producto educativo que brinda exposición a la interfaz comando – línea de los dispositivos de Cisco para practicar y aprender por descubrimiento. Packet Tracer 5.2 es la última versión del simulador de redes de Cisco Systems, herramienta fundamental si el alumno está cursando el CCNA o se dedica al networking. En este programa se crea la topología física de la red simplemente arrastrando los dispositivos a la pantalla. Luego clickando en ellos se puede ingresar

Control PS3 en Debian, Ubuntu

INSTALAR EL CONTROL DE PLAY STATION 3 EN GNU / LINUX. EN LAS DISTRIBUCIONES DEBIAN 6.0 SQUEEZE, DEBIAN WHEEZY (TESTING), LINUX MINT DEBIAN EDITION, LINUX MINT, GUADALINEX, UBUNTU. Les voy a decir como conectar su control de Play Station 3 en Debian por medio de un cable USB, personalmente lo he probado en Debian 6.0 Squeeze (estable) y Debian Wheezy (testing), no lo he probado en Linux Mint Debian Edition (LMDE), pero no tendría porque no funcionar. En el caso de Ubuntu y sus derivadas supongo que también debería funcionar, no lo he probado porque no uso dicha distro, pero los comandos los tome de un tutorial para ella, no es “copy and paste” , solo copie los comandos, el resto es de mi experiencia personal. NOTA PARA USUARIOS DE LINUX MINT, GUADALINEX Y UBUNTU: Los comandos que voy a poner son para Debian y Linux Mint Debian Editon, para el caso de Ubuntu y derivados ya saben que los comandos como root se ejecutan con “sudo”. Además creo q