Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1331487 > unrolled thread

Re: kernel pruning script..

Started byDavid Rientjes <rientjes@google.com>
First post2016-02-10 22:10 +0100
Last post2016-02-10 23:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: kernel pruning script.. David Rientjes <rientjes@google.com> - 2016-02-10 22:10 +0100
    Re: kernel pruning script.. Linus Torvalds <torvalds@linux-foundation.org> - 2016-02-10 23:00 +0100

#1331487 — Re: kernel pruning script..

FromDavid Rientjes <rientjes@google.com>
Date2016-02-10 22:10 +0100
SubjectRe: kernel pruning script..
Message-ID<r0Kbo-7zi-9@gated-at.bofh.it>
On Mon, 8 Feb 2016, Linus Torvalds wrote:

> > I run this by hand every now and then.  I'm probably doing it all wrong.
> >
> > --b.
> >
> > #!/bin/bash
> >
> > # because I use CONFIG_LOCALVERSION_AUTO, not the same version again and
> > # again, /boot and /lib/modules/ eventually fill up.
> > # Dumb script to purge that stuff:
> >
> > ssh "root@$1" '
> >
> > for f in $(ls /lib/modules); do
> >         if rpm -qf "/lib/modules/$f" >/dev/null; then
> >                 echo "keeping $f (installed from rpm)"
> >         elif [ $(uname -r) = "$f" ]; then
> >                 echo "keeping $f (running kernel) "
> >         else
> >                 echo "removing $f"
> >                 rm -f "/boot/initramfs-$f.img" "/boot/System.map-$f"
> >                 rm -f "/boot/vmlinuz-$f"   "/boot/config-$f"
> >                 rm -rf "/lib/modules/$f"
> >                 new-kernel-pkg --remove $f
> >         fi
> > done
> > '

I do something similar to this on a regular basis as well, but I also rm 
-rf /lib/firmware/$f

[toc] | [next] | [standalone]


#1331530

FromLinus Torvalds <torvalds@linux-foundation.org>
Date2016-02-10 23:00 +0100
Message-ID<r0KXM-7U9-9@gated-at.bofh.it>
In reply to#1331487
On Wed, Feb 10, 2016 at 1:05 PM, David Rientjes <rientjes@google.com> wrote:

>> > for f in $(ls /lib/modules); do
>> >         if rpm -qf "/lib/modules/$f" >/dev/null; then
>> >                 echo "keeping $f (installed from rpm)"
>> >         elif [ $(uname -r) = "$f" ]; then
>> >                 echo "keeping $f (running kernel) "
>> >         else
>> >                 echo "removing $f"
>> >                 rm -f "/boot/initramfs-$f.img" "/boot/System.map-$f"
>> >                 rm -f "/boot/vmlinuz-$f"   "/boot/config-$f"
>> >                 rm -rf "/lib/modules/$f"
>> >                 new-kernel-pkg --remove $f
>> >         fi
>> > done
>> > '
>
> I do something similar to this on a regular basis as well, but I also rm
> -rf /lib/firmware/$f

So I don't think most people do that. I know I don't. I think it comes
into play mainly if you do the packaged kernel thing (ie the
"builddeb" rule or the rpmbuild), and in that case you should never
remove the files manually anyway.

The normal firmware_install just puts things into /lib/firmware,
because the firmware files are supposed to be versioned on their own,
not by kernel version.

So I don't think that's a thing we want to add in general. However, I
*would* want to add sanity checks for deb-based things, right now we
just have that

   if rpm -qf "/lib/modules/$f" >/dev/null; then
        echo "keeping $f (installed from rpm)"

and we'd need something similar for a debian package.

Also note that what I have actually been using - and what I committed
- wasn't really the quoted original script from Bruce. I end up
pruning individual kernels by name (rather than pruning everything in
/lib/modules).

Finally, note that I removed the "ssh root@$1" model that Bruce had -
his script really makes more sense in his situation where he does this
to his target test machines, but I don't think that's the proper model
for a script like this in the general case.

So to get the behavior that Bruce's script had, you'd actually do

   ssh root@target 'cd /lib/modules && prune-kernel *'

with the thing I committed.

So the script that is committed (it's in current -git as
"scripts/prune-kernel") is slightly different from this emailed
thread, but I'd be more than happy to take patches for it. I've used
my edited version for a long while (pretty much since Bruce posted
it), but it's a complete hack. I think it started out as a hack, and I
hacked it up (or down, depending on your situation) some more, and
while the largest reason for me to commit it was just to not have to
look it up every time I do a new machine install, I'm also hoping that
now that it's in the kernel tree, maybe people will say ".. but I'm
running Ubuntu, and that rpm test does nothing for me, so it should
add a line to do X".

But I still think that your firmware thing implies that you're using a
packaged kernel, and that you shouldn't be removing subdirectories by
hand.

           Linus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web