User experience in using apt clean on PVE

gfngfn256

Distinguished Member
Mar 29, 2023
2,487
776
153
I know that Debian/Ubuntu by default do not remove cached packages & as such nor does PVE.

I make semi-regular offline disk images of my entire host's OS disk & as such:
The smaller the used space is on the disk; the smaller the resulting (compressed) disk image is & the shorter the entire imaging process takes - hence less downtime.

Over time the apt cache fills up.
Here is an example on a PVE host that is ~2 years old:
Code:
~# du -h -x -d1 /var/cache/apt
5.8G    /var/cache/apt/archives
5.9G    /var/cache/apt
That is from a root system that in total:
Code:
~# du -h -x -d0 /
9.8G    /

So that is a whopping 5.9/9.8=>60% on the apt cache itself!

I'm thinking that (on a system that anyway has full internet access) running apt-get clean can do no harm.

However, before taking such a (drastic?) step, I would really appreciate any other users' experience/advice with this.
 
You can also just configure APT do to automatic cleanup of downloaded packages like yum/dns would do automatically:

Code:
echo 'APT::Keep-Downloaded-Packages "false";' > /etc/apt/apt.conf.d/99deletepackages

This only applies to newly downloaded packages. You need to run apt clean before.

EDIT: typos
 
Last edited:
  • Like
Reactions: UdoB
and a little background after thinking a bit more about this:

The smaller the used space is on the disk; the smaller the resulting (compressed) disk image
Keep in mind that you would want to overwrite the free space on the filesystem with zeros or issue some discards to really have nothing on the block device before backing it up.

However, before taking such a (drastic?) step
It's not drastic and automatically done by most automation tools if you use them for updates.

I know that Debian/Ubuntu by default do not remove cached packages
'downloaded' would be the word here. Depending on your configuration those can be packages that have been installed or packages that are going to be installed.
 
Code:
echo 'APT::Keep-Downloaded-Packages "false";' > /etc/apt/apt.conf.d/99deletepackages
Sorry, posting so much on this thred, but the answer is sadly no as straight forward as it should be. The setting is default since a couple of Debian versions and it works flawlessly with Debian Bookworm. After install/upgrade the files are removed. I cannot see why PVE should be different in this regard, which is not. It also removes its downloaded packages after installation, just checked. However, I also have older packages from 2024 and before in my apt cache folder, so that may have changed in the past. This is very strange.
 
Sorry, posting so much on this thread
On the contrary - I absolutely want to hear everything. So thanks would be in order!


not as straight forward as it should be
I also discovered some of your findings - during my research.

It also removes its downloaded packages after installation, just checked.
Were you using apt or apt-get ? I believe this is (possibly) one of the differences between the two.

However, I also have older packages from 2024 and before in my apt cache folder
I previously did my own snooping:

Code:
~# ls -lh /var/cache/apt/archives/ | grep "2025" | wc -l
8
~# ls -lh /var/cache/apt/archives/ | grep "2024" | wc -l
413
~# ls -lh /var/cache/apt/archives/ | grep "2023" | wc -l
246
~# ls -lh /var/cache/apt/archives/ | grep "2022" | wc -l
25
~# ls -lh /var/cache/apt/archives/ | grep "2021" | wc -l
3
~# ls -lh /var/cache/apt/archives/ | grep "2020" | wc -l
6
~# ls -lh /var/cache/apt/archives/ | grep "2019" | wc -l
3
~# ls -lh /var/cache/apt/archives/ | grep "2018" | wc -l
1
~# ls -lh /var/cache/apt/archives/ | grep "2017" | wc -l
1
~# ls -lh /var/cache/apt/archives/ | grep "2016" | wc -l
0


This is very strange.
One of the reasons, I put my query out there.


Anyway again a big thanks to you & anybody else who can chime in.
 
Thank you for providing this nice rabbit hole of today. I can reproduce a usecase in which the files stay.

I want to upgrade my box without having PVE repositories enabled and it works until it breaks with the predicted error:

Code:
Get:132 https://mirror/debian bookworm/main amd64 uidmap amd64 1:4.13+dfsg1-1+deb12u1 [189 kB]
Get:133 https://mirror/debian bookworm/main amd64 xsltproc amd64 1.1.35-1+deb12u1 [114 kB]
Fetched 155 MB in 1s (116 MB/s)
W: (pve-apt-hook) !! WARNING !!
W: (pve-apt-hook) You are attempting to remove the meta-package 'proxmox-ve'!

Fixing this and rerunning the dist-upgrade will update everything and also delete the additional downloaded packages, yet in the end the 133 packages previously downloaded will not be removed and stay here:

Code:
/var/cache/apt/archives $ ls -l | grep deb -c
133

Perfect.