Thank you for visiting!
My little window on internet allowing me to share several of my passions
Categories:
- OpenBSD
- High Availability
- vdcron
- My Sysupgrade
- FreeBSD
- Nas
- DragonflyBSD
- fapws
- Alpine Linux
- Openbox
- Desktop
- Security
- nvim
- yabitrot
- nmctl
- Tint2
- Firewall
- VPN
- Project Management
- Hifi
- Alarm
Most Popular Articles:
Last Articles:
After +5 years, I propose a method to clean up my OpenBSD laptop
Posted on 2023-02-12 15:03:00 from Vincent in OpenBSD
After several years of doing upgrades, I discovered lot of unused files on my different system's folders: /usr/X11R6, /usr/lib, ...
What is really nice with OpenBSD is that "system" is totally separated from the user space.
In this blog I will present my method to clean up the "system" part, including firmware.
Context
Thanks to the update process provided by OpenBSD, we can easily update our system every 6 months. Wth my slightly updated version of sysupgrade.sh you can even avoid to have files from all provided sets. Indeed, my sysupgrade do not install sets you do not want.
By checking files on /usr/X11R6 I have lot of files from 2019 and 2020. Having files of that date is always possible, but I have more that 1200 :(.
This post will show how I get rid of those old files without compromising the machine.
Obviously, doing a full clean up and fresh install will better do the job, but I do not want to go to such drastic scenario. This requires to backup/dump you home filesystem, to backup /etc, ...
I present a more simple method by looking for "old" files and remove them carefully.
Method
My method will simply make a delta between files present on my drive and files present in sets (tgz files provided by OpenBSD here )
Get all files present in all installed sets
You have to know which sets are installed on your machine. If like me you use my tuned sysupgrade, you can see it in /etc/sysupgrade_sets.
For this specific task, I will store all my working file in /home/check
mkdir /home/check
cd /home/check
Then I download all required sets and I extract their content in specific files
By putting all together, here the file we could call "get_sets.sh":
!/bin/sh
VERSION=72
FTPSRC=https://cdn.openbsd.org/pub/OpenBSD/7.2/arm64/
for set in base comp man xbase xfont xserv xshare
do
echo $set
ftp $FTPSRC$set$VERSION.tgz
tar -tzvf "$set$VERSION.tgz" > $set.txt
done
Please adapt the list of sets, in this script I do not install gamexx.tgz.
And adapt the version of OpenBSD you have on your system in both variable VERSION and FTPSRC.
At the moment of writing this blog, I have OpenBSD 7.2 installed.
Browsing the different folders
The next step will be to browse your system, folder per folder, and check if the file is present or not not in the sets.
But we do need to browse only system's files. So, several folders must be skipped. This is what does the following script.
To check if a file is not present in the sets, We have the following script. Let's call it is_not_in_tgz.sh:
#!/bin/sh
case "$1" in
/usr/local/*);;
/altroot/*);;
/dev/*);;
/efi/*);;
/home/*);;
/mnt/*);;
/net/*);;
/root/*);;
/sys/*);;
/tmp/*);;
/extra/*);;
*)
grep -q "\.$1" *.txt
if [ "$?" != "0" ]
then
echo "$1"
fi
;;
esac
Except "/extra", which is very special in my case, I think that the other folders must stay listed for a "normal" install of OpenBSD. That way we will only check files present in the "system" space of OpenBSD.
Do not forget to chmod this script:
chmod +x is_not_in_tgz.sh
Finally, we will trigger this check for all system files like this. Let's call this script scan.sh
#!/bin/sh
find /bin -type f -exec ./is_not_in_tgz.sh {} \;
find /sbin -type f -exec ./is_not_in_tgz.sh {} \;
find /usr -type f -exec ./is_not_in_tgz.sh {} \;
I do not think that we have to investigate more than those 3 folders.
Anyhow, you could do a full scan in "/", since we have put exclusions in our is_not_in_tgz.sh script, but, I think we can avoid it.
We are ready to perform the big scan. So let's do it like this:
sh scan.sh > scan_out
This generate a big list of files candidate to remove.
I first check their last modification date by doing:
sed 's/^/ls -al /' scan_out > scan_out_ls
sh scan_out_ls
Then, after removing few lines from scan_out I was not sure, I did:
sed 's/^/rm /' scan_out > scan_out_rm
sh scan_out_rm
In my case, I've removed 4895 files ;)
Cleaning firmwares
The last aspect could be to cleanup all firmware installed.
Normally fw_update manage it correctly for you. But let's force it ;)
First, plug your machine with an internet cable in (Wifi will be lost).
And leave X screens to come back to console mode.
It's better to reboot your machine, so you will have a fresh dmesg. this is where fw_update is looking for drivers.
fw_upfate -da
This will delete all installed firmware.
You can check it by doing:
pkg_info -a | grep firmware
You can also check in /etc/firmware. In both cases, you should not see any of files.
This is where you need internet access without firmware !!!
Now, you can re-install required firmware for your machine:
fw_update -vvvv
The -vvvv will allow you to see all what fw_update will do.
You will see what he will download and installing what he will install (in /etc/firmware)
Conclusion
After several years, you accumulate few files here and there.
Except some disk's space this should not annoy OpenBSD to run correctly.
But like dust on your shelve, this is better without it ;)