Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp47866ybx; Tue, 5 Nov 2019 19:12:54 -0800 (PST) X-Google-Smtp-Source: APXvYqydMg6FK3OXVSA4symAZN6rG3VXfahC6GVCrcJpR7H90wAmzfrmOIdspEHHYab2DQfRAVmd X-Received: by 2002:a17:906:c9d8:: with SMTP id hk24mr24921490ejb.159.1573009974358; Tue, 05 Nov 2019 19:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573009974; cv=none; d=google.com; s=arc-20160816; b=alVYbE2aRIhHgWngt0OfC9ku9V3KcTk0owmB/mbIwSr/xlRTroLN/+ROilWXgeIyoj rKjMv6TEb135q3wqSZoKCmsEzfnftOBmoLP+FJrIg03/ylu5bv3UMlU5/WPBcWrAYsfE 6PuEK5FDuBOWo0iWYBpMnYEoeyGXOqNvzi+gfDzA0h+vazqqSl8cDdVmgvUSUOQJMOVM /fYlbprpa1MJQOOBSVxVaoKCAPpMn96kyKGiNhC+Wul47OSoht4O2EqOEj+bY14DBO2J YlUKx6RW9tLu/lcicTknamQejEdbwF0rJOFRKZBpJyZ6mzW0VaoQr6Y6nMsaxfhDUfFa MziA== 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:dkim-signature; bh=61rW3ZN687Kx3j+VgwRzZNWD70+TlJxx1UgOBW1jhZs=; b=oGFi++njLY0MSU3rjFGJpJKzmF0VQB12Og7S4oDho/G1cFF5Kx8jyalMA7JELE2Rk6 zmSF10BLiZizxV2t4++Xmy5NuSCj9v9d04jbS58kxTOcHg3I+oAWlXv5EvPjiNxuw5VJ sBKKiBtTAUBiF1wmynkbbnQWFuraLsJrEQbGqBv8WdhX8L4frNzIQ5v+0QF7XOmOsvdw KBRV1ORdZocnfOvB+kAj7sdeODMmKLgMusIMB2P224H3ltbT8A92lziICqKa3+iONppR W9V1EPSblDIKFfYowI2evYnq1tIKMvcE8bAdvZRBnTN/YlgQbxSpfW+xljwZtxU90PBP 27mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RlwfvW2F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si14089364eda.131.2019.11.05.19.12.31; Tue, 05 Nov 2019 19:12:54 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RlwfvW2F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731239AbfKFDKq (ORCPT + 99 others); Tue, 5 Nov 2019 22:10:46 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36163 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730562AbfKFDKp (ORCPT ); Tue, 5 Nov 2019 22:10:45 -0500 Received: by mail-pf1-f195.google.com with SMTP id v19so17733150pfm.3; Tue, 05 Nov 2019 19:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=61rW3ZN687Kx3j+VgwRzZNWD70+TlJxx1UgOBW1jhZs=; b=RlwfvW2FHvnQ+TqEQmEQXdzw9lKZuOOTOuydSdJA0wohAfLqDmCFF9z7AFR8fphKRW Bw/OXm/vlqfX0LkDGNiqXT5TG1pu/YcY+vdq7gUml4ZMzO4QgRHKRtlbehBmCJ1Fz6T+ KV1lsj5D8SeZJh37loLRcMjNlY8XkPxDdocc0SLfE8l10xgRB5nh3tRBkNczxfkzbIxm aJ5Y7Z802lg56hEdudzKNA37kmYZ+wnaRgR4gjh9ZFMwgh1WzVxNh6lfRMU5CMqEY7cF l0v+3wrL1Z4qpWsS6D9AOaPDqKnTUhqK0NP0qR/ewdTYP+RJNQatfdxOyZ2MnRrv1HYR ZV7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=61rW3ZN687Kx3j+VgwRzZNWD70+TlJxx1UgOBW1jhZs=; b=nQF2Rf4q2fmp40xpy6hM6OrVl/pQNEffbUQaoUh8E09rtT7dSqKry4bdyG9kGAp27r mfELtNfNIAQ2FeCRr4KsV6f4EayEFIVUVsdyCOBbUqXDvmEs/WZ+qKBqm42semuGbBZe DRdm64E8+RjfOAlvMZtRfpJ2/AbJHC/jBpJuH/JriKBH1c/Vyolc9s0bzWjs1I+Pk+KZ fTD2PuJuCQhBABAOZ78nTpxvxqvUY/9ogXcAoXW8725sceLOvbEciJe2nvKVTTsLBNe4 1btyxk0ivd4irmI2sBDXwricHnhKqhDc4lzPr28BHnwGaVDboYwiEbSRIoyftB/7KdVc WoJw== X-Gm-Message-State: APjAAAXDJGnCncJvP8DCxN1ePV8b9W9LnYsEziagfAAHQwWnOTN+1it/ 9YM85QUXv8Jv955vThtrMFc= X-Received: by 2002:a63:de0b:: with SMTP id f11mr242482pgg.8.1573009844516; Tue, 05 Nov 2019 19:10:44 -0800 (PST) Received: from Gentoo ([103.231.91.67]) by smtp.gmail.com with ESMTPSA id a21sm816475pjv.20.2019.11.05.19.10.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Nov 2019 19:10:43 -0800 (PST) Date: Wed, 6 Nov 2019 08:40:30 +0530 From: Bhaskar Chowdhury To: Masahiro Yamada Cc: "J. Bruce Fields" , Randy Dunlap , Michal Marek , Linux Kbuild mailing list , Linux Kernel Mailing List Subject: Re: [PATCH] scripts:prune-kernel:remove old kernels and modules dir from system Message-ID: <20191106031027.GA20442@Gentoo> References: <20191102063036.28601-1-unixbhaskar@gmail.com> <50680c37-9e85-0050-c1e1-700260a0471c@infradead.org> <20191105023243.GA16635@fieldses.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3MwIy2ne0vdjdPXF" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --3MwIy2ne0vdjdPXF Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 11:53 Wed 06 Nov 2019, Masahiro Yamada wrote: >On Tue, Nov 5, 2019 at 11:32 AM J. Bruce Fields wrote: >> >> 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. > >I am with Bruce. > >This patch is trying to replace everything >with worse code. Well,Masahiro, I won't mind dropping the idea, which you already concluded.But, would you care to let me know how worse the code seems to be???? > > >BTW. >Bruce, >Does the current script expect RHEL or something? >I do not see 'new-kernel-pkg' on my Ubuntu machine. > >It would still work with 'new-kernel-pkg: command not found' >warning. > >We could bypass it if we like. > >command -v new-kernel-pkg && new-kernel-pkg --remove $f > > > >Masahiro Yamada > > > >> > >> > 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 > > > >-- >Best Regards > >Masahiro Yamada --3MwIy2ne0vdjdPXF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEnwF+nWawchZUPOuwsjqdtxFLKRUFAl3COZ8ACgkQsjqdtxFL KRWVrAf/f7XlGHTm+DCHQQvJc/N5CFlmb0pqxDZadAw3T/yDSA7HDcGjNQlxb3Gb 9+/ald1wwaxhsFlbQ+hd0tRDPljsz6uoQlKTW+/JfBxPi+SFoojAZUhx18t7d7AK fruM+AjZ7nfIRmQil8zcIOp5U7WDJ26UveAcWwuDN/u/EsdqOCUJqOYYhph91L1W trl+5LD4NerIA8+7ULBB1wIto1Bf4F7KH3K5Qbl2aC+wLkWsEVN+VkIMjy0cTkdj q9SwT7VGmETkRa+NiUWgthM97z/mzdFafkHpPNMNyM/+Dlhww9Zc4sYF23yBzkwt xAUXFEQ2FFpIw48SYEZBAlVdQBijsw== =NThd -----END PGP SIGNATURE----- --3MwIy2ne0vdjdPXF--