diff --git a/install/login/limine-snapper.sh b/install/login/limine-snapper.sh index c91815dca5..d8de4fa449 100644 --- a/install/login/limine-snapper.sh +++ b/install/login/limine-snapper.sh @@ -29,6 +29,11 @@ EOF CMDLINE=$(grep "^[[:space:]]*cmdline:" "$limine_config" | head -1 | sed 's/^[[:space:]]*cmdline:[[:space:]]*//') + # Enable SSD TRIM passthrough for LUKS-encrypted drives + if [[ $CMDLINE == *"cryptdevice="* ]] && [[ $CMDLINE != *"allow-discards"* ]]; then + CMDLINE=$(printf '%s\n' "$CMDLINE" | sed 's/\(cryptdevice=[^ "]*\)/\1:allow-discards/') + fi + sudo cp $OMARCHY_PATH/default/limine/default.conf /etc/default/limine sudo sed -i "s|@@CMDLINE@@|$CMDLINE|g" /etc/default/limine diff --git a/migrations/1776500000.sh b/migrations/1776500000.sh new file mode 100644 index 0000000000..df961d560c --- /dev/null +++ b/migrations/1776500000.sh @@ -0,0 +1,28 @@ +echo "Enable SSD TRIM for LUKS-encrypted drives" + +# Only apply if the system uses LUKS encryption +if ! grep -q "cryptdevice=" /etc/default/limine 2>/dev/null; then + exit 0 +fi + +# Skip if allow-discards is already configured +if grep -q "allow-discards" /etc/default/limine 2>/dev/null; then + exit 0 +fi + +# Add :allow-discards to the cryptdevice= parameter in the boot config +# Format: cryptdevice=device:dmname -> cryptdevice=device:dmname:allow-discards +sudo sed -i 's/\(cryptdevice=[^ "]*\)/\1:allow-discards/' /etc/default/limine + +# Extract the dmname from cryptdevice=device:dmname and enable allow-discards +# on the running LUKS device so TRIM works immediately +DMNAME=$(grep -oP 'cryptdevice=[^: "]+:\K[^: "]+' /etc/default/limine | head -1) +if [[ -n $DMNAME ]] && [[ -b /dev/mapper/$DMNAME ]]; then + sudo cryptsetup --allow-discards --persistent refresh "$DMNAME" +fi + +# Regenerate initramfs and boot entry +sudo limine-mkinitcpio +sudo limine-update + +echo "SSD TRIM enabled for LUKS encryption"