Wednesday 13 March 2013

Remove unused kernels and headers from ubuntu server

Yet again I found my system clogged up with unused kernels and headers. This time I am making a note of the one-liner to remove the unused junk.

(Found at http://tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/)

You can first check that the correct packages are selected to remove with;

 dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get --dry-run remove 

and if you are happy remove those with this;

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge


A word of warning, if you have installed a new kernel recently ensure you have rebooted since, and secondly ensure that your current kernel is not on the list of packages to remove of you will end up with a un-bootable system.

eth0 naming persistance

I needed to change the physical hardware for an instance of Ubuntu Server 12.04 after some hardware failed, although most of the hardware changes were seamless the network adapter name changed from eth0 to eth1, the fix for which I found here.

http://www.serenux.com/2009/11/howto-fix-a-missing-eth0-adapter-after-moving-ubuntu-server-from-one-box-to-another/

Essentially the udev rule found at

/etc/udev/rules.d/70-persistent-net.rules


Stores and makes persistent the names of the respective adapters.  By removing the line relating the that adapter is identified by such as

ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="00:a0:c9:78:9a:bc", NAME="eth0"




Subsequently the new adapter is then initialised with the name eth0.