Enable SSD TRIM for LUKS-encrypted drives#5332
Open
stephentaylor-com wants to merge 2 commits intobasecamp:devfrom
Open
Enable SSD TRIM for LUKS-encrypted drives#5332stephentaylor-com wants to merge 2 commits intobasecamp:devfrom
stephentaylor-com wants to merge 2 commits intobasecamp:devfrom
Conversation
Add :allow-discards to the cryptdevice= kernel parameter so TRIM commands pass through the dm-crypt layer to the SSD. Without this, the drive controller treats freed blocks as occupied, increasing write amplification and reducing drive longevity. Migration applies the change immediately via cryptsetup --persistent so no reboot is required. New installs get it automatically during Limine setup. Closes basecamp#2229
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enables SSD TRIM passthrough for LUKS-encrypted root volumes by ensuring :allow-discards is set on the cryptdevice= kernel parameter and by updating existing installations via a migration.
Changes:
- Add a new migration to update
/etc/default/limineto include:allow-discardsand regenerate Limine artifacts. - Attempt to enable discards immediately on existing installs via
cryptsetup --allow-discards --persistent refresh …. - Update the Limine setup path for new installs so generated
/etc/default/limineincludes:allow-discardswhencryptdevice=is present.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
migrations/1776500000.sh |
Adds migration to append :allow-discards to cryptdevice= and rebuild Limine initramfs/entries. |
install/login/limine-snapper.sh |
Ensures new installs include :allow-discards in the extracted cryptdevice= cmdline before writing /etc/default/limine. |
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use printf instead of echo to avoid edge cases with cmdline values - Extract dmname dynamically instead of hard-coding /dev/mapper/root - Exclude quotes from sed match to handle KERNEL_CMDLINE[...] format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
:allow-discardsto thecryptdevice=kernel parameter so TRIM commands pass through the dm-crypt layer to the SSDcryptsetup --persistent(no reboot required):allow-discardsautomatically during Limine setupCloses #2229
Details
Without
:allow-discards, dm-crypt blocks all TRIM/DEALLOCATE commands from reaching the SSD — even on modern NVMe drives. The drive controller treats freed blocks as occupied data, increasing write amplification and reducing drive longevity.Since kernel 6.2, btrfs automatically enables
discard=async, sofstrim.timeris not needed. The only missing piece is allowing TRIM commands to pass through the LUKS encryption layer.Changes
migrations/1776500000.sh— Migration for existing installs:cryptdevice=in/etc/default/limine:allow-discardsto the kernel parametercryptsetup --allow-discards --persistent refresh rootinstall/login/limine-snapper.sh— For new installs::allow-discardsto the extractedcryptdevice=cmdline before writing to/etc/default/limineTest plan
lsblk --discardshows non-zeroDISC-GRANfor root after migrationsudo fstrim -avtrims the root partition:allow-discardsin/etc/default/limine