clean out old kernel versions?

Colin Law clanlaw at gmail.com
Sun Mar 7 17:16:57 UTC 2021


On Sun, 7 Mar 2021 at 17:13, Colin Law <clanlaw at gmail.com> wrote:
>
> On Sun, 7 Mar 2021 at 17:05, Dave Stevens <geek at uniserve.com> wrote:
> >
> >  $ sudo apt autoremove
> > [sudo] password for user:
> > Reading package lists... Done
> > Building dependency tree
> > Reading state information... Done
> > 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
> > user at user-Satellite-A100 /boot $
> >
> >  /boot $ ls -l | wc
> >     440    3953   31232
> > user at user-Satellite-A100 /boot $
>
> In that case presumably apt doesn't know about them.  This is a script
> that I used a little time ago when I got into a similar situation.
> Apparently, if you call it with -s it will do a simulation so you can
> check what is going to happen.  You might want to be even more
> cautious and replace the last line with an echo command initially just
> to make sure it looks ok.
>
> #!/bin/sh
> # removes all except latest and current running kernels
> # call with -s to simulate
>
> ( \
> KERNEL_HIGHEST=$(dpkg -l 'linux-image-[0-9.]*-[0-9]*-[a-zA-Z0-9]*' |
> grep ^ii | awk '{print $2}' | sort -V | tail -n 1 | sed
> 's/^linux-image-\([0-9.]*-[0-9]*\)-.*$/\1/') ; \
> KERNEL_CURRENT=$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/") ; \
> sudo apt-get purge $1 $(dpkg -l 'linux-*-[0-9-]*' | grep ^ii | awk
> '{print $2}' | sed "/$KERNEL_CURRENT/d;/$KERNEL_HIGHEST/d" ) ; \
> )
>

To clarify where the line breaks are, they are after each backslash so
the lines between the parenthesis lines start with KERNAL_HIGHEST,
KERNEL_CURRENT, and sudo.

Colin




More information about the ubuntu-users mailing list