-1

By uninstalling a package, we expect that there will be more free disk space. However, "sudo apt purge PACKAGE" actually decreases the free disk space. It seems that "apt purge" creates more garbage than it deletes anything. (Edit: This problem occurs only on LiveOS but not on an installed OS. It was later found that this weird phenomenon comes from the unavoidable nature of LiveOS and that apt itself is innocent.)

In the following demonstrative experiment, "apt purge" performed uninstallation of Firefox, followed by uninstallation of ffmpeg. Before and after each "apt purge", the used space and the free space (available space) of the disk were examined by "df -h /".

Before the first "apt purge", "df -h /" showed the following. G and M printed by df mean GiB and MiB respectively if -h is present.

Size  Used Avail Use%
1.9G   60M  1.8G   4%

Then, Firefox was to be uninstalled by "sudo apt purge firefox", which printed the following message.

After this operation, 220 MB disk space will be freed.
Do you want to continue? [Y/n]

Y was entered, and the uninstallation was executed.

Then, "df -h /" showed the following.

Size  Used Avail Use%
1.9G  141M  1.7G   8%

Thus, the used space increased by 81 MiB (bc <<< '141-60'), even though it was supposed to decrease by 220 MB.

Next, following the uninstallation of Firefox, ffmpeg was to be uninstalled by "sudo apt purge ffmpeg", which printed the following message.

After this operation, 2058 kB disk space will be freed.
Do you want to continue? [Y/n]

So, 2 MB was supposed to be freed. Y was entered, and the uninstallation was executed.

Then, "df -h /" showed the following.

Size  Used Avail Use% Mounted on
1.9G  230M  1.6G  13% /

Thus, the used space increased by 89 MiB (bc <<< '230-141'), even though it was supposed to decrease by 2 MB.

Question 1: Why does the uninstallation by "apt purge" increase the used disk space?

Question 2: I am not even sure whether "apt purge" ever deletes anything. I wonder if "apt purge" only moves the package out of the system to a temporary space so that apt can undo the uninstallation later. If that is the case, exactly in which directory is the uninstalled package staying? I want to delete it. Even if shutting down or restarting the machine automatically deletes it, I want to delete it without shutting down or restarting the machine.

Question 3: "apt purge" seems to create big garbage on the disk. Where is the garbage? I want to delete it. Even if shutting down or restarting the machine automatically deletes it, I want to delete it without shutting down or restarting the machine.

My Ubuntu is Ubuntu MATE 20.04.3 Live. It is a Live OS. I am using Ubuntu from the Ubuntu installation media (read-only) without installing the Ubuntu to HDD. Both Firefox and ffmpeg came with Ubuntu MATE 20.04.3 by default. I ran the above experiment immediately after the booting of Ubuntu Live completed.

-- update --

The purpose of this question is to solve this problem on the Live OS. I like Live OSs better than real OSs installed on rw file systems. If "apt purge" works differently depending on whether a Live OS or an installed OS, and if this problem does not exist on the installed OS, it does not solve my situation at all. I would like to know why this problem exists on the Live OS. The Live OS is part of my question.

-- update --

The following comment by Thomas Ward cleared all the mystery that I could not figure out regarding this problem when running on LiveOS.

The difference is stored in memory as a differing file, so you lose space the larger you change the system between the live OS image and your current state.

Especially the clause "The difference is stored in memory as a differing file" is the most helpful infomation. Without this comment by Thomas Ward, the answer by Nmath did not convince me.

I guess that the "memory" refers to the RAM disk of which "df -h /" reports about the used space and the free space.

UB89BVHZG
  • 117
  • 3
    Repeat your experiment using a real OS installed on a rw file system, and then we may talk. – vanadium May 19 '22 at 16:40
  • 3
    The expected behavior will never be replicated on the Live OS. The Live OS is fixed to a specific disk image, and you can't edit that image (it's a read only OS). The difference is stored in memory as a differing file, so you lose space the larger you change the system between the live OS image and your current state. See the answers. – Thomas Ward May 19 '22 at 17:52
  • Read this answer for why deleting app in Live USB reduces persistent disk space. – user68186 May 20 '22 at 21:06
  • You cannot uninstall packages in a read only file system. – HomerSimpson May 22 '22 at 13:49

1 Answers1

10

"It is a Live OS"

This is the reason.

A live session is based on a read-only file system. Any changes you make during the live session are written in addition to this read only file system.

So if you delete an application, you don't actually delete any of the application files, but more data has to be written to accommodate for the changes you have made.

Nmath
  • 12,333