How to remove old kernels from a TemplateVM

My standard Qubes Debian-11 template has grown to a size of ~10GB, about 4GB of these are used by quite a lot of older kernels. This isn’t a huge problem of course, but it’s just a little bit nagging/aggravating.

Before starting to behave like an idiot purist and blindly type ‘sudo apt autoremove’ in the template, thereby possibly (partly) wrecking a fine working system, I would like to hear the (not so) expert opinions on this matter.

As a contrast, a fully functional Debian11-minimal template which was rarely updated because it was mostly used as a starter for other templates, is just 1.3GB in size, that’s quite a difference.

I’d also like to use this post to say a well meant thanks to all of the Qubes team, for this fantastic OS.

Does sudo apt-get autoremove suggest any of those old kernels for removal?

1 Like

yes, from 5.10.0-10 up to 5.10.0-22. It also wants to remove some other stuff, but nothing that seems Qubes related.

Yet blindly running autoremove might be an invitation to the blues.
(I ran it in an AppVM to test, all went well, but it doesn’t boot up in the new state of course).

I feel quite the opposite:

  • apt/apt-get is the package manager for Debian
  • its autoremove command identifes packages that are no longer used in the system

I use it as a starting point. Unless I’ve installed packages in unconventional ways, I treat anything that’s flagged by autoremove as a no-brainer. Once that done, if I still need additional space then I start thinking. YMMV!

As usual, making a backup or a clone of your template before experimenting with it is always a good idea!

The docs are more nuanced than me and give good guidance:

autoremove (apt-get(8))

autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed as dependencies changed or the package(s) needing them were removed in the meantime.

You should check that the list does not include applications you have grown to like even though they were once installed just as a dependency of another package. You can mark such a package as manually installed by using apt-mark(8). Packages which you have installed explicitly via install are also never proposed for automatic removal.

(source: apt man page)


little search with ducduckgo:
Inspired by this page: How to Remove Old Kernels in Debian and Ubuntu -

-Find the kernel in use:
uname -sr

-List all installed kernels:
dpkg --list | grep linux-image | awk ‘{print$2}’

Then delete kernels you want to remove:
dpkg --purge linux-image-xxxxx linux-image-xxxxxxxxxxxxx

Procedure of the same way for the header: replace “linux-image” by “linux-headers”.

If the OP is worried about potentially removing a package they shouldn’t, I really don’t think this is this better than using a tool that at least verifies that no other package depends on the one you’ll remove. :confused:

After seeing your topic, I said to myself "it’s true that it’s been a while since I cleaned up! ". So, I tried this method on my other Debian system and it all went well. I then came to do the same thing on my templates. No problems to report… :slight_smile:
I kept a kernel anyway, just in case but everything seems ok…
One more thing, i make:

sudo update-grub2

to update the configuration.

Out of caution I first tried to backup the template, but this failed for some unclear reason. After 1 hour, progress was still at 0% with no processor activity.

Then I decided to run apt autoremove --purge anyway. Because I hardly adapt the standard Qubes templates, there wouldn’t be that much of a problem in case of failure, a simple reinstall of the template would fix it.

The process went fine, also AppVM’s based on the template boot up fine again. I think it’s more prudent to leave grub alone in the template, especially when simply using apt autoremove to delete old kernels there is no need for that AFAIK.

Thanks Gonzalo and Tezeria for the feedback.

The template has shrunk for approximately 40%. I still wonder in what way a larger template could be a hindrance for the system. AppVM’s take the same amount of time to boot with the now smaller template.

If for instance a template is 10 GB and you start 5 AppVM’s based on this template, does the system make 5 copies, temporarily using a total of 50GB?

Fortunately not! lol . I believe (correct me if I’m wrong but I never calculated!) that each AppVMs only weighs the content of /home and /rw. For example, my template debian12 use 5.7GB and my sys-net based on the template debian12 use 223MB, debian-12-dvm 185MB, sys-vpn 150MB, etc…

1 Like

There is Qubes documentation about the subject

So, old kernels bloating the template are probably not at all important, even less than in a physical system where they can fill up a boot partition. Still happy I deleted them :wink:

1 Like

I’ve used this successfully many times in Mint, which is Debian based.
It works.