View previous topic :: View next topic |
Author |
Message |
Latrina n00b
Joined: 13 Aug 2017 Posts: 62 Location: Cambridge, UK
|
Posted: Fri Nov 24, 2017 10:24 pm Post subject: [SOLVED]Enable TRIM on LUKS + LVM ? OpenRC |
|
|
Hello folks,
my setup is very simple, ssd1 has / and ssd2 /home. They are both LUKS encrypted and do use LVM.
On ssd1 I was able to enable trim support by adding the following to /etc/default/grub
Code: |
GRUB_CMDLINE_LINUX_DEFAULT="root_trim=yes" |
and this to /etc/lvm/lvm.conf
To enable TRIM for ssd2 I tried adding
Code: |
cryptdevice=/dev/sdb1:home:allow-discards |
to /etc/default/grub and to GRUB_CMDLINE_LINUX_DEFAULT= but unfortunately that didn't do the trick.
Any idea? Thanks _________________ Enslaved by Systemd and all the linuxisms that come with it.
Last edited by Latrina on Sat Nov 25, 2017 3:23 pm; edited 1 time in total |
|
Back to top |
|
|
frostschutz Advocate
Joined: 22 Feb 2005 Posts: 2977 Location: Germany
|
Posted: Fri Nov 24, 2017 11:08 pm Post subject: |
|
|
One thing to point out, issue_discards = 1 does not enable trim. It makes LVM proactively issue trim, when you lvremove, lvresize, etc.
If you have ever ran a wrong LVM command and recovered from that by using one of the backups in /etc/lvm - that doesn't work any more with issue_discards = 1 as that has already discarded your data.
I recommend issue_discards = 0. If you want to trim unused space in an LVM, you can always do it by lvcreate -l100%FREE somelv, and then blkdiscard somelv and subsequently lvremove somelv.
----
crypt is pretty much the only thing that prevents trim and needs allow discards to enable. Everything else just supports it automagically if it's at all possible (e.g. mdadm works for all but the most obscure raid levels).
You can check if it's enabled via 'dmsetup table'.
Code: |
# devices with allow_discards:
dmsetup table | grep crypt | grep allow_discards
# devices without allow_discards:
dmsetup table | grep crypt | grep -v allow_discards
# latter is normal if you also have encrypted HDD instead of SSD
|
Unfortunately there is no (obvious/safe) way to add the allow_discards flag at a later time (although technically it's possible to do so). So you have to track down what is actually running cryptsetup open on your device, and find out why it's not passing the allow discards flag. This could be your initramfs (of which there are several different flavors), some init script, etc.
----
You're referring to your devices by /dev/sdb1, should use UUID in any case as drive letters may change around randomly as well. |
|
Back to top |
|
|
Latrina n00b
Joined: 13 Aug 2017 Posts: 62 Location: Cambridge, UK
|
Posted: Sat Nov 25, 2017 3:16 pm Post subject: |
|
|
Hey @frostschutz, thanks for clarifying the scope of issue_discards=. You made me realize it had nothing to do with mounting the LUKS encrypted drive with trim support and it had the potential to do more harm than good.
In the end, and after hours of googling, I stumbled upon the resolution. In order to enable TRIM support on a LUKS encrypted drive at a later time, you need to add options="--allow-discards" to the disk definition in /etc/conf.d/dmcrypt.
For example:
Code: | ## Definition for /dev/mapper/home /home (/dev/sdb1)
target=home
source=UUID="XXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXX"
key='/etc/keys/home.key'
options="--allow-discards" |
Restart the system and execute sudo dmsetup table /dev/mapper/YourVolume --showkeys. If all went well, the output will have 1 allow_discards.
In conclusion this took me several hours due to absolute lack of documentation, nor in gentoo wiki nor anywhere else as there aren't many OpenRC distros out there. All the guides I was able to find they all pointed out to systemd.
In my opinion this should be added to https://wiki.gentoo.org/wiki/Dm-crypt .
Thanks for the help. _________________ Enslaved by Systemd and all the linuxisms that come with it. |
|
Back to top |
|
|
frostschutz Advocate
Joined: 22 Feb 2005 Posts: 2977 Location: Germany
|
Posted: Sat Nov 25, 2017 4:10 pm Post subject: |
|
|
It's a wiki, feel free to edit. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|