linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: prune-kernel : prune kernels generalized way
@ 2019-10-19 13:07 Bhaskar Chowdhury
  2019-10-19 16:01 ` J. Bruce Fields
  0 siblings, 1 reply; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-19 13:07 UTC (permalink / raw)
  To: yamada.masahiro, michal.lkml
  Cc: rdunlap, linux-kbuild, linux-kernel, bfields, Bhaskar Chowdhury

This patch will remove old kernel from the system in a selective way.

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
 scripts/prune-kernel | 86 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 72 insertions(+), 14 deletions(-)

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index e8aa940bc0a9..9d839a4e4539 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -5,17 +5,75 @@
 # again, /boot and /lib/modules/ eventually fill up.
 # Dumb script to purge that stuff:

-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
+#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
+boot_dir=/boot
+modules_dir=/lib/modules
+
+function remove_old_kernel(){
+	cd $boot_dir
+	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_version
+}
+
+function remove_old_modules_dir(){
+	cd $modules_dir
+	rm -rf $modules_version
+}
+
+printf "\n\n Enlist the installed kernels \n\n"
+
+
+find $boot_dir -name "vmlinuz-*" -type f -exec ls -1 {} \;
+
+printf "\n\n\n Please give the kernel version to remove: %s"
+read kernel_version
+
+if [[ $kernel_version == "" ]];then
+	exit 1
+else
+	remove_old_kernel
+fi
+
+printf "\n\n Enlist the installed modules directory \n\n"
+
+find $modules_dir -maxdepth 0 -type d -exec ls -1 {} \;
+
+printf "\n\n Please give the full modules directory name to remove: %s"
+read modules_version
+
+if [[ $modules_version == "" ]];then
+	printf "You have forgotten to give the modules dir to remove"
+else
+	remove_old_modules_dir
+fi
+
+printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done \n"
+
+while :
+ do
+    printf "\n\n Do you want to remove another?[YN]: %s"
+    read response
+       if [[ $response == "Y" ]];then
+	 printf "Please give another version to remove: %s"
+	 read kernel_version
+	 remove_old_kernel
+	 printf "Please give the full modules directory name to remove: %s"
+	 read modules_version
+	 remove_old_modules_dir
+	 printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ..Done \n\n"
+      elif [[ $response == "N" ]];then
+	 exit 1
+    fi
+ done
--
2.21.0


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

* Re: [PATCH] scripts: prune-kernel : prune kernels generalized way
  2019-10-19 13:07 [PATCH] scripts: prune-kernel : prune kernels generalized way Bhaskar Chowdhury
@ 2019-10-19 16:01 ` J. Bruce Fields
  2019-10-19 22:16   ` Bhaskar Chowdhury
  0 siblings, 1 reply; 9+ messages in thread
From: J. Bruce Fields @ 2019-10-19 16:01 UTC (permalink / raw)
  To: Bhaskar Chowdhury
  Cc: yamada.masahiro, michal.lkml, rdunlap, linux-kbuild, linux-kernel

On Sat, Oct 19, 2019 at 06:37:22PM +0530, Bhaskar Chowdhury wrote:
> This patch will remove old kernel from the system in a selective way.

Please don't comment out code, just delete it, git's there to keep the
old code.

There's some redundant code that should be inside a loop.

A little more detail in the changelog might be useful to those of us who
are lazy about reading bash script....

Looks like this just prompts for each individual delete?  Actually it
looks like it requires the user to enter the module path and kernel
version for each one which makes it not much more convenient use than a
bare "ls" and "rm".

I personally use this in unattended scripts.  I mean, I don't really
care what we do with this, as I use my own copy of the script, so
whatever's useful to more people is fine.

But if somebody does actually use it as-is, it'd be nicer to keep the
current behavior and add an option ("-i" or something) for the
interactive behavior.

--b.

> 
> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
> ---
>  scripts/prune-kernel | 86 ++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 72 insertions(+), 14 deletions(-)
> 
> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
> index e8aa940bc0a9..9d839a4e4539 100755
> --- a/scripts/prune-kernel
> +++ b/scripts/prune-kernel
> @@ -5,17 +5,75 @@
>  # again, /boot and /lib/modules/ eventually fill up.
>  # Dumb script to purge that stuff:
> 
> -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
> +#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
> +boot_dir=/boot
> +modules_dir=/lib/modules
> +
> +function remove_old_kernel(){
> +	cd $boot_dir
> +	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_version
> +}
> +
> +function remove_old_modules_dir(){
> +	cd $modules_dir
> +	rm -rf $modules_version
> +}
> +
> +printf "\n\n Enlist the installed kernels \n\n"
> +
> +
> +find $boot_dir -name "vmlinuz-*" -type f -exec ls -1 {} \;
> +
> +printf "\n\n\n Please give the kernel version to remove: %s"
> +read kernel_version
> +
> +if [[ $kernel_version == "" ]];then
> +	exit 1
> +else
> +	remove_old_kernel
> +fi
> +
> +printf "\n\n Enlist the installed modules directory \n\n"
> +
> +find $modules_dir -maxdepth 0 -type d -exec ls -1 {} \;
> +
> +printf "\n\n Please give the full modules directory name to remove: %s"
> +read modules_version
> +
> +if [[ $modules_version == "" ]];then
> +	printf "You have forgotten to give the modules dir to remove"
> +else
> +	remove_old_modules_dir
> +fi
> +
> +printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done \n"
> +
> +while :
> + do
> +    printf "\n\n Do you want to remove another?[YN]: %s"
> +    read response
> +       if [[ $response == "Y" ]];then
> +	 printf "Please give another version to remove: %s"
> +	 read kernel_version
> +	 remove_old_kernel
> +	 printf "Please give the full modules directory name to remove: %s"
> +	 read modules_version
> +	 remove_old_modules_dir
> +	 printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ..Done \n\n"
> +      elif [[ $response == "N" ]];then
> +	 exit 1
> +    fi
> + done
> --
> 2.21.0

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

* Re: [PATCH] scripts: prune-kernel : prune kernels generalized way
  2019-10-19 16:01 ` J. Bruce Fields
@ 2019-10-19 22:16   ` Bhaskar Chowdhury
  0 siblings, 0 replies; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-19 22:16 UTC (permalink / raw)
  To: J. Bruce Fields
  Cc: yamada.masahiro, michal.lkml, rdunlap, linux-kbuild, linux-kernel

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

On 12:01 Sat 19 Oct 2019, J. Bruce Fields wrote:
>On Sat, Oct 19, 2019 at 06:37:22PM +0530, Bhaskar Chowdhury wrote:
>> This patch will remove old kernel from the system in a selective way.
>
>Please don't comment out code, just delete it, git's there to keep the
>old code.
>
I thought it would be more appropriate to know user why it's written in
first place.So ,deleting is not a good idea!

>There's some redundant code that should be inside a loop.
I don't want to make thing unnecessary complicated. Two more line
,scripts like this, doesn't harm at all. Easy for readability.
>
>A little more detail in the changelog might be useful to those of us who
>are lazy about reading bash script....
>
More "unnecessary" words doesn't make the actual purpose of the scripts
more helpful. I believe the single line I put is good enough for the
people to capture the essence.
>Looks like this just prompts for each individual delete?  Actually it
>looks like it requires the user to enter the module path and kernel
>version for each one which makes it not much more convenient use than a
>bare "ls" and "rm".
>
No , it is not. You missed out the point. The user should be reminded
what they are upto and precisely what is needed. I don't care who the
user are. This is operation just can not be done airy-fairy way.
>I personally use this in unattended scripts.  I mean, I don't really
>care what we do with this, as I use my own copy of the script, so
>whatever's useful to more people is fine.
>
Yes, you wrote it for your convenience, and that's great. I am thinking
of putting broader user base, so the verbosity and explicitness.
>But if somebody does actually use it as-is, it'd be nicer to keep the
>current behavior and add an option ("-i" or something) for the
>interactive behavior.
Subtle thing is not my cup of tea, honestly lack of bent of mind always
prevent me to doing that kind of thing.What you mention a flag would be
great and pretty trivial . But the whole point of having this script to
be "usable" lies somewhere else.
>
>--b.
>
Bruce, I am no way trying to demean or over riding your thought and
work. Just trying to make things work for everyone else. I just took it
your good work to extend it , certainly others could have done much
better if they stab on it,including you. No, doubt about it.

Thanks,
Bhaskar
>> 
>> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
>> ---
>>  scripts/prune-kernel | 86 ++++++++++++++++++++++++++++++++++++--------
>>  1 file changed, 72 insertions(+), 14 deletions(-)
>> 
>> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
>> index e8aa940bc0a9..9d839a4e4539 100755
>> --- a/scripts/prune-kernel
>> +++ b/scripts/prune-kernel
>> @@ -5,17 +5,75 @@
>>  # again, /boot and /lib/modules/ eventually fill up.
>>  # Dumb script to purge that stuff:
>> 
>> -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
>> +#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
>> +boot_dir=/boot
>> +modules_dir=/lib/modules
>> +
>> +function remove_old_kernel(){
>> +	cd $boot_dir
>> +	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_version
>> +}
>> +
>> +function remove_old_modules_dir(){
>> +	cd $modules_dir
>> +	rm -rf $modules_version
>> +}
>> +
>> +printf "\n\n Enlist the installed kernels \n\n"
>> +
>> +
>> +find $boot_dir -name "vmlinuz-*" -type f -exec ls -1 {} \;
>> +
>> +printf "\n\n\n Please give the kernel version to remove: %s"
>> +read kernel_version
>> +
>> +if [[ $kernel_version == "" ]];then
>> +	exit 1
>> +else
>> +	remove_old_kernel
>> +fi
>> +
>> +printf "\n\n Enlist the installed modules directory \n\n"
>> +
>> +find $modules_dir -maxdepth 0 -type d -exec ls -1 {} \;
>> +
>> +printf "\n\n Please give the full modules directory name to remove: %s"
>> +read modules_version
>> +
>> +if [[ $modules_version == "" ]];then
>> +	printf "You have forgotten to give the modules dir to remove"
>> +else
>> +	remove_old_modules_dir
>> +fi
>> +
>> +printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done \n"
>> +
>> +while :
>> + do
>> +    printf "\n\n Do you want to remove another?[YN]: %s"
>> +    read response
>> +       if [[ $response == "Y" ]];then
>> +	 printf "Please give another version to remove: %s"
>> +	 read kernel_version
>> +	 remove_old_kernel
>> +	 printf "Please give the full modules directory name to remove: %s"
>> +	 read modules_version
>> +	 remove_old_modules_dir
>> +	 printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ..Done \n\n"
>> +      elif [[ $response == "N" ]];then
>> +	 exit 1
>> +    fi
>> + done
>> --
>> 2.21.0

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

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

* Re: [PATCH] scripts : prune-kernel : prune kernels generalized way
  2019-10-17 20:16 ` Randy Dunlap
@ 2019-10-17 23:00   ` Bhaskar Chowdhury
  0 siblings, 0 replies; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-17 23:00 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: yamada.masahiro, michal.lkml, bfields, linux-kbuild, linux-kernel

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

On 13:16 Thu 17 Oct 2019, Randy Dunlap wrote:
>On 10/16/19 11:31 PM, Bhaskar Chowdhury wrote:
>> This patch will remove old kernel from the system in a selective way.
>> 
>> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
>> ---
>> For Randy :
>> ✔ ~/git-linux/linux-kbuild [master|AM/REBASE ↑·8|✔]
>> 11:42 $ ./scripts/checkpatch.pl -f
>> scripts/0001-Fix-all-the-concern-raised-by-Randy.patch
>> total: 0 errors, 0 warnings, 93 lines checked
>> 
>> scripts/0001-Fix-all-the-concern-raised-by-Randy.patch has no obvious
>> style problems and is ready for submission.
>> 
>> scripts/prune-kernel | 75 ++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 75 insertions(+)
>> 
>> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
>> index e69de29bb2d1..9461ae2bc122 100755
>> --- a/scripts/prune-kernel
>> +++ b/scripts/prune-kernel
>> @@ -0,0 +1,75 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +# 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:
>> +
>> +#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
>> +boot_dir=/boot
>> +modules_dir=/lib/modules
>> +function remove_old_kernel(){
>> +	cd $boot_dir
>> +	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_verison
>
>typo/spello: not tested:                                                  ^^^^^^^^^^^^^^
>
/face palm
>> +}
>> +function remove_old_kernel_modules_dir(){
>> +	cd $modules_dir
>> +	rm -rf $modules_version
>> +}
>> +printf "\n\n Enlist the installed kernels \n\n"
>> +
>> +find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
>> +
>> +printf "\n\n\n Please give the kernel version to remove: %s"
>> +read kernel_version
>> +if [[ $kernel_version -eq "" ]];then
>> +	printf "You have forgotten the version to give for removal"
>
>No message needed IMO -- just exit.
>
I though busy user mind should be reminded what they miss, so the msg. 
>> +	exit 1
>> +else
>> +        remove_old_kernel
>> +fi
>> +
>> +printf "\n\n Enlist the installed modules directory \n\n"
>> +
>> +find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
>> +
>> +printf "\n\n Please give the full modules directory name to remove: %s"
>> +read modules_version
>> +if [[ $modules_version -eq "" ]];then
>> +	printf "You have forgotten to give the modules dir to remove"
>
>ditto.
>
Same login like above if it reaches here, which should not.
>> +else
>> +        remove_old_kernel_modules_dir
>> +fi
>> +
>> +printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
>> +while :
>> +  do
>> +     printf "\n\n Do you want to remove another?[YN] : %s"
>> +     read response
>> +
>> +       if [[ $response == "Y" ]];then
>
>Odd indentation here.  Some lines use tab, some lines use spaces.
>
Don't know how fix this bloody thing.
>> +	printf "Please give another version to remove : %s"
>> +	read kernel_version
>> +	remove_old_kernel
>> +	printf "\n\n Please give the full modules directory name to remove: %s"
>> +	read modules_version
>> +	remove_old_kernel_modules_dir
>> +        printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
>> +
>> +      elif [[ $response == "N" ]];then
>> +	   exit 1
>> +      fi
>> +  done
>> --
>> 2.21.0
>
>
>And lastly, 'patch' will apply this patch cleanly, but it ends up with
>almost all of this patch inserted into the new prune-kernel source file
>before the current contents of the prune-kernel source file,
>so I think that the emailed patch file has a problem.
>
Duh! that shit ...should have realized it before ...
>-- 
>~Randy
>
Thanks Randy for the heads up.

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

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

* Re: [PATCH] scripts : prune-kernel : prune kernels generalized way
  2019-10-17  6:31 [PATCH] scripts : " Bhaskar Chowdhury
@ 2019-10-17 20:16 ` Randy Dunlap
  2019-10-17 23:00   ` Bhaskar Chowdhury
  0 siblings, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2019-10-17 20:16 UTC (permalink / raw)
  To: Bhaskar Chowdhury, yamada.masahiro, michal.lkml
  Cc: bfields, linux-kbuild, linux-kernel

On 10/16/19 11:31 PM, Bhaskar Chowdhury wrote:
> This patch will remove old kernel from the system in a selective way.
> 
> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
> ---
> For Randy :
> ✔ ~/git-linux/linux-kbuild [master|AM/REBASE ↑·8|✔]
> 11:42 $ ./scripts/checkpatch.pl -f
> scripts/0001-Fix-all-the-concern-raised-by-Randy.patch
> total: 0 errors, 0 warnings, 93 lines checked
> 
> scripts/0001-Fix-all-the-concern-raised-by-Randy.patch has no obvious
> style problems and is ready for submission.
> 
> scripts/prune-kernel | 75 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
> 
> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
> index e69de29bb2d1..9461ae2bc122 100755
> --- a/scripts/prune-kernel
> +++ b/scripts/prune-kernel
> @@ -0,0 +1,75 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# 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:
> +
> +#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
> +boot_dir=/boot
> +modules_dir=/lib/modules
> +function remove_old_kernel(){
> +	cd $boot_dir
> +	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_verison

typo/spello: not tested:                                                  ^^^^^^^^^^^^^^

> +}
> +function remove_old_kernel_modules_dir(){
> +	cd $modules_dir
> +	rm -rf $modules_version
> +}
> +printf "\n\n Enlist the installed kernels \n\n"
> +
> +find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
> +
> +printf "\n\n\n Please give the kernel version to remove: %s"
> +read kernel_version
> +if [[ $kernel_version -eq "" ]];then
> +	printf "You have forgotten the version to give for removal"

No message needed IMO -- just exit.

> +	exit 1
> +else
> +        remove_old_kernel
> +fi
> +
> +printf "\n\n Enlist the installed modules directory \n\n"
> +
> +find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
> +
> +printf "\n\n Please give the full modules directory name to remove: %s"
> +read modules_version
> +if [[ $modules_version -eq "" ]];then
> +	printf "You have forgotten to give the modules dir to remove"

ditto.

> +else
> +        remove_old_kernel_modules_dir
> +fi
> +
> +printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
> +while :
> +  do
> +     printf "\n\n Do you want to remove another?[YN] : %s"
> +     read response
> +
> +       if [[ $response == "Y" ]];then

Odd indentation here.  Some lines use tab, some lines use spaces.

> +	printf "Please give another version to remove : %s"
> +	read kernel_version
> +	remove_old_kernel
> +	printf "\n\n Please give the full modules directory name to remove: %s"
> +	read modules_version
> +	remove_old_kernel_modules_dir
> +        printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
> +
> +      elif [[ $response == "N" ]];then
> +	   exit 1
> +      fi
> +  done
> --
> 2.21.0


And lastly, 'patch' will apply this patch cleanly, but it ends up with
almost all of this patch inserted into the new prune-kernel source file
before the current contents of the prune-kernel source file,
so I think that the emailed patch file has a problem.

-- 
~Randy


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

* [PATCH] scripts : prune-kernel : prune kernels generalized way
@ 2019-10-17  6:31 Bhaskar Chowdhury
  2019-10-17 20:16 ` Randy Dunlap
  0 siblings, 1 reply; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-17  6:31 UTC (permalink / raw)
  To: yamada.masahiro, michal.lkml
  Cc: rdunlap, bfields, linux-kbuild, linux-kernel, Bhaskar Chowdhury

This patch will remove old kernel from the system in a selective way.

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
For Randy :
✔ ~/git-linux/linux-kbuild [master|AM/REBASE ↑·8|✔]
11:42 $ ./scripts/checkpatch.pl -f
scripts/0001-Fix-all-the-concern-raised-by-Randy.patch
total: 0 errors, 0 warnings, 93 lines checked

scripts/0001-Fix-all-the-concern-raised-by-Randy.patch has no obvious
style problems and is ready for submission.

scripts/prune-kernel | 75 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index e69de29bb2d1..9461ae2bc122 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -0,0 +1,75 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# 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:
+
+#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
+boot_dir=/boot
+modules_dir=/lib/modules
+function remove_old_kernel(){
+	cd $boot_dir
+	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_verison
+}
+function remove_old_kernel_modules_dir(){
+	cd $modules_dir
+	rm -rf $modules_version
+}
+printf "\n\n Enlist the installed kernels \n\n"
+
+find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
+
+printf "\n\n\n Please give the kernel version to remove: %s"
+read kernel_version
+if [[ $kernel_version -eq "" ]];then
+	printf "You have forgotten the version to give for removal"
+	exit 1
+else
+        remove_old_kernel
+fi
+
+printf "\n\n Enlist the installed modules directory \n\n"
+
+find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
+
+printf "\n\n Please give the full modules directory name to remove: %s"
+read modules_version
+if [[ $modules_version -eq "" ]];then
+	printf "You have forgotten to give the modules dir to remove"
+else
+        remove_old_kernel_modules_dir
+fi
+
+printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
+while :
+  do
+     printf "\n\n Do you want to remove another?[YN] : %s"
+     read response
+
+       if [[ $response == "Y" ]];then
+	printf "Please give another version to remove : %s"
+	read kernel_version
+	remove_old_kernel
+	printf "\n\n Please give the full modules directory name to remove: %s"
+	read modules_version
+	remove_old_kernel_modules_dir
+        printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
+
+      elif [[ $response == "N" ]];then
+	   exit 1
+      fi
+  done
--
2.21.0


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

* Re: [PATCH] scripts : prune-kernel : prune kernels generalized way
  2019-10-16 16:08 ` Randy Dunlap
@ 2019-10-17  6:19   ` Bhaskar Chowdhury
  0 siblings, 0 replies; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-17  6:19 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: yamada.masahiro, michal.lkml, linux-kbuild, linux-kernel, bfields

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

On 09:08 Wed 16 Oct 2019, Randy Dunlap wrote:
>On 10/15/19 11:13 PM, Bhaskar Chowdhury wrote:
>> This patch will remove old kernel from the system in a selective way.
>>
>> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
>> ---
>> Thanks, a bunch to Randy for the hand holding . :)
>
>Hi Bhaskar,
>
>First problem is that patch complains:
>
>checking file scripts/prune-kernel
>Using Plan A...
>patch: **** malformed patch at line 87: 2.21.0
>
>IOW, this patch does not apply cleanly.

Whoops! Sending the patch with all the corrections. 

>More comments below.
>
>
>>  scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
>>  1 file changed, 59 insertions(+), 12 deletions(-)
>>
>> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
>> index e8aa940bc0a9..78dd4c854b2b 100755
>> --- a/scripts/prune-kernel
>> +++ b/scripts/prune-kernel
>> @@ -5,17 +5,64 @@
>>  # again, /boot and /lib/modules/ eventually fill up.
>>  # Dumb script to purge that stuff:
>>
>> +#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
>> +boot_dir=/boot
>> +modules_dir=/lib/modules
>> +
>> +function remove_old_kernel(){
>> +	cd $boot_dir
>> +	rm -If vmlinuz-$kenrel_version System.map-$kernel_version config-$kernel_verison
>
>Typos:
>	               $kernel_version                                   $kernel_version
>
>I.e., you can't have tested this.
>
Fixed.
>> +}
>> +function remove_old_kernel_modules_dir(){
>> +	cd $modules_dir
>> +	rm -rf $modules_version
>> +}
>> +printf "\n\n Enlist the installed kernels \n\n"
>> +
>> +find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
>> +
>> +printf "\n\n\n Please give the kernel version to remove: %s"
>> +read kernel_version
>> +
>
>If I enter nothing here, no need to call remove_old_kernel.
>
Okay, terminate it there, because allowing defeat the purpose 
of the script.
>> +remove_old_kernel
>> +
>> +printf "\n\n Enlist the installed modules directory \n\n"
>> +
>> +find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
>> +
>> +printf "\n\n Please give the full modules directory name to remove: %s"
>> +read modules_version
>
>If I enter nothing here, don't call remove_old_kernel_modules_dir.
>
It will not reach here, because we have terminated it above.
>> +
>> +remove_old_kernel_modules_dir
>> +
>> +printf "\n\n Removed kernel version: $kernel_version and associcated modules: $modules_version ...Done \n"
>
>       typo:                                                associated
>
Fixed.
>> +while :
>>  do
>
>Why is the "do" line missing a '+'?  The only do/done in the current script
>are already listed above as being commented out.
>
>> +printf "\n\n Do you want to remove another?[YN] : %s"
>> +read response
>> +
>> +if [[ $response == "Y" ]];then
>> +	printf "Please give another version to remove : %s"
>> +	read kernel_version
>> +	remove_old_kernel
>> +	printf "\n\n Please give the full modules directory name to remove: %s"
>> +	read modules_version
>> +	remove_old_kernel_modules_dir
>> +elif [[ $response == "N" ]];then
>> +	printf "\n\n Alright,no more. \n\n"
>
>Just exit, no printf needed.
>
>> +	exit 1
>> +fi
>>  done

>Same comment for "done" as for "do" above.
I must have done something wrong that is why...now fixed it.
>
>> --
>> 2.21.0
>
>
Thank you Randy, and extremely sorry to gobbles up your and everyones
time...heck..
>-- 
>~Randy

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

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

* Re: [PATCH] scripts : prune-kernel : prune kernels generalized way
  2019-10-16  6:13 Bhaskar Chowdhury
@ 2019-10-16 16:08 ` Randy Dunlap
  2019-10-17  6:19   ` Bhaskar Chowdhury
  0 siblings, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2019-10-16 16:08 UTC (permalink / raw)
  To: Bhaskar Chowdhury, yamada.masahiro, michal.lkml
  Cc: linux-kbuild, linux-kernel, bfields

On 10/15/19 11:13 PM, Bhaskar Chowdhury wrote:
> This patch will remove old kernel from the system in a selective way.
> 
> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
> ---
> Thanks, a bunch to Randy for the hand holding . :)

Hi Bhaskar,

First problem is that patch complains:

checking file scripts/prune-kernel
Using Plan A...
patch: **** malformed patch at line 87: 2.21.0

IOW, this patch does not apply cleanly.

More comments below.


>  scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 59 insertions(+), 12 deletions(-)
> 
> diff --git a/scripts/prune-kernel b/scripts/prune-kernel
> index e8aa940bc0a9..78dd4c854b2b 100755
> --- a/scripts/prune-kernel
> +++ b/scripts/prune-kernel
> @@ -5,17 +5,64 @@
>  # again, /boot and /lib/modules/ eventually fill up.
>  # Dumb script to purge that stuff:
> 
> +#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
> +boot_dir=/boot
> +modules_dir=/lib/modules
> +
> +function remove_old_kernel(){
> +	cd $boot_dir
> +	rm -If vmlinuz-$kenrel_version System.map-$kernel_version config-$kernel_verison

Typos:
	               $kernel_version                                   $kernel_version

I.e., you can't have tested this.

> +}
> +function remove_old_kernel_modules_dir(){
> +	cd $modules_dir
> +	rm -rf $modules_version
> +}
> +printf "\n\n Enlist the installed kernels \n\n"
> +
> +find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
> +
> +printf "\n\n\n Please give the kernel version to remove: %s"
> +read kernel_version
> +

If I enter nothing here, no need to call remove_old_kernel.

> +remove_old_kernel
> +
> +printf "\n\n Enlist the installed modules directory \n\n"
> +
> +find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
> +
> +printf "\n\n Please give the full modules directory name to remove: %s"
> +read modules_version

If I enter nothing here, don't call remove_old_kernel_modules_dir.

> +
> +remove_old_kernel_modules_dir
> +
> +printf "\n\n Removed kernel version: $kernel_version and associcated modules: $modules_version ...Done \n"

       typo:                                                associated

> +while :
>  do

Why is the "do" line missing a '+'?  The only do/done in the current script
are already listed above as being commented out.

> +printf "\n\n Do you want to remove another?[YN] : %s"
> +read response
> +
> +if [[ $response == "Y" ]];then
> +	printf "Please give another version to remove : %s"
> +	read kernel_version
> +	remove_old_kernel
> +	printf "\n\n Please give the full modules directory name to remove: %s"
> +	read modules_version
> +	remove_old_kernel_modules_dir
> +elif [[ $response == "N" ]];then
> +	printf "\n\n Alright,no more. \n\n"

Just exit, no printf needed.

> +	exit 1
> +fi
>  done

Same comment for "done" as for "do" above.

> --
> 2.21.0


-- 
~Randy

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

* [PATCH] scripts : prune-kernel : prune kernels generalized way
@ 2019-10-16  6:13 Bhaskar Chowdhury
  2019-10-16 16:08 ` Randy Dunlap
  0 siblings, 1 reply; 9+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-16  6:13 UTC (permalink / raw)
  To: yamada.masahiro, michal.lkml
  Cc: linux-kbuild, linux-kernel, rdunlap, bfields, Bhaskar Chowdhury

This patch will remove old kernel from the system in a selective way.

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
Thanks, a bunch to Randy for the hand holding . :)

 scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index e8aa940bc0a9..78dd4c854b2b 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -5,17 +5,64 @@
 # again, /boot and /lib/modules/ eventually fill up.
 # Dumb script to purge that stuff:

+#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
+boot_dir=/boot
+modules_dir=/lib/modules
+
+function remove_old_kernel(){
+	cd $boot_dir
+	rm -If vmlinuz-$kenrel_version System.map-$kernel_version config-$kernel_verison
+}
+function remove_old_kernel_modules_dir(){
+	cd $modules_dir
+	rm -rf $modules_version
+}
+printf "\n\n Enlist the installed kernels \n\n"
+
+find $boot_dir -name "vmlinuz-*" -type f  -exec ls -1 {} \;
+
+printf "\n\n\n Please give the kernel version to remove: %s"
+read kernel_version
+
+remove_old_kernel
+
+printf "\n\n Enlist the installed modules directory \n\n"
+
+find $modules_dir  -maxdepth 0 -type d -exec ls -1 {} \;
+
+printf "\n\n Please give the full modules directory name to remove: %s"
+read modules_version
+
+remove_old_kernel_modules_dir
+
+printf "\n\n Removed kernel version: $kernel_version and associcated modules: $modules_version ...Done \n"
+while :
 do
+printf "\n\n Do you want to remove another?[YN] : %s"
+read response
+
+if [[ $response == "Y" ]];then
+	printf "Please give another version to remove : %s"
+	read kernel_version
+	remove_old_kernel
+	printf "\n\n Please give the full modules directory name to remove: %s"
+	read modules_version
+	remove_old_kernel_modules_dir
+elif [[ $response == "N" ]];then
+	printf "\n\n Alright,no more. \n\n"
+	exit 1
+fi
 done
--
2.21.0


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

end of thread, other threads:[~2019-10-19 22:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-19 13:07 [PATCH] scripts: prune-kernel : prune kernels generalized way Bhaskar Chowdhury
2019-10-19 16:01 ` J. Bruce Fields
2019-10-19 22:16   ` Bhaskar Chowdhury
  -- strict thread matches above, loose matches on Subject: below --
2019-10-17  6:31 [PATCH] scripts : " Bhaskar Chowdhury
2019-10-17 20:16 ` Randy Dunlap
2019-10-17 23:00   ` Bhaskar Chowdhury
2019-10-16  6:13 Bhaskar Chowdhury
2019-10-16 16:08 ` Randy Dunlap
2019-10-17  6:19   ` Bhaskar Chowdhury

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).