PDA

View Full Version : [SOLVED] Removing old kernels



zkab
March 12th, 2015, 11:29 AM
I used a script from a Linux article to remove old Linux kernels from my systems.

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

But I get an error - E: Can not write log (Is stdout a terminal?) - tcgetattr (25: Inappropriate ioctl for device)
Also the directory with the old modules is not removed - /lib/modules/3.19.0-7-generic not empty

How can that be fixed - I am not so familiar with 'sed'

dino99
March 12th, 2015, 11:33 AM
why dont you use a simple cron job doing 'sudo apt-get autoremove' ?
or if you only wants the oldest been removed, but the more recent still been installed, then 'sudo apt-get purge 'linux-image-3.xx' where you set the xx to the real numbers to remove, and do the same for 'linux-image-extra-...' and the related 'headers'

zkab
March 12th, 2015, 12:47 PM
I want some script that automatically removes all kernel packages (except the current one) and deletes all related files on disk.

slickymaster
March 12th, 2015, 12:49 PM
I want some script that automatically removes all kernel packages (except the current one) and deletes all related files on disk.
See this thread: http://ubuntuforums.org/showthread.php?t=1961409

zkab
March 12th, 2015, 01:36 PM
OK - so if I want to keep the current kernel & one kernel before I should run:
sudo apt-get purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | head -n -1) --assume-yes
acording to http://ubuntuforums.org/showthread.php?t=1961409 or ...

slickymaster
March 12th, 2015, 01:47 PM
Yes.

zkab
March 12th, 2015, 02:17 PM
Thanks