linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bhaskar Chowdhury <unixbhaskar@gmail.com>
To: yamada.masahiro@socionext.com, michal.lkml@markovi.net
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	rdunlap@infradead.org, bfields@fieldses.org,
	Bhaskar Chowdhury <unixbhaskar@gmail.com>
Subject: [PATCH] scripts : prune-kernel : prune kernels generalized way
Date: Wed, 16 Oct 2019 11:43:12 +0530	[thread overview]
Message-ID: <20191016061312.10626-1-unixbhaskar@gmail.com> (raw)

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

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
Thanks, a bunch to Randy for the hand holding . :)

 scripts/prune-kernel | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)

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


             reply	other threads:[~2019-10-16  6:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16  6:13 Bhaskar Chowdhury [this message]
2019-10-16 16:08 ` [PATCH] scripts : prune-kernel : prune kernels generalized way Randy Dunlap
2019-10-17  6:19   ` Bhaskar Chowdhury
2019-10-17  6:31 Bhaskar Chowdhury
2019-10-17 20:16 ` Randy Dunlap
2019-10-17 23:00   ` Bhaskar Chowdhury
2019-10-19 13:07 [PATCH] scripts: " Bhaskar Chowdhury
2019-10-19 16:01 ` J. Bruce Fields
2019-10-19 22:16   ` Bhaskar Chowdhury

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191016061312.10626-1-unixbhaskar@gmail.com \
    --to=unixbhaskar@gmail.com \
    --cc=bfields@fieldses.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=rdunlap@infradead.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).