2

When using an encrypted drive in a virtual machine, the VM image starts very small if you do not initialize the drive with random data. When you fill the drive, it grows, but when you delete files it doesn't shrink.

With a not encrypted drive, you can fill the drive with zeros (i.e. by creating a large file filled with zeros), so the VM-Software can compress it. But with a encrypted drive, the zeros get encrypted and the VM image cannot shrink.

Is there some kind of TRIM command like SSDs have, which zeros out the unused space of a filesystem on the underlying encrypted blockdevice?

  • Plain dm-crypt? Are you sure about that? How exactly did you set up these encrypted volumes? – Michael Hampton Feb 15 '17 at 18:00
  • 1
    Well, fstrim is exactly doing that. But you have to add the discard option in the /etc/crypttab. You also have to make sure that the trim command is supported all the way down to your virtual disk and virtual storage controller. – Thomas Feb 15 '17 at 18:33
  • This also depends on what filesystem you're using on top of everything. Your TRIM command will be started there, and will be passed down through your storage stack until it hits however deep you've configured it to go. With most volume managers (LVM, for example) this is turned off by default but is configurable. – Spooler Feb 15 '17 at 18:33
  • 1
    ahem high five, @Thomas – Spooler Feb 15 '17 at 18:34
  • No, dm-crypt with LUKS, but i guess the needed infrastructure would be in the devicemapper code. @Thomas Thank you, will try. But i guess it passes a real "TRIM" command, not an emulated one (save zeros to the virtual disk)? – allo Feb 16 '17 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.