1

I want to have a LUKS volume as a loopback device pointing at a sparse file. Lets say I put a 20gb file on it, then later I delete it. How can I zero that area on the device itself so I can fallocate -d the loopback file to reclaim the space?

Daffy
  • 375
  • 2
  • 10

1 Answers1

1

Not answering the question as written, but to achieve the desired effect, you can open the luks partition like this.

$ losetup -f --show luksfile
/dev/loop0
$ cryptsetup open --allow-discards /dev/loop0 luksvolume
$ mount -o discard /dev/mapper/luksvolume /mnt/luksvolume

This makes the cryptsetup device obey TRIM commands, which makes the underlying file grow and shrink accordingly. The mount -o discard can be replaced with an occasional trimfs.

It should be noted, however, that using TRIM on luks partitions could have security implications.

Daffy
  • 375
  • 2
  • 10