Using QEMU on btrfs host with Timeshift

My dear fellows,

recently I’ve been searching and studying a lot of information about btrfs, but there is still one particular setup scenario where I would need your help or at least confirmation. It is combination of btrfs, Timeshift snapshots and using your computer as host for QEMU virtual machines.

What I have learned so far (and I really need to highlight THIS HOWTO as it is pure gold and helped me a ton:

  • When choosing btrfs during EndeavourOS installation, the installers intelligently creates subvolumes @ (for root), @home, @cache (for /var/cache), @log (for /var/log) and even @swap for storing swapfile with nocow attribute, so there is almost no reason to adjust anything, as the subvolumes layout makes perfect sense
  • The above layout, among other things, ensures that certain subvolumes are omitted from Timeshift snapshots, as Timeshift automatically skips subvolumes created/mounted underneath root (@)
  • At the same time, however, btrfs is many times considered as not ideal for storing virtual machines, especially qcow2 volumes from KVM/QEMU. It has something to do with double copy-on-write approach, with a lot of fragmentation and low performance
  • One recommended approach is to store qcow2 images in a folder which has nocow attribute set (chattr +C) and therefore all files in this folder would be created with copy-on-write disabled
  • Unfortunately, as soon as this folder is snapshotted (via Timeshift), copy-on-write is automatically enabled

And now the big question - what to do? Would the following approach be valid?

  • Create one additional subvolume, e.g. @vm, set its attribute to nocow (chattr +C) and mount it for example under /vm
  • This way, the qcow2 images would be created with copy-on-write disabled, and since the subvolume is mounted under root, Timeshift would exclude it from snapshotting

Looking very much forward to your feedback and advice!

1 Like

Yes, of course. Whenever you have something that you want to exclude from snapshots, the best way is to create separate subvolume for it. You can create a subvol at the root called @vm and mount it somewhere or you can just create a nested subvol wherever you keep your VM files and not worry about mounting it.

1 Like

Thank you so much dalto for the ninja-fast reply!

I don’t suppose I need the autodefrag and compress options when mounting the @vm subvolume, as long as it would only contain the qcow2 images, right?

Yes, you don’t.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.