Remove old kernels automatically

Chris cpollock at embarqmail.com
Wed Oct 29 12:58:42 UTC 2014


On Tue, 2014-10-14 at 14:50 +0300, Marius Gedminas wrote:
> On Mon, Oct 13, 2014 at 12:59:57PM +0000, Andrew Langhorn wrote:
> > Using sed, uname and apt, I am trying to ensure that all kernels older
> > than the current and one behind are uninstalled from my machines. I
> > keep the current one, for obvious reasons, and the previous kernel in
> > case I need to roll back.
> > 
> > To do this, I'm using 
> > `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`,
> > which pipes the output of `uname -r ` to sed, ignores any lines
> > beginning with `ii` to ensure installed kernels aren't removed, and
> > applies that to the ouput of `dpkg -l 'linux-*`.
> > 
> > This ensures that all previous kernels present are removed.
> > 
> > Can I blacklist the previous one, given that I don't know the name, as
> > it may well change?
> 
> You could readlink /vmlinuz.old and scrape the version number from
> there.
> 
> I suggest doing the same for /vmlinuz, since the currently running
> kernel is not necessarily the *latest* kernel, e.g. if you haven't
> rebooted yet.
> 
> BTW in recent Ubuntu versions old kernel packages are marked as
> autoremovable so you can get rid of them by doing `sudo apt-get
> autoremove` every now and then.
> 
> Marius Gedminas

Marius, thought I'd give autoremove a try. I see a lot of other items
being removed in the list below but no kernel packages unless I'm not
reading correctly. This is 14.04.1 LTS

The following packages will be REMOVED:
  alacarte argyll browser-plugin-gnash caribou caribou-antler
dconf-editor
  dconf-tools finger fonts-cantarell freepats gdebi gdebi-core gdm
  gir1.2-gconf-2.0 gir1.2-gtop-2.0 gir1.2-panelapplet-4.0
gir1.2-rest-0.7
  gir1.2-tracker-1.0 gir1.2-zpj-0.0 gksu gnash gnash-common
gnome-applets
  gnome-applets-data gnome-backgrounds gnome-color-manager
gnome-dictionary
  gnome-documents gnome-games gnome-icon-theme-extras gnome-media
  gnome-nettool gnome-online-accounts gnome-online-miners
gnome-packagekit
  gnome-packagekit-data gnome-packagekit-session gnome-panel
gnome-panel-data
  gnome-shell-extensions gnome-tweak-tool gstreamer0.10-gconf
  gstreamer0.10-plugins-bad gtk2-engines hamster-applet
hamster-indicator
  inkscape libass4 libavresample1 libbonoboui2-0 libbonoboui2-common
  libboost-iostreams1.54.0 libboost-program-options1.54.0
  libboost-thread1.54.0 libcaribou-gtk-module libcaribou-gtk3-module
  libcdaudio1 libdc1394-22 libdca0 libdirac-encoder0 libdirectfb-1.2-9
  libdiscid0 libenca0 libfaad2 libflite1 libgdict-1.0-6 libgdict-common
  libgfbgraph-0.2-0 libgksu2-0 libgme0 libgnome-media-profiles-3.0-0
  libgnomecanvas2-0 libgnomecanvas2-common libgnomeui-0
libgnomeui-common
  libgsl0ldbl libgstreamer-plugins-bad0.10-0 libgtkmm-2.4-1c2a
  libgupnp-dlna-2.0-3 libicc2 libimdi0 libjemalloc1 libkate1 libmagick
++5
  libmimic0 libmms0 libmodplug1 libmpcdec6 libofa0 libopenal-data
libopenal1
  librygel-core-2.2-2 librygel-renderer-2.2-2
librygel-renderer-gst-2.2-2
  librygel-server-2.2-2 libslv2-9 libsofia-sip-ua-glib3 libsofia-sip-ua0
  libsoundtouch0 libspandsp2 libswscale2 libts-0.0-0 libvo-aacenc0
  libvo-amrwbenc0 libwildmidi-config libwildmidi1 libzapojit-0.0-0
libzbar0
  libzvbi-common libzvbi0 perlmagick python-gnome2 python-numpy
python-pyatspi
  python-pyorbit python-wnck realmd rygel rygel-playbin
rygel-preferences
  sound-juicer telepathy-rakia tsconf unoconv
0 upgraded, 0 newly installed, 124 to remove and 10 not upgraded.
After this operation, 287 MB disk space will be freed.

-- 
Chris
KeyID 0xE372A7DA98E6705C
31.11°N 97.89°W (Elev. 1092 ft)
07:55:44 up 7 min, 2 users, load average: 0.05, 0.52, 0.39
Ubuntu 14.04.1 LTS, kernel 3.13.0-39-generic





More information about the ubuntu-users mailing list