Skip to contentSkip to conversation

scripts : prune-kernel : prune kernels generalized way

PATCH In review Bhaskar Chowdhury 2 participants 3 messages Oct 16, 2019 – Oct 17, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts : prune-kernel : prune kernels generalized way

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

---
Thanks, a bunch to Randy for the hand holding . :)

 scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)
scripts/prune-kernel +59 -1
index e8aa940bc0a9..78dd4c854b2b 100755
@@ -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

#1 lore raw
Quoted 5 lines · Bhaskar Chowdhury

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

---
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.

Quoted 21 lines
 scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)
scripts/prune-kernel +10 -0
index e8aa940bc0a9..78dd4c854b2b 100755
@@ -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"

scripts/prune-kernel line 27

Quoted 10 lines
scripts/prune-kernel +10 -0
+#                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.

scripts/prune-kernel line 39

Quoted 12 lines
scripts/prune-kernel +12 -0
+}
+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.

scripts/prune-kernel line 47

Quoted 8 lines
scripts/prune-kernel +8 -0
+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.

scripts/prune-kernel line 51

Quoted 4 lines
scripts/prune-kernel +4 -0
+
+remove_old_kernel_modules_dir
+
+printf "\n\n Removed kernel version: $kernel_version and associcated modules: $modules_version ...Done \n"

typo: associated

scripts/prune-kernel line 53

Quoted 2 lines
scripts/prune-kernel +1 -0
+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.

scripts/prune-kernel line 65

Quoted 12 lines
scripts/prune-kernel +12 -0
+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.

scripts/prune-kernel line 68

Quoted 3 lines
scripts/prune-kernel +2 -0
+	exit 1
+fi
 done

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

Quoted 2 lines
scripts/prune-kernel +0 -1
--

2.21.0

Signature · 1 line
~Randy
#2 lore raw
Quoted 9 lines · Randy Dunlap
Quoted 5 lines · Bhaskar Chowdhury

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

---
Thanks, a bunch to Randy for the hand holding . :)

Hi Bhaskar,

Quoted 7 lines

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.

Quoted 38 lines

More comments below.

Quoted 21 lines
 scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)
scripts/prune-kernel +10 -0
index e8aa940bc0a9..78dd4c854b2b 100755
@@ -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"

scripts/prune-kernel line 27

Quoted 10 lines
scripts/prune-kernel +10 -0
+#                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

Quoted 2 lines

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

Fixed.

Quoted 6 lines
Quoted 6 lines
scripts/prune-kernel +6 -0
+}
+function remove_old_kernel_modules_dir(){
+	cd $modules_dir
+	rm -rf $modules_version
+}
+printf "\n\n Enlist the installed kernels \n\n"
Quoted 9 lines

scripts/prune-kernel line 39

Quoted 6 lines
scripts/prune-kernel +6 -0
+
+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.

Quoted 11 lines

scripts/prune-kernel line 47

Quoted 8 lines
scripts/prune-kernel +8 -0
+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.

Quoted 7 lines

scripts/prune-kernel line 51

Quoted 4 lines
scripts/prune-kernel +4 -0
+
+remove_old_kernel_modules_dir
+
+printf "\n\n Removed kernel version: $kernel_version and associcated modules: $modules_version ...Done \n"

typo: associated

Fixed.

Quoted 21 lines

scripts/prune-kernel line 53

Quoted 2 lines
scripts/prune-kernel +1 -0
+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.

scripts/prune-kernel line 65

Quoted 12 lines
scripts/prune-kernel +12 -0
+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.

Quoted 5 lines

scripts/prune-kernel line 68

Quoted 3 lines
scripts/prune-kernel +2 -0
+	exit 1
+fi
 done

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

I must have done something wrong that is why...now fixed it.

Quoted 5 lines
Quoted 3 lines
scripts/prune-kernel +0 -1
--

2.21.0

Thank you Randy, and extremely sorry to gobbles up your and everyones time...heck..

Quoted 2 lines
Signature · 1 line
~Randy