You are not logged in.

#1 2024-01-17 15:04:09

OIhfes
Member
Registered: 2024-01-17
Posts: 10

Could not be able to run fstrim on LUKS

Hello everyone.
I am the very freshman to the archlinux and today I would like to ask a question that bothers me a lot.
Actually I want to do

sudo fstrim -v /

but it won't works because I encrypt the disk with LUKS and it will return

fstrim: /: the discard operation is not supported

So I refer to this site https://wiki.archlinux.org/title/Dm-cry … ives_(SSD), and following is my config based on it:
First I input

sudo nano /etc/fstab

and I edit it and add a line like this:

/dev/disk/by-uuid/My LUKS UUID   /           ext4  defaults,discard   0  1

Then I use this command:

sudo nano /etc/crypttab

And I edit it and add a line like this:

cryptroot      UUID=My LUKS UUID    none                    luks,discard

At last I save all of them and use this command

sudo mkinitcpio -P

then I reboot the computer. Unfortunately after the reboot I am still not be able to run fstrim on LUKS and it still return with

fstrim: /: the discard operation is not supported

Offline

#2 2024-01-17 16:43:34

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 613

Re: Could not be able to run fstrim on LUKS

OIhfes wrote:

First I input

sudo nano /etc/fstab

and I edit it and add a line like this:

/dev/disk/by-uuid/My LUKS UUID   /           ext4  defaults,discard   0  1

You don't need to mount with the discard option to use fstrim.

OIhfes wrote:

Then I use this command:

sudo nano /etc/crypttab

And I edit it and add a line like this:

cryptroot      UUID=My LUKS UUID    none                    luks,discard

The LUKS container with the root file system is unlocked in early userspace (in the initramfs stage). That's long before /etc/crypttab on real root gets parsed.
You should either use the method with kernel parameters or enable discards persistently by setting the allow-discards flag in the LUKS2 header. Both of those things are described in https://wiki.archlinux.org/title/Dm-cry … ives_(SSD) (which you linked).

Offline

#3 2024-01-18 02:54:38

OIhfes
Member
Registered: 2024-01-17
Posts: 10

Re: Could not be able to run fstrim on LUKS

Oh, I just found that

cryptsetup --allow-discards --persistent refresh root

can just makes me able to trim the SSD smile

Last edited by OIhfes (2024-01-18 02:58:40)

Offline

Board footer

Powered by FluxBB