TRIM command in Windows 7

How to enable TRIM command in Windows 7 with a Solid State Drive

All versions and releases of Windows 7 support the TRIM command. To enable or disable TRIM Command, you will need to open an Elevated Command Prompt window.

How To Open an Elevated Command Prompt window: Click on Start Orb > Type “CMD.exe” in Search box > Right click on “CMD” and select “Run as Administrator” (If you receive a prompt confirmation, click YES)

How to Enable TRIM Command

In the Elevated command Prompt windows, type the following:

fsutil behavior set disabledeletenotify 0

How to Disable TRIM Command

In the Elevated command Prompt windows, type the following:

fsutil behavior set disabledeletenotify 1

To check to see if the TRIM command is enabled n Windows 7 do the following:

fsutil behavior query disabledeletenotify

DisableDeleteNotify = 1 (Windows TRIM commands are disabled)
DisableDeleteNotify = 0 (Windows TRIM commands are enabled)

How to enable AHCI in Windows 7 after Instalation:

  1. Exit all Windows-based programs.
  2. Click Start, type regedit in the Start Search box, and then press ENTER.
  3. If you receive the User Account Control dialog box, click Continue.
  4. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINESSystemCurrentControlSetServicesahci
  5. In the right pane, right-click Start in the Name column, and then click Modify.
  6. In the Value data box, type 0, and then click OK.
  7. On the File menu, click Exit to close Registry Editor.

After this you’ll have to restart your computer, go to BIOS and enable AHCI. When you log in to Windows again, you’ll notice the installation of drivers for AHCI. Another restart will be required to finish the driver installation.

These steps are provided at your own risk and not suggested unless you know and understand the risks. You will want to make sure the controller driver and MB BIOS support this option before you enable it.

TRIM command for Linux

Most current SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling. The TRIM command is supported by the Ext4 and Btrfs filesystems but the latter is beyond of the scope of this tutorial. Most Linux users will find the ext4 filesystem more than sufficient for their needs. There are two requirements for using the TRIM command in Linux.

  1. Properly working installation of Ubuntu or other GNU/Linux distribution.
  2. Linux kernel 2.6.33 or later. Ubuntu 10.10 (Maverick) ships with kernel 2.6.35. This kernel is also available for Ubuntu 10.04 (Lucid) via a backport package.

With these two requirements satisfied, enabling the TRIM command is easy.

Make a backup copy of the current /etc/fstab for disaster recovery purposes:
sudo cp /etc/fstab /etc/fstab_bak-notrim

Edit the /etc/fstab file:

gksudo gedit /etc/fstab
or
sudo vi /etc/fstab

For every partition using Ext4 we add the word discard to the list of options. That means you need to prepend or append the word “discard” to the existing list of word options separating it with comma without leaving a space. Nothing else needs to be modified. For example, to change the root filesystem entry from:

UUID=[NUMS-AND-LETTERS] / ext4 errors=remount-ro 0 1

we change the entry to:

UUID=[NUMS-AND-LETTERS] / ext4 discard,errors=remount-ro 0 1

Save the changes and exit your editor.

Restart the operating system to have the changes take affect.
shutdown -r -y now
reboot
init 6

In case you make a mistake you can boot from the Ubuntu Live CD or other live Linux media, mount the root partition of your SSD and revert the changes by correcting any typos or syntax errors or restoring your backup file.

To test that the TRIM command is working, take the following steps:

Switch to the root user or preface your commands with sudo:
sudo -i
Creat a 50MB file with random data:
dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct
Check the starting LBA address of the file:
hdparm --fibmap tempfile
Read the first address of the file, note that you need to put the first LBA in place of [ADDRESS]:
hdparm --read-sector [ADDRESS] /dev/sdX
Remove the file and synchronize the filesystem:
rm tempfile
sync
Use the same command as in 4 to re-read the LBA:
hdparm --read-sector [ADDRESS] /dev/sdX

If TRIM is working correctly, the output of the last command will be a series of zeros. If the output is anything other than zeros, TRIM is not working. Check to make sure your kernel supports TRIM and recheck your ext4 filesystem configuration. This test will not work if your filesystem is encrypted.