scripts: prune-kernel:remove old kernels and modules dir from system
PATCH 1/1 scripts: prune-kernel:remove old kernels and modules dir from system
This patch will remove old kernels and modules directorey related to that kernel from the system by interactively and silently.Here are few interactions with the scripts
1)
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
14:52 $ ./scripts/prune-kernel -h
Usage: prune-kernel [ri]
-r | --remove kernel_ver modules_dir_name
-i | --interactive use as interactive way ✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $ ./scripts/prune-kernel --help Usage: prune-kernel [ri]
-r | --remove kernel_ver modules_dir_name
-i | --interactive use as interactive way
2)
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $ ./scripts/prune-kernel -r 5.3.3
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:53 $ ./scripts/prune-kernel -r
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:54 $ ./scripts/prune-kernel -r 5.3.3 5.3.3-foo
3)
$ ./scripts/prune-kernel --remove You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $ ./scripts/prune-kernel --remove 5.3.3 You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $ ./scripts/prune-kernel --remove 5.3.3 5.3.3-foo
4)14:55 $ ./scripts/prune-kernel -i
Enter kernel version to remove or blank/empty to exit:
5)14:57 $ ./scripts/prune-kernel --interactive
Enter kernel version to remove or blank/empty to exit:
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
6)14:59 $ ./scripts/prune-kernel --interactive
Enter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
7)15:00 $ ./scripts/prune-kernel -i
Enter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
--- scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
scripts/prune-kernel +63 -0
@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will delete old kernels and modules directory related to it +#-h with the script will show you the help +#-r with the script take two parameter: kernel_ver and modules_dir_name +#-i with the script allow you do the removing interactive way +flag=$1 +kernel_ver=$2 +modules_dir_name=$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 | --remove kernel_ver modules_dir_name \n" + printf "\n -i | --interactive use as interactive way \n" +} + +for arg in "$@" +do + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s" + read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s" + read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done. \n" + else + exit 1 + fi + fi + ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules dir name\n" + exit 1 + else + cd $boot_dir + rm -f $kernel_ver + cd $modules_dir + rm -rf $modules_dir_name + fi + ;; + esac +done
--
2.23.0
Randy Dunlap
NAKHi,
Quoted 10 lines · Bhaskar Chowdhury
This patch will remove old kernels and modules directorey related to that kernel from the system by interactively and silently.Here are few interactions with the scripts
1)
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
14:52 $./scripts/prune-kernel-h
Usage: prune-kernel [ri]
Quoted 7 lines
-r | --remove
kernel_vermodules_dir_name-i | --interactive use as interactive way ✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $ ./scripts/prune-kernel --help Usage: prune-kernel [ri]
That "[ri]" is confusing to me.
Quoted 11 lines
-r | --remove kernel_ver modules_dir_na]-i | --interactive use as interactive way2)
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel-r 5.3.3
You need to provide kernel version and modules dir name
Quoted 6 lines
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:53 $
./scripts/prune-kernel-r
You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:54 $
./scripts/prune-kernel-r 5.3.3 5.3.3-foo
This one above didn't remove any kernel files.
Needs more testing.
Quoted 76 lines
3)
$ ./scripts/prune-kernel --remove You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 5.3.3-foo4)14:55 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:
5)14:57 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]6)14:59 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
7)15:00 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
Signed-off-by Bhaskar Chowdhury <[email protected]>--- scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)scripts/prune-kernel +19
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will delete old kernels and modules directory related to it +#-h with the script will show you the help +#-r with the script take two parameter: kernel_ver and modules_dir_name +#-i with the script allow you do the removing interactive way +flag=$1 +kernel_ver=$2 +modules_dir_name=$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
scripts/prune-kernel line 32
Quoted 10 lines
scripts/prune-kernel +10
-0+ return 0 +} + +usage() { + printf "Usage: $(basename $0) [ri] \n" + printf "\n -r | --remove kernel_ver modules_dir_name \n" + printf "\n -i | --interactive use as interactive way \n" +} + +for arg in "$@"
what is the purpose (use) of "arg" here?
what is the purpose of the for loop?
Is any 'shift' needed to consume (or discard) the first 3 positional command line arguments?
scripts/prune-kernel line 44
Quoted 12 lines
scripts/prune-kernel +12
-0+do + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s" + read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s" + read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done. \n"
This message is only printed if $modules_version is non-empty. If it is empty, remove_old_kernel() has silently removed some kernel files (if they existed).
Quoted 6 lines
scripts/prune-kernel +6
-0+ else + exit 1 + fi + fi + ;; + -h | --help)
scripts/prune-kernel line 60
Quoted 10 lines
scripts/prune-kernel +10
-0+ usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules dir name\n" + exit 1 + else + cd $boot_dir + rm -f $kernel_ver
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
scripts/prune-kernel
Quoted 7 lines
scripts/prune-kernel +6
-1+ cd $modules_dir + rm -rf $modules_dir_name + fi + ;; + esac +done --
The script, after this patch is applied, still contains the old script's for-loop at the end of the "new" prune-kernel script.
Nack.
Signature · 1 line
~Randy
Thank you Randy, my response are inline. Please look at it.I am wondering , what else I could do get this damn! thing going?? Any clue??
Quoted 15 lines · Randy Dunlap
Hi,
Quoted 12 lines · Bhaskar Chowdhury
This patch will remove old kernels and modules directorey related to that kernel from the system by interactively and silently.Here are few interactions with the scripts
1)
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
14:52 $./scripts/prune-kernel-h
Usage: prune-kernel [ri]-r | --remove
kernel_vermodules_dir_name
Quoted 7 lines
Quoted 5 lines
-i | --interactive use as interactive way ✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $ ./scripts/prune-kernel --help Usage: prune-kernel [ri]That "[ri]" is confusing to me.
This are the options one has to pass with the script.Like below:
Quoted 15 lines
Quoted 15 lines
-r | --remove kernel_ver modules_dir_na]-i | --interactive use as interactive way2)
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel-r 5.3.3
You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:53 $
./scripts/prune-kernel-r
You need to provide kernel version and modules dir name
Quoted 5 lines
Quoted 2 lines
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:54 $
./scripts/prune-kernel-r 5.3.3 5.3.3-fooThis one above didn't remove any kernel files.
Needs more testing.
It does remove but silently, as you and Bruce asked for this feature.
Quoted 81 lines
Quoted 81 lines
3)
$ ./scripts/prune-kernel --remove You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 5.3.3-foo4)14:55 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:
5)14:57 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]6)14:59 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
7)15:00 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
Signed-off-by Bhaskar Chowdhury <[email protected]>--- scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)scripts/prune-kernel +23
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will delete old kernels and modules directory related to it +#-h with the script will show you the help +#-r with the script take two parameter: kernel_ver and modules_dir_name +#-i with the script allow you do the removing interactive way +flag=$1 +kernel_ver=$2 +modules_dir_name=$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() {
Quoted 8 lines
scripts/prune-kernel line 32
Quoted 6 lines
scripts/prune-kernel +6
-0+ printf "Usage: $(basename $0) [ri] \n" + printf "\n -r | --remove kernel_ver modules_dir_name \n" + printf "\n -i | --interactive use as interactive way \n" +} + +for arg in "$@"what is the purpose (use) of "arg" here?
This variable is used in case statement below.
Quoted 2 lines
what is the purpose of the for loop?
It scan through all the parameters pass .
Quoted 2 lines
Is any 'shift' needed to consume (or discard) the first 3 positional command line arguments?
Nope, that is not required. And I haven't use any.
Quoted 16 lines
scripts/prune-kernel line 44
Quoted 13 lines
scripts/prune-kernel +12
-0+do + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s" + read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s" + read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done. \n"This message is only printed if $modules_version is non-empty. If it is empty,
remove_old_kernel()has silently removed some kernel files (if they existed).
it will fail to remove anything if the kernel_version or modules_version are empty and importantly exit.
Quoted 11 lines
Quoted 11 lines
scripts/prune-kernel +10
-0+ else + exit 1 + fi + fi + ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove)
Quoted 8 lines
scripts/prune-kernel line 60
Quoted 6 lines
scripts/prune-kernel +6
-0+ if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules dir name\n" + exit 1 + else + cd $boot_dir + rm -f $kernel_verThat 'rm' doesn't remove any files. Compare what
remove_old_kernel()does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 11 lines
scripts/prune-kernel
Quoted 8 lines
scripts/prune-kernel +6
-1+ cd $modules_dir + rm -rf $modules_dir_name + fi + ;; + esac +done --The script, after this patch is applied, still contains the old script's for-loop at the end of the "new" prune-kernel script.
Amazing! now it needs some explanation how I did...you probably want that ..here are the steps....
1)fetch that prune-kernel file from repos , which contains Bruce's code in it.
2) get inot it by editior, remove all except first two lines i.e bash interpreter and PSDX .
3)Save and commit it locally.
4) Write my own code
5) save it and commit it locally.
6) go one level up use checkpatch to see anything bad creeps in
7) Fixed the damn things if it reports.
8) create the patch
9) test it
10) Send it.
Now, how the heck , that for loop is getting staying there is a mystry to me!! Look like that is ruin all the work.
irk...
Quoted 5 lines
Nack.
Signature · 1 line
~Randy
Quoted 20 lines · Bhaskar Chowdhury
Thank you Randy, my response are inline. Please look at it.I am wondering , what else I could do get this damn! thing going?? Any clue??
Quoted 15 lines · Randy Dunlap
Hi,
Quoted 12 lines · Bhaskar Chowdhury
This patch will remove old kernels and modules directorey related to that kernel from the system by interactively and silently.Here are few interactions with the scripts
1)
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
14:52 $./scripts/prune-kernel-h
Usage: prune-kernel [ri]-r | --remove
kernel_vermodules_dir_name
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
-i | --interactive use as interactive way ✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel--help
Usage: prune-kernel [ri]That "[ri]" is confusing to me.
This are the options one has to pass with the script.Like below:
I know that. But it's missing '-', so it looks like
$ prune-kernel r 5.2.5-foobar
would work.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
-r | --remove
kernel_vermodules_dir_na]-i | --interactive use as interactive way
2)✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel-r 5.3.3
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:53 $./scripts/prune-kernel-r
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:54 $./scripts/prune-kernel-r 5.3.3 5.3.3-foo
Quoted 3 lines
Quoted 2 lines
This one above didn't remove any kernel files.
Needs more testing.It does remove but silently, as you and Bruce asked for this feature.
No, see the code below for -r...
Quoted 89 lines
Quoted 80 lines
Quoted 80 lines
3)
$ ./scripts/prune-kernel --remove You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 5.3.3-foo4)14:55 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:
5)14:57 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]6)14:59 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
7)15:00 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
Signed-off-by Bhaskar Chowdhury <[email protected]>---
scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++1 file changed, 63 insertions(+)scripts/prune-kernel +23
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will delete old kernels and modules directory related to it +#-h with the script will show you the help +#-r with the script take two parameter: kernel_ver and modules_dir_name +#-i with the script allow you do the removing interactive way +flag=$1 +kernel_ver=$2 +modules_dir_name=$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() {Quoted 8 lines
scripts/prune-kernel line 32
Quoted 6 lines
scripts/prune-kernel +6
-0+ printf "Usage: $(basename $0) [ri] \n" + printf "\n -r | --remove kernel_ver modules_dir_name \n" + printf "\n -i | --interactive use as interactive way \n" +} + +for arg in "$@"what is the purpose (use) of "arg" here?
Quoted 1 line
This variable is used in case statement below.
I can't find any use of 'arg' anywhere else in the script. Please show me where it is.
Quoted 3 lines
Quoted 2 lines
what is the purpose of the for loop?
It scan through all the parameters pass .
What is this script supposed (expected) to do with multiple arg parameters?
Quoted 39 lines
Quoted 2 lines
Is any 'shift' needed to consume (or discard) the first 3 positional command line arguments?
Nope, that is not required. And I haven't use any.
Quoted 14 lines
scripts/prune-kernel line 44
Quoted 13 lines
scripts/prune-kernel +12
-0+do + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s" + read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s" + read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done. \n"Quoted 2 lines
This message is only printed if $modules_version is non-empty. If it is empty,
remove_old_kernel()has silently removed some kernel files (if they existed).it will fail to remove anything if the
kernel_versionormodules_versionare empty and importantly exit.Quoted 18 lines
Quoted 17 lines
scripts/prune-kernel +16
-0+ else + exit 1 + fi + fi + ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules dir name\n" + exit 1 + else + cd $boot_dir + rm -f $kernel_ver
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what
remove_old_kernel()does.No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Quoted 26 lines
Quoted 10 lines
scripts/prune-kernel line 66
Quoted 7 lines
scripts/prune-kernel +6
-0+ cd $modules_dir + rm -rf $modules_dir_name + fi + ;; + esac +doneThe script, after this patch is applied, still contains the old script's for-loop at the end of the "new" prune-kernel script.
Amazing! now it needs some explanation how I did...you probably want that ..here are the steps....
1)fetch that prune-kernel file from repos , which contains Bruce's code in it.
2) get inot it by editior, remove all except first two lines i.e bash interpreter and PSDX .
3)Save and commit it locally.
4) Write my own code
5) save it and commit it locally.
6) go one level up use checkpatch to see anything bad creeps in
7) Fixed the damn things if it reports.
8) create the patch
9) test it
10) Send it.
Quoted 3 lines
Now, how the heck , that for loop is getting staying there is a mystry to me!! Look like that is ruin all the work.
irk...
I don't know. I just know that it's not working AFAICT.
Signature · 1 line
~Randy
Thank you so much Randy. I am awfully sorry about the ugly code , hopefully come up with a better one. If I understood your expectation.
I know we all are blessed with limited resources like patience.Thanks for holding this long...little more and we will be over it.
:)
Quoted 26 lines · Randy Dunlap
Quoted 25 lines · Bhaskar Chowdhury
Thank you Randy, my response are inline. Please look at it.I am wondering , what else I could do get this damn! thing going?? Any clue??
Quoted 20 lines · Randy Dunlap
Hi,
Quoted 16 lines · Bhaskar Chowdhury
This patch will remove old kernels and modules directorey related to that kernel from the system by interactively and silently.Here are few interactions with the scripts
1)
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]
14:52 $./scripts/prune-kernel-h
Usage: prune-kernel [ri]-r | --remove
kernel_vermodules_dir_name-i | --interactive use as interactive way ✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel--help
Usage: prune-kernel [ri]
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
That "[ri]" is confusing to me.
This are the options one has to pass with the script.Like below:
I know that. But it's missing '-', so it looks like
$ prune-kernel r 5.2.5-foobarwould work.
Will correct that.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
-r | --remove
kernel_vermodules_dir_na]-i | --interactive use as interactive way
2)✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:52 $
./scripts/prune-kernel-r 5.3.3
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:53 $./scripts/prune-kernel-r
You need to provide kernel version and modules dir name
✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:54 $./scripts/prune-kernel-r 5.3.3 5.3.3-foo
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
This one above didn't remove any kernel files.
Needs more testing.It does remove but silently, as you and Bruce asked for this feature.
No, see the code below for -r...
Okay ...look like some some uniformity missing
Quoted 89 lines
Quoted 89 lines
Quoted 88 lines
Quoted 76 lines
3)
$ ./scripts/prune-kernel --remove You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 You need to provide kernel version and modules dir name✘-1 ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔] 14:55 $
./scripts/prune-kernel--remove 5.3.3 5.3.3-foo4)14:55 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:
5)14:57 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:
✔ ~/git-linux/linux-kbuild [master|AM 1/1 ↑·59|✔]6)14:59 $
./scripts/prune-kernel--interactiveEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
7)15:00 $
./scripts/prune-kernel-iEnter kernel version to remove or blank/empty to exit:5.3.3 Please give the full modules directory name to remove:5.3.3-foo
Removed kernel version:5.3.3 and associated modules:5.3.3-foo ...Done.
Signed-off-by Bhaskar Chowdhury <[email protected]>---
scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++1 file changed, 63 insertions(+)scripts/prune-kernel +19
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will delete old kernels and modules directory related to it +#-h with the script will show you the help +#-r with the script take two parameter: kernel_ver and modules_dir_name +#-i with the script allow you do the removing interactive way +flag=$1 +kernel_ver=$2 +modules_dir_name=$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_versionscripts/prune-kernel line 32
Quoted 10 lines
scripts/prune-kernel +10
-0+ return 0 +} + +usage() { + printf "Usage: $(basename $0) [ri] \n" + printf "\n -r | --remove kernel_ver modules_dir_name \n" + printf "\n -i | --interactive use as interactive way \n" +} + +for arg in "$@"what is the purpose (use) of "arg" here?
Quoted 4 lines
Quoted 1 line
This variable is used in case statement below.
I can't find any use of 'arg' anywhere else in the script. Please show me where it is.
My bad and apologies for overlooking.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
what is the purpose of the for loop?
It scan through all the parameters pass .
What is this script supposed (expected) to do with multiple arg parameters?
It uses multiple parameter
Quoted 43 lines
Quoted 39 lines
Quoted 2 lines
Is any 'shift' needed to consume (or discard) the first 3 positional command line arguments?
Nope, that is not required. And I haven't use any.
Quoted 14 lines
scripts/prune-kernel line 44
Quoted 13 lines
scripts/prune-kernel +12
-0+do + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s" + read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s" + read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ...Done. \n"Quoted 2 lines
This message is only printed if $modules_version is non-empty. If it is empty,
remove_old_kernel()has silently removed some kernel files (if they existed).it will fail to remove anything if the
kernel_versionormodules_versionare empty and importantly exit.Quoted 18 lines
Quoted 17 lines
scripts/prune-kernel +16
-0+ else + exit 1 + fi + fi + ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules dir name\n" + exit 1 + else + cd $boot_dir + rm -f $kernel_verQuoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what
remove_old_kernel()does.No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what
rmeove_old_kernel()does:rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e call remove_old_kernel to do the job instead of depending on individual kernel.
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
scripts/prune-kernel line 66
Quoted 9 lines
scripts/prune-kernel +6
-0+ cd $modules_dir + rm -rf $modules_dir_name + fi + ;; + esac +doneQuoted 2 lines
The script, after this patch is applied, still contains the old script's for-loop at the end of the "new" prune-kernel script.
Amazing! now it needs some explanation how I did...you probably want that ..here are the steps....
1)fetch that prune-kernel file from repos , which contains Bruce's code in it.
2) get inot it by editior, remove all except first two lines i.e bash interpreter and PSDX .
3)Save and commit it locally.
4) Write my own code
5) save it and commit it locally.
6) go one level up use checkpatch to see anything bad creeps in
7) Fixed the damn things if it reports.
8) create the patch
9) test it
10) Send it.
Quoted 5 lines
Quoted 3 lines
Now, how the heck , that for loop is getting staying there is a mystry to me!! Look like that is ruin all the work.
irk...I don't know. I just know that it's not working AFAICT.
Thank you, will be more vigilant in next iteration.
Quoted 4 lines
Signature · 2 lines
-- ~Randy
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.
The simplest thing to do is set kernel_version=$kernel_ver
and then call remove_old_kernel().
And set modules_version=$modules_dir_name and call remove_old_modules_dir().
But it would be cleaner to pass a parameter (kernel_version) to the remove_old_kernel() function and to pass a parameter (modules_dir) to the remove_old_modules_dir() function.
Signature · 1 line
~Randy
Quoted 14 lines · Randy Dunlap
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.
Quoted 9 lines
The simplest thing to do is set kernel_version=$kernel_ver
and then callremove_old_kernel().
And set modules_version=$modules_dir_name and callremove_old_modules_dir().But it would be cleaner to pass a parameter (
kernel_version) to theremove_old_kernel()function and to pass a parameter (modules_dir) to theremove_old_modules_dir()function.
Thank you...I have just modified the code and call both the function
under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $mo dules_version.
Capturing command line parameter in $kernel_version and $modules_version
Is that fine? Here is a code snippet:
-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
I have just test it and it works.
And about solitary r option without hypen is ignoring and doing nothing.
Means, if I pass ./scripts/prune-kernel r 5.3.3
it simply ignore and does nothing.Only with the hypen it can work.
Quoted 3 lines
Signature · 1 line
~Randy
Bhaskar
Quoted 25 lines · Bhaskar Chowdhury
Quoted 14 lines · Randy Dunlap
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.Quoted 9 lines
The simplest thing to do is set kernel_version=$kernel_ver
and then callremove_old_kernel().
And set modules_version=$modules_dir_name and callremove_old_modules_dir().But it would be cleaner to pass a parameter (
kernel_version) to theremove_old_kernel()function and to pass a parameter (modules_dir) to theremove_old_modules_dir()function.
Quoted 7 lines
Thank you...I have just modified the code and call both the function
under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $modules_version.Capturing command line parameter in $kernel_version and $modules_version
Is that fine? Here is a code snippet:
Yes, that should be OK.
Quoted 11 lines
-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
Quoted 7 lines
I have just test it and it works.
And about solitary r option without hypen is ignoring and doing nothing.
Means, if I pass
./scripts/prune-kernelr 5.3.3
it simply ignore and does nothing.Only with the hypen it can work.
Is that how it should be?
or what would you expect that to do?
Signature · 1 line
~Randy
Quoted 50 lines · Randy Dunlap
Quoted 25 lines · Bhaskar Chowdhury
Quoted 14 lines · Randy Dunlap
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.Quoted 9 lines
The simplest thing to do is set kernel_version=$kernel_ver
and then callremove_old_kernel().
And set modules_version=$modules_dir_name and callremove_old_modules_dir().But it would be cleaner to pass a parameter (
kernel_version) to theremove_old_kernel()function and to pass a parameter (modules_dir) to theremove_old_modules_dir()function.Quoted 7 lines
Thank you...I have just modified the code and call both the function
under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $modules_version.Capturing command line parameter in $kernel_version and $modules_version
Is that fine? Here is a code snippet:
Yes, that should be OK.
Quoted 14 lines
-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
fiI have just test it and it works.
Quoted 7 lines
Quoted 4 lines
And about solitary r option without hypen is ignoring and doing nothing.
Means, if I pass
./scripts/prune-kernelr 5.3.3
it simply ignore and does nothing.Only with the hypen it can work.Is that how it should be?
or what would you expect that to do?
Yes it should be. Any malformed parameter should be discarded,except what explicitly given in code form,as help reminder.
OR
Do you want me to reminds user that they are missing thing to operate correctly??
Quoted 3 lines
Signature · 2 lines
-- ~Randy
Bhaskar
Quoted 1 line
Quoted 65 lines · Bhaskar Chowdhury
Quoted 50 lines · Randy Dunlap
Quoted 25 lines · Bhaskar Chowdhury
Quoted 14 lines · Randy Dunlap
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.Quoted 9 lines
The simplest thing to do is set kernel_version=$kernel_ver
and then callremove_old_kernel().
And set modules_version=$modules_dir_name and callremove_old_modules_dir().But it would be cleaner to pass a parameter (
kernel_version) to theremove_old_kernel()function and to pass a parameter (modules_dir) to theremove_old_modules_dir()function.Quoted 7 lines
Thank you...I have just modified the code and call both the function
under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $modules_version.Capturing command line parameter in $kernel_version and $modules_version
Is that fine? Here is a code snippet:
Yes, that should be OK.
Quoted 14 lines
-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
fiI have just test it and it works.
Quoted 7 lines
Quoted 4 lines
And about solitary r option without hypen is ignoring and doing nothing.
Means, if I pass
./scripts/prune-kernelr 5.3.3
it simply ignore and does nothing.Only with the hypen it can work.Is that how it should be?
or what would you expect that to do?Yes it should be. Any malformed parameter should be discarded,except what explicitly given in code form,as help reminder.
OR
Do you want me to reminds user that they are missing thing to operate correctly??Quoted 1 line
Quoted 4 lines
Quoted 2 lines
Signature · 1 line
~RandyBhaskar
Quoted 1 line
Randy,
I think we should show the help message , whenever user put a malformed parameter, say they put something like this :
./scripts/prune-kernel f 5.3.3
It should show the help message to indicate what exactly need to pass with the script to get the desired result.
What do you think??
~Bhaskar
Quoted 11 lines
-----BEGIN PGP SIGNATURE-----
iQEzBAABCAAdFiEEnwF+nWawchZUPOuwsjqdtxFLKRUFAl27s0EACgkQsjqdtxFL KRV81wf/cMmIASLvGNbAxdbZY/7xnsdsaOWLsfH5c4twHsVwm74Zbasdq8s1l5Kn z8CZeWxKOKsItEY52g2vXbyDMFkk2La77kHZo4O5hQOmenRMaD9M7wcWqSCOJg59 EbhMUt7RLpJLDKYTtegoGIyNgVZXfV8PpH6iKIvNscyJPMNBvppgRKkn80MWoG7k i0rMI6kvchwilxhVz/LPbJgKrIayhriKIBfTbDracSdX+WtJMQbAjdWRgGk0rmGe wS0p8nwJmmqXSc/qrrgZPR9VxsknVNMm/PzKS9CTE+GvELjXS8MeG3iwauQ4hx2K B255AW+zobp0IQGwTqH7VwO0u2GzLQ==
=3y5/
-----END PGP SIGNATURE-----
Quoted 74 lines · Bhaskar Chowdhury
Quoted 64 lines · Bhaskar Chowdhury
Quoted 50 lines · Randy Dunlap
Quoted 25 lines · Bhaskar Chowdhury
Quoted 14 lines · Randy Dunlap
Quoted 4 lines · Bhaskar Chowdhury
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
That 'rm' doesn't remove any files. Compare what remove_old_kernel() does.
No,it is not using that function rather take the parameter from the commandline and get into boot dir match with it and remove it.
Quoted 8 lines
Quoted 6 lines
But it doesn't do that. I tested it. It should be more like what rmeove_old_kernel() does:
rm -If vmlinuz-$kernel_ver System.map-$kernel_ver config-$kernel_ver
and if not, please explain why not.
Okay, again some uniformity missing in the code, I would like to your
suggested method,i.e callremove_old_kernelto do the job instead of depending on individual kernel.Quoted 9 lines
The simplest thing to do is set kernel_version=$kernel_ver
and then callremove_old_kernel().
And set modules_version=$modules_dir_name and callremove_old_modules_dir().But it would be cleaner to pass a parameter (
kernel_version) to theremove_old_kernel()function and to pass a parameter (modules_dir) to theremove_old_modules_dir()function.Quoted 7 lines
Thank you...I have just modified the code and call both the function
under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $modules_version.Capturing command line parameter in $kernel_version and $modules_version
Is that fine? Here is a code snippet:
Yes, that should be OK.
Quoted 14 lines
-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
fiI have just test it and it works.
Quoted 7 lines
Quoted 4 lines
And about solitary r option without hypen is ignoring and doing nothing.
Means, if I pass
./scripts/prune-kernelr 5.3.3
it simply ignore and does nothing.Only with the hypen it can work.Is that how it should be?
or what would you expect that to do?Yes it should be. Any malformed parameter should be discarded,except what explicitly given in code form,as help reminder.
OR
Do you want me to reminds user that they are missing thing to operate correctly??Quoted 1 line
Quoted 4 lines
Quoted 2 lines
--
~RandyBhaskar
Quoted 1 line
Randy,
I think we should show the help message , whenever user put a malformed parameter, say they put something like this :
Quoted 6 lines
./scripts/prune-kernelf 5.3.3It should show the help message to indicate what exactly need to pass with the script to get the desired result.
What do you think??
I agree. Entering garbage junk should spit out help.
Signature · 1 line
~Randy