Pages

Friday, March 7, 2014

Cleaning out linux-image-x.x.xx-xx-* files

I was suddenly denied access to my in-house web-server with a message telling me the disk is full. After a quick check with df -h I could confirm the root partition used 100%.
First I started to look for "user -files" I could remove, but found out there wasn't all that many of them. Most of the usage was in the folders /lib, /usr and /var. A quick question to my friend google took me in the direction that there could be some linux-image files no longer used that were spending my disk.
Some more searching gave me the following solution to removing these unused kernel files:

sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge


This worked like a charm and got rid of some Gigs no longer used.

To further clean up my system, I also checked which packages was removed from my system, but still was keeping configuration files with this command:


sudo dpkg --list |grep "^rc" | cut -d " " -f 3


I got quite a long list of packages wasting space.
So to remove these configuration files and clean up the list of installed packages I purged the list of packages and their configuration files with this command:


sudo dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge

It cleared some more space on my servers and laptops.

No comments:

Post a Comment