All of lore.kernel.org
 help / color / mirror / Atom feed
* kernel pruning script..
@ 2016-02-08 20:14 Linus Torvalds
  2016-02-08 20:22 ` J. Bruce Fields
  2016-02-10 21:05 ` David Rientjes
  0 siblings, 2 replies; 4+ messages in thread
From: Linus Torvalds @ 2016-02-08 20:14 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Linux Kernel

I'm replying to a really old email, because I - once again - installed
this silly script that you wrote several years ago on a new machine.

So Bruce - how about we add this script to the kernel "tools"
directory, because it's actually very useful for anybody who uses
CONFIG_LOCALVERSION_AUTO like I do (and clearly you at least used to
do too).

I think CONFIG_LOCALVERSION_AUTO is really nice for various reasons
(not the least of which is just doing thing like

    gitk $(uname -r)..

but also because it makes it easy to go back to previous kernels when
you're working on bisecting stuff etc).

I'll happily commit it as "tools/prune-kernel" or similar, but would
like to get an ok from you as the original author.

And if somebody has improvements for specific distros, maybe the
script will start getting improvements. And I won't have to copy it
from an old machine every time, because it will just be there with the
kernel source tree (and without a kernel source tree it's not needed).

                 Linus

On Wed, Jul 10, 2013 at 1:54 PM, J. Bruce Fields <bfields@fieldses.org> 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
> '

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kernel pruning script..
  2016-02-08 20:14 kernel pruning script Linus Torvalds
@ 2016-02-08 20:22 ` J. Bruce Fields
  2016-02-10 21:05 ` David Rientjes
  1 sibling, 0 replies; 4+ messages in thread
From: J. Bruce Fields @ 2016-02-08 20:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Linux Kernel

On Mon, Feb 08, 2016 at 12:14:23PM -0800, Linus Torvalds wrote:
> I'm replying to a really old email, because I - once again - installed
> this silly script that you wrote several years ago on a new machine.
> 
> So Bruce - how about we add this script to the kernel "tools"
> directory, because it's actually very useful for anybody who uses
> CONFIG_LOCALVERSION_AUTO like I do (and clearly you at least used to
> do too).
> 
> I think CONFIG_LOCALVERSION_AUTO is really nice for various reasons
> (not the least of which is just doing thing like
> 
>     gitk $(uname -r)..
> but also because it makes it easy to go back to previous kernels when
> you're working on bisecting stuff etc).

Yes, I'm a fan.  My test scripts check uname after boot to make sure
they're testing the kernel they built.

> I'll happily commit it as "tools/prune-kernel" or similar, but would
> like to get an ok from you as the original author.

Oh, feel free, thanks.

--b.

> And if somebody has improvements for specific distros, maybe the
> script will start getting improvements. And I won't have to copy it
> from an old machine every time, because it will just be there with the
> kernel source tree (and without a kernel source tree it's not needed).
> 
>                  Linus
> 
> On Wed, Jul 10, 2013 at 1:54 PM, J. Bruce Fields <bfields@fieldses.org> 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
> > '

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kernel pruning script..
  2016-02-08 20:14 kernel pruning script Linus Torvalds
  2016-02-08 20:22 ` J. Bruce Fields
@ 2016-02-10 21:05 ` David Rientjes
  2016-02-10 21:51   ` Linus Torvalds
  1 sibling, 1 reply; 4+ messages in thread
From: David Rientjes @ 2016-02-10 21:05 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: J. Bruce Fields, Linux Kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kernel pruning script..
  2016-02-10 21:05 ` David Rientjes
@ 2016-02-10 21:51   ` Linus Torvalds
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2016-02-10 21:51 UTC (permalink / raw)
  To: David Rientjes; +Cc: J. Bruce Fields, Linux Kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-10 21:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08 20:14 kernel pruning script Linus Torvalds
2016-02-08 20:22 ` J. Bruce Fields
2016-02-10 21:05 ` David Rientjes
2016-02-10 21:51   ` Linus Torvalds

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.