scripts:prune-kernel:Removed old kernels and modules dir from system
PATCH 1/1 scripts:prune-kernel:Removed old kernels and modules dir from system
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.
--- 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 remove old kernels and modules directory related to it. +# "-h" or "--help" show how to use this script or show without parameter. +#"-r" or "--remove" show how to silently remove old kernel and modules dir. +#"-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:%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\nRemoved kernel version:$kernel_version and associated modules directory:$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 directory name \n" + exit 1 + else + remove_old_kernel + remove_old_modules_dir + fi + ;; + *) + usage + exit 1 + ;; + esac
--
2.23.0
Quoted 5 lines · Bhaskar Chowdhury
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 <[email protected]>
Hi Bhaskar,
I think that you are getting a lot closer with this patch, but there are still a few issues. And of course, it's not up to me whether the patch is applied.
See below.
Quoted 28 lines
--- scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)scripts/prune-kernel +16
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will remove old kernels and modules directory related to it. +# "-h" or "--help" show how to use this script or show without parameter. +#"-r" or "--remove" show how to silently remove old kernel and modules dir. +#"-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 +} +
scripts/prune-kernel line 29
Quoted 10 lines
scripts/prune-kernel +10
-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"
In those 3 printf's, drop the ending space before the \n.
scripts/prune-kernel line 35
Quoted 6 lines
scripts/prune-kernel +6
-0+ return 0 +} + + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s"
Drop the %s - it's not needed.
scripts/prune-kernel line 39
Quoted 4 lines
scripts/prune-kernel +4
-0+ read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s"
Drop the %s here also.
scripts/prune-kernel line 47
Quoted 8 lines
scripts/prune-kernel +8
-0+ read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\nRemoved kernel version:$kernel_version and associated modules directory:$modules_version ...Done \n" + else + exit 1 + fi + fi
There is still a small problem here: if I enter a kernel_version and then remove_old_kernel() is called, and then I enter "" for modules_version, the script exits without that printf line. I guess that it is possible that someone only wants to remove the kernel_version files and not the modules.
Perhaps the thing to do is just make the prompts and calls and printf totally separate and repeated for kernel_version and modules_version. Do you see what I mean? or do you have other ideas about this?
scripts/prune-kernel line 55
Quoted 8 lines
scripts/prune-kernel +8
-0+ ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules directory name \n"
Drop the space before the \n.
scripts/prune-kernel
Quoted 12 lines
scripts/prune-kernel +11
-1+ exit 1 + else + remove_old_kernel + remove_old_modules_dir + fi + ;; + *) + usage + exit 1 + ;; + esac --
Same comment as before: after applying this patch, the "new" scripts/prune-kernel file still contains the previous script's for-loop at the end of the "new" script.
Signature · 1 line
~Randy
Quoted 7 lines · Randy Dunlap
Quoted 5 lines · Bhaskar Chowdhury
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 <[email protected]>
Quoted 8 lines
Hi Bhaskar,
I think that you are getting a lot closer with this patch, but there are still a few issues. And of course, it's not up to me whether the patch is applied.
See below.
Hi Randy,
Thank you for the review. My understanding below...kindly glean on it..
Quoted 32 lines
Quoted 32 lines
--- scripts/prune-kernel | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)scripts/prune-kernel +20
-0@@ -1,3 +1,66 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +#This script will remove old kernels and modules directory related to it. +# "-h" or "--help" show how to use this script or show without parameter. +#"-r" or "--remove" show how to silently remove old kernel and modules dir. +#"-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
Quoted 9 lines
scripts/prune-kernel line 29
Quoted 6 lines
scripts/prune-kernel +6
-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"In those 3 printf's, drop the ending space before the \n.
Will do in next patch.
Quoted 8 lines
scripts/prune-kernel line 35
Quoted 6 lines
scripts/prune-kernel +6
-0+ return 0 +} + + case "$flag" in + -i | --interactive) + printf "\nEnter kernel version to remove or blank/empty to exit:%s"Drop the %s - it's not needed.
Will do in next patch.
Quoted 7 lines
scripts/prune-kernel line 39
Quoted 5 lines
scripts/prune-kernel +4
-0+ read kernel_version + if [[ $kernel_version != "" ]]; then + remove_old_kernel + printf "Please give the full modules directory name to remove:%s"Drop the %s here also.
Will do it next patch.
Quoted 15 lines
scripts/prune-kernel line 47
Quoted 9 lines
scripts/prune-kernel +8
-0+ read modules_version + if [[ $modules_version != "" ]]; then + remove_old_modules_dir + printf "\n\nRemoved kernel version:$kernel_version and associated modules directory:$modules_version ...Done \n" + else + exit 1 + fi + fiThere is still a small problem here: if I enter a
kernel_versionand thenremove_old_kernel()is called, and then I enter "" formodules_version, the script exits without that printf line. I guess that it is possible that someone only wants to remove thekernel_versionfiles and not the modules.
I beg to differ. I think keep around old modules only gobbles up the space(I know it's aplenty these day...but I came from...)..anyway I thought it would be good to get rid of these stale stuff at once.
Quoted 3 lines
Perhaps the thing to do is just make the prompts and calls and printf totally separate and repeated for
kernel_versionandmodules_version. Do you see what I mean? or do you have other ideas about this?
Okay, I can understand. I could have done that...but thought instead show it at once . But again, I will take suggestion and put separate print statement for kernel removal and modules removal.
Quoted 11 lines
scripts/prune-kernel line 55
Quoted 9 lines
scripts/prune-kernel +8
-0+ ;; + -h | --help) + usage + exit 1 + ;; + -r | --remove) + if [[ $# -ne 3 ]]; then + printf "You need to provide kernel version and modules directory name \n"Drop the space before the \n.
Will do it next patch.
Quoted 18 lines
scripts/prune-kernel
Quoted 13 lines
scripts/prune-kernel +11
-1+ exit 1 + else + remove_old_kernel + remove_old_modules_dir + fi + ;; + *) + usage + exit 1 + ;; + esac --Same comment as before: after applying this patch, the "new"
scripts/prune-kernelfile still contains the previous script's for-loop at the end of the "new" script.
I am bemused and confused like hell Randy about this. This probably lack of understanding about git ...not sure though...
In ,wild dream, can I implement a "real new file" and forget about this whole chapter of trailing.??
Upfront apologies to Bruce...it seems I am getting defeated by my shortcoming ...heck..
Quoted 2 lines
Signature · 1 line
~Randy
Bhaskar