Skip to contentSkip to conversation

scripts : prune-kernel : prune kernels generalized way

PATCH In review Bhaskar Chowdhury 2 participants 3 messages 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.

---
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(+)
scripts/prune-kernel +75 -0
index e69de29bb2d1..9461ae2bc122 100755
@@ -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

#1 lore raw
Quoted 37 lines · Bhaskar Chowdhury

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

---
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(+)
scripts/prune-kernel +16 -0
index e69de29bb2d1..9461ae2bc122 100755
@@ -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"

scripts/prune-kernel line 26

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

scripts/prune-kernel line 39

Quoted 13 lines
scripts/prune-kernel +13 -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 [[ $kernel_version -eq "" ]];then
+	printf "You have forgotten the version to give for removal"

No message needed IMO -- just exit.

scripts/prune-kernel line 52

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

scripts/prune-kernel line 63

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

Quoted 13 lines
scripts/prune-kernel +12 -1
+	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
--
Quoted 1 line

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.

Signature · 1 line
~Randy
#2 lore raw
Quoted 42 lines · Randy Dunlap
Quoted 41 lines · Bhaskar Chowdhury

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

---
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(+)
scripts/prune-kernel +20 -0
index e69de29bb2d1..9461ae2bc122 100755
@@ -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
Quoted 9 lines

scripts/prune-kernel line 26

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

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

Quoted 7 lines
Quoted 7 lines
scripts/prune-kernel +7 -0
+	exit 1
+else
+        remove_old_kernel
+fi
+
+printf "\n\n Enlist the installed modules directory \n\n"
+
Quoted 9 lines

scripts/prune-kernel line 52

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

Quoted 5 lines
Quoted 5 lines
scripts/prune-kernel +5 -0
+else
+        remove_old_kernel_modules_dir
+fi
+
+printf "\n\n Removed kernel version: $kernel_version and associated modules: $modules_version ...Done \n"
Quoted 9 lines

scripts/prune-kernel line 63

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

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

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

Quoted 3 lines
Signature · 1 line
~Randy

Thanks Randy for the heads up.