linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system
@ 2019-11-02  6:30 Bhaskar Chowdhury
  2019-11-05  2:03 ` Randy Dunlap
  0 siblings, 1 reply; 31+ messages in thread
From: Bhaskar Chowdhury @ 2019-11-02  6:30 UTC (permalink / raw)
  To: rdunlap
  Cc: bfields, yamada.masahiro, michal.lkml, linux-kbuild,
	linux-kernel, 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 <unixbhaskar@gmail.com>
---
 scripts/prune-kernel | 82 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 65 insertions(+), 17 deletions(-)

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index e8aa940bc0a9..01d0778db71f 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -1,21 +1,69 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
+#This script will remove old kernels and modules directory related to it.
+#"-r" or "--remove" show how to silently remove old kernel and modules dir.
+# "-h" or "--help" show how to use this script or show without parameter.
+#"-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:"
+		read kernel_version
+		if [[ $kernel_version != "" ]]; then
+			remove_old_kernel
+			printf "\nRemoved kernel version:$kernel_version from the system.\n\n"
+			printf "Please give the full modules directory name to remove:"
+			read modules_version
+			if [[ $modules_version != "" ]]; then
+				remove_old_modules_dir
+				printf "\n\nRemoved modules directory:$modules_version from the system.\n\n"
+			else
+				exit 1
+			fi
+		fi
+		;;
+	-h | --help)
+		usage
+		exit 0
+		;;
+	-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

-# 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
--
2.23.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [PATCH] scripts: prune-kernel:remove old kernels and modules dir from system
@ 2019-10-30  9:54 Bhaskar Chowdhury
  2019-10-31  2:33 ` Randy Dunlap
  0 siblings, 1 reply; 31+ messages in thread
From: Bhaskar Chowdhury @ 2019-10-30  9:54 UTC (permalink / raw)
  To: rdunlap, bfields
  Cc: yamada.masahiro, michal.lkml, linux-kbuild, linux-kernel,
	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_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.


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

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index a25aa2160d47..a91010d0e2af 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -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


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

end of thread, other threads:[~2019-11-18  7:31 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-02  6:30 [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system Bhaskar Chowdhury
2019-11-05  2:03 ` Randy Dunlap
2019-11-05  2:32   ` J. Bruce Fields
2019-11-05  4:39     ` Bhaskar Chowdhury
2019-11-05  4:52       ` Bhaskar Chowdhury
2019-11-06  2:53     ` Masahiro Yamada
2019-11-06  3:10       ` Bhaskar Chowdhury
2019-11-06  4:03         ` Masahiro Yamada
2019-11-06  4:29           ` Bhaskar Chowdhury
2019-11-06  4:31       ` J. Bruce Fields
2019-11-06  4:32         ` Randy Dunlap
2019-11-06  4:42         ` Bhaskar Chowdhury
2019-11-06 19:30           ` J. Bruce Fields
2019-11-06 22:39             ` Bhaskar Chowdhury
2019-11-09  7:25               ` Masahiro Yamada
2019-11-09 11:13                 ` Bhaskar Chowdhury
2019-11-15  1:58                   ` Masahiro Yamada
2019-11-15 15:21                     ` Bhaskar Chowdhury
2019-11-18  7:30                       ` Masahiro Yamada
2019-11-05  4:33   ` Bhaskar Chowdhury
  -- strict thread matches above, loose matches on Subject: below --
2019-10-30  9:54 [PATCH] scripts: prune-kernel:remove " Bhaskar Chowdhury
2019-10-31  2:33 ` Randy Dunlap
2019-10-31  3:37   ` Bhaskar Chowdhury
2019-10-31  4:32     ` Randy Dunlap
2019-10-31  4:52       ` Bhaskar Chowdhury
2019-10-31  5:27         ` Randy Dunlap
2019-10-31  7:18           ` Bhaskar Chowdhury
2019-10-31 15:06             ` Randy Dunlap
2019-11-01  4:23               ` Bhaskar Chowdhury
2019-11-01  5:11                 ` Bhaskar Chowdhury
2019-11-01  5:45                   ` Randy Dunlap

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