Trim in templateVMs

Hello! How can I trim the disk in template VMs? I’m a new user and I don’t quite understand how to do this. In dom0, the command sudo fstrim -av works, but this operation is not supported in the templates. Please explain to me how this works in templates.

Thanks

1 Like

Hi,

If you use the Qubes OS templates, this works out of the box. When a qube delete stuff on their virtual disk, it’s reclaimed in the LVM pool once no snapshot of that qube are living (there is one snapshot of history by default).

2 Likes

Thank you for the response! So I don’t need to do anything in the templates? Or do I need to execute some commands to clear the cache and outdated dependencies? Sorry for such details. I’m just afraid of entering the wrong command and messing something up

1 Like

There is nothing special to do. At best, in templates qubes, at least debian for sure, you could remove old packages from the cache but it’s not that big.

2 Likes

Wow. That’s cool! That means the template will never fill up the entire disk if I don’t install additional programs? I used to have to run trim after every system update in KVM. Should I enable this in dom0, or is that already outdated information?

systemctl enable fstrim.timer
systemctl start fstrim.timer
1 Like

trim in dom0 is useful if you want to trim your SSD, which has pros and cons

for templates, you have nothing to do :slight_smile:

2 Likes

Cool! Thank you!

1 Like

And the last question for a complete understanding of this topic :slightly_smiling_face: I just deleted several apps in template and freed up 450 MB of disk space. But the disk usage did not change after rebooting the template. If I don’t need to do anything, when will the template disk free up 450 MB?
For example, I want to backup my qubes to a usb drive, but the template are taking up slightly more space than the usb drive has available. Perhaps there are some specific actions I can take to speed up the trim that I don’t know about :slightly_smiling_face:

1 Like

See this Volume backup and revert | Qubes OS

That’s why I mentioned snapshots, I should have linked this earlier, sorry.

2 Likes

This works if I have the template running in vm-pool, but if my template is in varlibqubes, I get errors when trying to revert: “NotImplementedError: Volume FileVolume has revert() not implemented”. What should I do in this case? I can manually delete old snapshots in /var/lib/qubes/vm-templates, but what should I do next if the command sudo fstrim -av does not work inside the template? I would be very grateful for a detailed answer. Thank you :blue_heart: :pray:

1 Like

can you describe what you did exactly?

1 Like

That’s the legacy ‘file’ storage driver (not lvm_thin or file-reflink). ‘file’ is rather broken and should not be used anymore. Indeed it has trouble freeing disk space and handling revisions.

You may want to reinstall Qubes OS with one of the supported automatic installation layouts: LVM Thin, Btrfs, or the so-called Standard Partition layout with XFS.

1 Like

Hello. I need to install my qubes in varlibqubes. I assume the problem is related to this? In varlibqubes can’t trim be done?

1 Like

My qube is installed in varlibqubes. I entered command qvm-volume revert fedora:private old but received the error ‘Got empty response from qubesd. See journalctl in dom0 for details’. In journalctl ‘NotImplementedError: Volume FileVolume has revert() not implemented’

1 Like

varlibqubes is just the name of a pool. It can use the modern file-reflink driver or the legacy ‘file’ driver, depending on whether the filesystem hosting its directory /var/lib/qubes supports reflinks or not.

If the ‘file’ driver is used, trimming some types of storage volumes (notably the ‘root’ volume in a TemplateVM) isn’t possible.

1 Like

Thank you for the response. How can I check info about it and what should I do to fix it? I am not a very advanced user, so I would be very grateful for a detailed answer :pray:

1 Like

How come?

If you run qvm-pool in a dom0 terminal, it will list the available pools.

If you really want to use varlibqubes though, the installation layout should be one of the latter two. Because for LVM Thin, varlibqubes is just a secondary ‘file’ pool that’s not really meant to be used.

1 Like

Will this be in the disk selection? I didn’t pay attention to this during the Qubes installation. I chose the default options

I am using it to run my qubes in ram Qubes in tmpfs 🤫 - #30 by qstateless

NAME          DRIVER
varlibqubes   file
linux-kernel  linux-kernel
vm-pool       lvm_thin

:neutral_face:

1 Like

And a question for the future - if I reinstall Qubes with LVM Thin, Btrfs, or the so-called Standard Partition layout with XFS, will I be able to do trim via revert? Or will revert no longer be needed and it will work automatically? Thank you

1 Like

Oof. There are a lot of ways to shoot yourself in the foot with these kind of setups if you’re not very familiar with the internal workings of Qubes OS and its storage, and even then…

I can’t really help you with this and would recommend just using a normal Qubes OS system (which will automatically reclaim disk space) instead. Sorry.

1 Like