Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED]Enable TRIM on LUKS + LVM ? OpenRC
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Latrina
n00b
n00b


Joined: 13 Aug 2017
Posts: 62
Location: Cambridge, UK

PostPosted: Fri Nov 24, 2017 10:24 pm    Post subject: [SOLVED]Enable TRIM on LUKS + LVM ? OpenRC Reply with quote

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
Code:

issue_discards = 1


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
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Fri Nov 24, 2017 11:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Latrina
n00b
n00b


Joined: 13 Aug 2017
Posts: 62
Location: Cambridge, UK

PostPosted: Sat Nov 25, 2017 3:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sat Nov 25, 2017 4:10 pm    Post subject: Reply with quote

Latrina wrote:

In my opinion this should be added to https://wiki.gentoo.org/wiki/Dm-crypt .


It's a wiki, feel free to edit.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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