Cleaning my Archlinux

9. July 2023 @ Frankfurt am Main, Deutschland

I installed Blackarch when I first set up my Archlinux system and have been using it for years. However, having Blackarch alongside the host system sometimes disrupts the rolling updates of the system. This can result in package name conflicts, duplicates, packages which are in my system but not in any of the mirrors, or packages that are not compatible with the system. Additionally, Blackarch includes many Python 2 packages, which have been deprecated. Each system update includes all the changing packages, even though I only use a few of them, which prolongs the update process. Overall, I am very satisfied with this distribution, but I recently discovered that using it as my daily driver may not be the best idea.

The commands in this post can be dangerous. Review before executing them

Uninstall Blackarch

To fully remove the Blackarch install, the command from here: https://unix.stackexchange.com/questions/532455/removing-blackarch-completely-from-system is not enough. This works fine when you abandon the thoughts of using Blackarch right after you installed it. But let’s first do this:

paclist blackarch | cut -d' ' -f1 | xargs sudo pacman -R

(add --noconfirm to actually execute)

However, this even doesn’t work in my case. The dependencies of the packages are messed up during previous updates. Some packages in Archlinux mirror find the packages from Blackarch necessary somehow.

I tried to find out what are the packages I need and end up manually selected packages from pacman -Qe, and removed everything else. pacman -Qt has also interesting results and when you want to list the packages which are not optional dependencies of any other packages, use pacman -Qtt. I listed the packages I installed and commented why they are installed. This reminds me when I was a child, I tried to visual spotting suspicious processes from Windows Task Manager by familiarity. pacman supports adding package as dependency but unfortunately doesn’t support specifying dependency of which package, so there are packages installed as dependency but were later left like orphans.

When we have the list of packages, we can validate whether there is unnecessary packages installed:

pacman -Qqe | grep -x -v -F -f <(cut -d' ' -f 1 installed.txt )
pacman -Qqt | grep -x -v -F -f <(cut -d' ' -f 1 installed.txt )
pacman -Qqtt | grep -x -v -F -f <(cut -d' ' -f 1 installed.txt )

From now on, I’m going to get this package list under version control.

Please note that it’s important to exercise caution.

Clean package cache

This is the easies part, just copy the commands from Archlinux wiki: https://wiki.archlinux.org/title/Pacman#Cleaning_the_package_cache

Use these two commands to remove cache and keep 1 recent version of installed packages and 0 of uninstalled packages.

paccache -rk1
paccache -ruk0

You can also use pacman built-in cleaning tools, but this does not support keeping recent versions.

pacman -Scc # I use pikaur instead to clean AUR cache together

Clean unused files

Here comes the tough part. This reminds me the Windows system in which whene you uninstall some software, you have to go find the garbage files and delete them yourself. At first I just use pacman -Qo to check whether a file is owned by a package. The first large files I saw was the wordlists generated by wordlistctl from Blackarch. wordlistctl has been removed, but the wordlists are not. I had to delete them myself.

Later I use find to bulk check the files, e.g.:

find /usr/share -maxdepth 1 -exec pikaur -Qo {} + >/dev/null

Gradually increasing -maxdepth helps a lot.

I deleted tons of files generated by Blackarch packages, tons of python 2 site packages, and tons of early version python 3 site packages. They are all out of management. Since I plan to set up develop environment in docker in the future, I also removed tons of ghc packages and ruby gems. Terrible! They are side effects.

Finally, I saved more than 100GB from /usr and /var. Considering the impact on the life of my SSD, this is very worthy.

There are also garbage files in my home folder, but this is harder to find. I only went through my familiar places in .config and .local. I deleted around 3 GB most of which are out of date python site packages, but I don’t think I deleted most of the garbage files.

Remove unused users

Some packages create users and groups but don’t remove them when uninstalled. Unfortunately I have to manually check them and remove them as well as their home folders.

Conclusion

In the end, I freed up more than 120GB of space. I also learned a lot about the system. I will keep the package list under version control and try to keep the system clean. I will also try to use docker for development to avoid the mess in the future. I hope this post helps you to clean your system.