All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhaskar Chowdhury <unixbhaskar@gmail.com>
To: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Randy Dunlap <rdunlap@infradead.org>,
	yamada.masahiro@socionext.com, michal.lkml@markovi.net,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system
Date: Tue, 5 Nov 2019 10:22:42 +0530	[thread overview]
Message-ID: <20191105045239.GC27350@Gentoo> (raw)
In-Reply-To: <20191105043918.GB27350@Gentoo>

[-- Attachment #1: Type: text/plain, Size: 6218 bytes --]

On 10:09 Tue 05 Nov 2019, Bhaskar Chowdhury wrote:
>On 21:32 Mon 04 Nov 2019, J. Bruce Fields wrote:
>>On Mon, Nov 04, 2019 at 06:03:13PM -0800, Randy Dunlap wrote:
>>> On 11/1/19 11:30 PM, Bhaskar Chowdhury wrote:
>>> > This patch allow you to remove old kernels and associated modules
>>> > directory from the system.You can do it at once with the -r flag
>>> > and interactively with the -i flag.
>>> > 
>>> > Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
>>> > ---
>>> >  scripts/prune-kernel | 82 +++++++++++++++++++++++++++++++++++---------
>>> >  1 file changed, 65 insertions(+), 17 deletions(-)
>>> 
>>> Hi,
>>> I believe that this script now does what the patch author intends it to do.
>>> It does have a few whitespace issues, but no big deals.  (see below)
>>
>>My original comment stands: looks like it prompts for full module path
>>and kernel versions which means it's no more convenient than just doing
>>an "ls" and then removing the ones you want to.  (In fact, with "rm"
>>you'd also get the benefit of tab completion....)

Bruce,

There is -r or --remove option , with that you can pass the kernel
version and modules directory name , and the script will remove those
without prompting you for those.

For instance you need to pass the options like this :

./scripts/prune-kernel -r kernel_version modules_directory_name
OR
./scripts/prune-kernel --remove kernel_version modules_directory_name

Which I certainly believe is not just "ls and rm" stuff...could you
please give it a shot ,and let me know the shortcoming please??

So , I can fix the damn thing.
>
>Hi Bruce,
>I am forcing user to put full modules directory name,kinda engagement 
>to the process.It is not a trivial operation, so the users should be 
>aware.
>OHT Could you please state what else you would like to be inducted in
>the so it can be useful?? So sorry for my weak memory if you already 
>explicitly stated something like that before.
>
>Thanks,
>Bhaskar
>>
>>It's quite different from the original script and I don't really see the
>>advantage.
>>
>>--b.
>>
>>> 
>>> Tested-by: Randy Dunlap <rdunlap@infradead.org>
>>> 
>>> 
>>> > diff --git a/scripts/prune-kernel b/scripts/prune-kernel
>>> > index e8aa940bc0a9..01d0778db71f 100755
>>> > --- a/scripts/prune-kernel
>>> > +++ b/scripts/prune-kernel
>>> > @@ -1,21 +1,69 @@
>>> >  #!/bin/bash
>>> >  # SPDX-License-Identifier: GPL-2.0
>>> > +#This script will remove old kernels and modules directory related to it.
>>> > +#"-r" or "--remove" show how to silently remove old kernel and modules dir.
>>> > +# "-h" or "--help" show how to use this script or show without parameter.
>>> > +#"-i" or "--interactive" show how to remove interactively.
>>> > +
>>> > +flag=$1
>>> > +kernel_version=$2
>>> > +modules_version=$3
>>> > +boot_dir=/boot
>>> > +modules_dir=/lib/modules
>>> > +
>>> > +remove_old_kernel() {
>>> > +	cd $boot_dir
>>> > +	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_version
>>> > +	return 0
>>> > +}
>>> > +
>>> > +remove_old_modules_dir() {
>>> > +	cd $modules_dir
>>> > +	rm -rf $modules_version
>>> > +	return 0
>>> > +}
>>> > +
>>> > +usage() {
>>> > +	printf "Usage: $(basename $0) [-ri]\n"
>>> > +	printf "\n -r or --remove  kernel_version modules_version\n"
>>> > +	printf "\n -i or --interactive do as interactive way\n"
>>> > +	return 0
>>> > +}
>>> > +
>>> > +case "$flag" in
>>> > +	-i | --interactive)
>>> > +		printf "\nEnter kernel version to remove or blank/empty to exit:"
>>> > +		read kernel_version
>>> > +		if [[ $kernel_version != "" ]]; then
>>> > +			remove_old_kernel
>>> > +			printf "\nRemoved kernel version:$kernel_version from the system.\n\n"
>>> 
>>> space after ':'
>>> 
>>> drop one \n above.
>>> 
>>> > +			printf "Please give the full modules directory name to remove:"
>>> > +			read modules_version
>>> > +			if [[ $modules_version != "" ]]; then
>>> > +				remove_old_modules_dir
>>> > +				printf "\n\nRemoved modules directory:$modules_version from the system.\n\n"
>>> 
>>> space after ':'
>>> 
>>> drop one \n above.
>>> 
>>> > +			else
>>> > +				exit 1
>>> > +			fi
>>> > +		fi
>>> > +		;;
>>> > +	-h | --help)
>>> > +		usage
>>> > +		exit 0
>>> > +		;;
>>> > +	-r | --remove)
>>> > +		if [[ $# -ne 3 ]]; then
>>> > +			 printf "You need to provide kernel version and modules directory name.\n"
>>> > +			 exit 1
>>> > +		 else
>>> > +			 remove_old_kernel
>>> > +			 remove_old_modules_dir
>>> > +		fi
>>> > +		;;
>>> > +	*)
>>> > +		usage
>>> > +		exit 1
>>> > +		;;
>>> > +esac
>>> > 
>>> > -# 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:
>>> > 
>>> 
>>> OK, the former script's loop is removed.. good.
>>> But the 2 preceding blank lines are not removed, so the script
>>> now ends with 2 unnecessary blank lines.
>>> 
>>> > -for f in "$@"
>>> > -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
>>> > --
>>> 
>>> 
>>> -- 
>>> ~Randy

>-----BEGIN PGP SIGNATURE-----
>
>iQEzBAABCAAdFiEEnwF+nWawchZUPOuwsjqdtxFLKRUFAl3A/PMACgkQsjqdtxFL
>KRUyqQgAya3BYL2iEMk0N3b1/Ji3TVzjrhaMrYM1bc6MDs7UA83ikBBG7C/dSmZ9
>3l9ANXfEnjaF64FpuLTNE2pT/tVxEj+xQz5iWw3JXV9TR7P2rq6814LH4b3hXX54
>A9r0sIRz0xwCMq7ihtNtgXziyviLp8UkUjIK+1C4vQ0h9/CvP0YETq8fgRWASMrS
>2+VErRPd06DryAAnapz9CnZz2Fju6S4mA2aaTJ3hiDLNmbj++6IoNQw+r5MZrWde
>yUqPQcfAzxs6/GIuUPK3uStudgofQjCKbHbPho9jjmwXrNSFH6/0/pjz5R91oMu9
>AWpkl0vkvAvzLsjRIeMG/MmClx0c3w==
>=VReA
>-----END PGP SIGNATURE-----

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-11-05  4:52 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-02  6:30 [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system Bhaskar Chowdhury
2019-11-05  2:03 ` Randy Dunlap
2019-11-05  2:32   ` J. Bruce Fields
2019-11-05  4:39     ` Bhaskar Chowdhury
2019-11-05  4:52       ` Bhaskar Chowdhury [this message]
2019-11-06  2:53     ` Masahiro Yamada
2019-11-06  3:10       ` Bhaskar Chowdhury
2019-11-06  4:03         ` Masahiro Yamada
2019-11-06  4:29           ` Bhaskar Chowdhury
2019-11-06  4:31       ` J. Bruce Fields
2019-11-06  4:32         ` Randy Dunlap
2019-11-06  4:42         ` Bhaskar Chowdhury
2019-11-06 19:30           ` J. Bruce Fields
2019-11-06 22:39             ` Bhaskar Chowdhury
2019-11-09  7:25               ` Masahiro Yamada
2019-11-09 11:13                 ` Bhaskar Chowdhury
2019-11-15  1:58                   ` Masahiro Yamada
2019-11-15 15:21                     ` Bhaskar Chowdhury
2019-11-18  7:30                       ` Masahiro Yamada
2019-11-05  4:33   ` Bhaskar Chowdhury
  -- strict thread matches above, loose matches on Subject: below --
2019-10-30  9:54 [PATCH] scripts: prune-kernel:remove " Bhaskar Chowdhury
2019-10-31  2:33 ` Randy Dunlap
2019-10-31  3:37   ` Bhaskar Chowdhury
2019-10-31  4:32     ` Randy Dunlap
2019-10-31  4:52       ` Bhaskar Chowdhury
2019-10-31  5:27         ` Randy Dunlap
2019-10-31  7:18           ` Bhaskar Chowdhury
2019-10-31 15:06             ` Randy Dunlap
2019-11-01  4:23               ` Bhaskar Chowdhury
2019-11-01  5:11                 ` Bhaskar Chowdhury
2019-11-01  5:45                   ` Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191105045239.GC27350@Gentoo \
    --to=unixbhaskar@gmail.com \
    --cc=bfields@fieldses.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=rdunlap@infradead.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.