Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2137376ybg; Sat, 19 Oct 2019 09:02:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzA/ENT3vr64C/rEiWvfS8Ga8rBpSxFpciGZiaFE8FmJ4SzHPp4rkNGLcizJk8+97Ou4yoD X-Received: by 2002:a05:6402:120c:: with SMTP id c12mr15777029edw.119.1571500931818; Sat, 19 Oct 2019 09:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571500931; cv=none; d=google.com; s=arc-20160816; b=LbiQovGBsssC6yc3HHpaFI/8fpsdtDUjayq7Hd6OrR4n3BQcAPVBSZlcZjZJn9DALg q2E6jcuPle7GMrcPejx5a2tQxyg7e1phhQgb+xJ8dvx0yTSB7GbL2LvYBUfjMbBJAzwe lDlwyl8+M8RYJrYT9XTPbmE+PrQDmvxKEgEuLqY0771deadl18HhmflZ9BChM7Sk6w/v g//I+g26x91W4hJEXMeogjZMqO0sTjxUWH7BqowlEaD069oaDj87vsKR/vkA4Ecg0tmY vJOV33IquaWE7ROB5JZeBUl6k0QSdjXZr5u4vYA6NackaB7Ot42li7BMocEn3/68eypV kr+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=XuoTgEYPr8VhXhYawdSx5H0PJEXpBbBILlEERNknPTk=; b=S49xshGq45PVSETeaJhYaN+UkD+l8E6PmgdkqPKEIO8DmfZcjdsgb12GvaPb5BDFo2 +cO4jy9BWFbd/ovfg1TVz5sVJppEDZxFntFBmWAk6i2YXHImUrjoh7iEldVkUJm5HmZA BnBYxzSv0adbryq96KIrYTI98uJZdD+nso7+nK5C6jzydIpSIsOYY0c5Ahomtt2gNIaZ 0c1PmYtHN0YvCSwOCPJb0ZBz/UjE2wo3EKC6WxGceQklcaRc/Mn9OXzhE8Xm1kO22Nan ulRFN5DxI8TN/4rWKfBx8wYF9tPXbAXUstp5BEYuhq7Gp4ZsJNiL4GFq1Jtut4F9O2Yy wFuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s7si6329354edd.290.2019.10.19.09.01.48; Sat, 19 Oct 2019 09:02:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726106AbfJSQBn (ORCPT + 99 others); Sat, 19 Oct 2019 12:01:43 -0400 Received: from fieldses.org ([173.255.197.46]:39520 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725924AbfJSQBn (ORCPT ); Sat, 19 Oct 2019 12:01:43 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 5DF6A1C95; Sat, 19 Oct 2019 12:01:42 -0400 (EDT) Date: Sat, 19 Oct 2019 12:01:42 -0400 From: "J. Bruce Fields" To: Bhaskar Chowdhury Cc: yamada.masahiro@socionext.com, michal.lkml@markovi.net, rdunlap@infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] scripts: prune-kernel : prune kernels generalized way Message-ID: <20191019160142.GA31839@fieldses.org> References: <20191019130722.8067-1-unixbhaskar@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191019130722.8067-1-unixbhaskar@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 19, 2019 at 06:37:22PM +0530, Bhaskar Chowdhury wrote: > This patch will remove old kernel from the system in a selective way. Please don't comment out code, just delete it, git's there to keep the old code. There's some redundant code that should be inside a loop. A little more detail in the changelog might be useful to those of us who are lazy about reading bash script.... Looks like this just prompts for each individual delete? Actually it looks like it requires the user to enter the module path and kernel version for each one which makes it not much more convenient use than a bare "ls" and "rm". I personally use this in unattended scripts. I mean, I don't really care what we do with this, as I use my own copy of the script, so whatever's useful to more people is fine. But if somebody does actually use it as-is, it'd be nicer to keep the current behavior and add an option ("-i" or something) for the interactive behavior. --b. > > Signed-off-by: Bhaskar Chowdhury > --- > scripts/prune-kernel | 86 ++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 72 insertions(+), 14 deletions(-) > > diff --git a/scripts/prune-kernel b/scripts/prune-kernel > index e8aa940bc0a9..9d839a4e4539 100755 > --- a/scripts/prune-kernel > +++ b/scripts/prune-kernel > @@ -5,17 +5,75 @@ > # 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 > +#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_version > +} > + > +function remove_old_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 == "" ]];then > + 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 == "" ]];then > + printf "You have forgotten to give the modules dir to remove" > +else > + remove_old_modules_dir > +fi > + > +printf "\n\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 "Please give the full modules directory name to remove: %s" > + read modules_version > + remove_old_modules_dir > + printf "\n\n\n Removed kernel version:$kernel_version and associated modules:$modules_version ..Done \n\n" > + elif [[ $response == "N" ]];then > + exit 1 > + fi > + done > -- > 2.21.0