12

A lot of SSD-related instructions online currently say you should add allow-discards and root_trim=yes to your GRUB_CMDLINE_LINUX. I have yet to find one that says why you should do that, i.e. what exactly (if anything!) do those parameters do. Where is the documentation on this and what does it say about those two parameters' purpose?

According to Cryptsetup 1.4.0 Release Notes,

Since kernel 3.1, dm-crypt devices optionally (not by default) support block discards (TRIM) commands. If you want to enable this operation, you have to enable it manually on every activation using --allow-discards

cryptsetup luksOpen --allow-discards /dev/sdb test_disk 

but is it the same when passed to the kernel (via GRUB_CMDLINE_LINUX)?

Edit: Kernel.org's list of kernel parameters doesn't (currently, Jan 2013, at least) have either of these options.

2

1 Answer 1

8

From my understanding the boot parameter root_trim=yes is Gentoo specific. Within genkernel there is a script which looks for the parameter and sets the option --allow-discards with cryptsetup (see their git repository). Furthermore I found many reports of Ubuntu or Debian users which said that it worked without the root_trim parameter. I also found no lines in Ubuntus update-initramfs script.

So all in all it is no boot parameter, but more a parameter to cryptsetup. The documentation of --allow-discards can be found in the manpage of cryptsetup(8):

--allow-discards
Allow using of discards (TRIM) requests for device. This option is only relevant for create, luksOpen or loopaesOpen.

WARNING: Assess the specific security risks carefully before enabling this option. For example, allowing discards on encrypted devices may lead to the leak of information about the ciphertext device (filesystem type, used space etc.) if the discarded blocks can be located easily on the device later.

Kernel version 3.1 or more recent is required. For older versions is the option ignored.

Based on this blog on TRIM & dm-crypt, TRIM is operation where upper layer (e.g. filesystem) informs the device which sectors are no longer used (do not contain valid data anymore) and that the device does not need to keep that data content.

In Linux terminology is this operation called discard. In the SCSI world it's be referred to as the UNMAP command.

The discard operation can be used for two purposes: thin Provisioning (informs that data area can be returned to allocation pool) and for SSD operation optimization.

Discards is most useful for SSD optimization since the internal architecture uses larger blocks than sectors and that the blocks must be erased before a write operation can be performed. Information about sectors which do not need to keep data is very useful since the filesystem would be able to more effectively organize blocks in such a way that data fragmentation is minimized and also the disk lifetime would increase.

7
  • So, neither of the options is needed if the filesystem isn't encypted? Why two options if all they do is enable one command to work? Jan 15, 2013 at 21:36
  • Thanks for pointing out the relation between the kernel parameter and the mount/devicemapper option in your updated answer. +1 this time. :)
    – gertvdijk
    Jan 16, 2013 at 11:33
  • This answer is starting to look good. I also found allow_discards in dm-crypt's current documentation; everything seems to imply it's not a kernel parameter but an option for the dm-crypt device-mapper target. I'm still trying to find out if those can be passed on the linux command line. That would explain the instructions parroted all over, otherwise it is probably just misinformation. Jan 16, 2013 at 12:05
  • 1
    @JaniUusitalo It really does not make sense to me to make this a (global) kernel paramater. 1) you really want to specify this filesystem/device-specific rather than system-wide, 2) mount/fstab options lets you do so already, 3) at boot time (before the initramfs has mounted your / as read/write) you're not likely to need this functionality.
    – gertvdijk
    Jan 16, 2013 at 12:53
  • 4
    The kernel parameterizing of allow-discards could be an Archism: apparently in Arch, you notify GRUB of an encrypted root with (e.g.) "cryptdevice=/dev/mapper/root:root:allow-discards". This being picked up by Ubuntu users might be due to Arch's wiki being referred to as "Best reference" by Ubuntu wiki's EncryptedFilesystems. Jan 16, 2013 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.