Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp196655ybx; Mon, 4 Nov 2019 18:34:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxy4ZSlk62YQgOgxZBZZzgN9H+c1N3I8vWJ9ye5cccFWlQifEGfJGT91nBX6A0dszVFacxv X-Received: by 2002:a05:6402:1718:: with SMTP id y24mr733400edu.220.1572921262191; Mon, 04 Nov 2019 18:34:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572921262; cv=none; d=google.com; s=arc-20160816; b=M3BnviKAb3Z1Rh1iCqWyK8Ou9arHXCKo6afsayUHJmYANWHlh0pI/T8rzpSoMYrTbw SLBqthbGXHDjkhPyjR13Q/zItl0bsORFY1Nh8qRMi7b0cNmHv/eqkF5XGiusqq6oDWCf MH7upOSeB5sQQ75bl6bcX8Vs2rJGiifWvAdIX0IxRAZHk9egpc7txPcx63UNn+L6Ch5d S9M/5jlyqHX6LThHC4bMYGVINU+49NNyXbYH6SMA3Z7E/IrxHx8rC7DJuHuNTxxRk+Wr H0/v1QCfBFzTvjGpGj5e+H3E93gQFEj6F6HqhPk5esFh8u7eBgqnB5QLODIsatKL43Jq NBuw== 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=/TtB0Zv5lTWGfqJ9oq4+WWvdrRnnljMgadbtupc52Og=; b=Nn9c2BILH2ehOw+ZQc8XKTFDQjcDkukj4cYED3GfgxmIbpFEV2bAxMV52Mu2Tfufor XHDtJB7KWZDOlFTYhT8oBDG6tADdJPzKd5A/QisDbOA3hkMcCxviLWQpeXp4wEGsbvCW t8wPPIfgsHQQfN6PHmuXJHNPc9Koeoebm5SPT2CYyrQjlqZ1kk/AiXEKmKRjG5QPeV2r Hxp4YgWUzqAx6y1860tOYGVLa6A1KYc3rlOc77u6Y+EQEMrjU12YzIAmlaW8Jq0AXios e2nPRjWcStaILC2tB862BHhlVkevB/k8qOzjBKekOvCkGri1WATIRiMVbT4lok0ielI9 o23Q== 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 h5si9277755edj.25.2019.11.04.18.33.58; Mon, 04 Nov 2019 18:34:22 -0800 (PST) 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 S1730462AbfKECcp (ORCPT + 99 others); Mon, 4 Nov 2019 21:32:45 -0500 Received: from fieldses.org ([173.255.197.46]:60368 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729830AbfKECco (ORCPT ); Mon, 4 Nov 2019 21:32:44 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 993A81C19; Mon, 4 Nov 2019 21:32:43 -0500 (EST) Date: Mon, 4 Nov 2019 21:32:43 -0500 From: "J. Bruce Fields" To: Randy Dunlap Cc: Bhaskar Chowdhury , yamada.masahiro@socionext.com, michal.lkml@markovi.net, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system Message-ID: <20191105023243.GA16635@fieldses.org> References: <20191102063036.28601-1-unixbhaskar@gmail.com> <50680c37-9e85-0050-c1e1-700260a0471c@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50680c37-9e85-0050-c1e1-700260a0471c@infradead.org> 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 Mon, Nov 04, 2019 at 06:03:13PM -0800, Randy Dunlap wrote: > On 11/1/19 11:30 PM, Bhaskar Chowdhury wrote: > > 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 > > --- > > scripts/prune-kernel | 82 +++++++++++++++++++++++++++++++++++--------- > > 1 file changed, 65 insertions(+), 17 deletions(-) > > Hi, > I believe that this script now does what the patch author intends it to do. > It does have a few whitespace issues, but no big deals. (see below) My original comment stands: looks like it prompts for full module path and kernel versions which means it's no more convenient than just doing an "ls" and then removing the ones you want to. (In fact, with "rm" you'd also get the benefit of tab completion....) It's quite different from the original script and I don't really see the advantage. --b. > > Tested-by: Randy Dunlap > > > > 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" > > space after ':' > > drop one \n above. > > > + 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" > > space after ':' > > drop one \n above. > > > + 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: > > > > OK, the former script's loop is removed.. good. > But the 2 preceding blank lines are not removed, so the script > now ends with 2 unnecessary blank lines. > > > -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 > > -- > > > -- > ~Randy