CentOS/RedHatで古いカーネルを安全に削除するpackage-cleanupコマンドです。
- インストールされているカーネル
- package-cleanupインストール
- 古いカーネルの削除
- 確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# rpm -q kernel kernel-3.10.0-327.el7.x86_64 kernel-3.10.0-327.36.3.el7.x86_64 kernel-3.10.0-514.6.2.el7.x86_64 # grubby --info=ALL index=0 kernel=/boot/vmlinuz-3.10.0-514.6.2.el7.x86_64 args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8" root=/dev/mapper/centos-root initrd=/boot/initramfs-3.10.0-514.6.2.el7.x86_64.img title=CentOS Linux (3.10.0-514.6.2.el7.x86_64) 7 (Core) index=1 kernel=/boot/vmlinuz-3.10.0-327.36.3.el7.x86_64 args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8" root=/dev/mapper/centos-root initrd=/boot/initramfs-3.10.0-327.36.3.el7.x86_64.img title=CentOS Linux (3.10.0-327.36.3.el7.x86_64) 7 (Core) index=2 kernel=/boot/vmlinuz-3.10.0-327.el7.x86_64 args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8" root=/dev/mapper/centos-root initrd=/boot/initramfs-3.10.0-327.el7.x86_64.img title=CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core) index=3 kernel=/boot/vmlinuz-0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" root=/dev/mapper/centos-root initrd=/boot/initramfs-0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c.img title=CentOS Linux (0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c) 7 (Core) index=4 non linux entry |
package-cleanupコマンドはyum-utilsに含まれています。
1 2 3 4 |
# package-cleanup -bash: package-cleanup: command not found # yum install yum-utils |
--count=
で世代数を指定します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# package-cleanup --oldkernels --count=1 Loaded plugins: fastestmirror --> Running transaction check ---> Package kernel.x86_64 0:3.10.0-327.el7 will be erased ---> Package kernel.x86_64 0:3.10.0-327.36.3.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Removing: kernel x86_64 3.10.0-327.el7 @anaconda 136 M kernel x86_64 3.10.0-327.36.3.el7 @updates 136 M Transaction Summary =================================================================================================== Remove 2 Packages Installed size: 272 M Is this ok [y/N]: |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# package-cleanup --oldkernels --count=2 Loaded plugins: fastestmirror --> Running transaction check ---> Package kernel.x86_64 0:3.10.0-327.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Removing: kernel x86_64 3.10.0-327.el7 @anaconda 136 M Transaction Summary =================================================================================================== Remove 1 Package Installed size: 136 M Is this ok [y/N]: |
1 2 3 |
# package-cleanup --oldkernels --count=3 Loaded plugins: fastestmirror No old kernels to remove |
実際に削除してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# package-cleanup --oldkernels --count=2 Loaded plugins: fastestmirror --> Running transaction check ---> Package kernel.x86_64 0:3.10.0-327.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Removing: kernel x86_64 3.10.0-327.el7 @anaconda 136 M Transaction Summary =================================================================================================== Remove 1 Package Installed size: 136 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : kernel-3.10.0-327.el7.x86_64 1/1 Verifying : kernel-3.10.0-327.el7.x86_64 1/1 Removed: kernel.x86_64 0:3.10.0-327.el7 Complete! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# rpm -q kernel kernel-3.10.0-327.36.3.el7.x86_64 kernel-3.10.0-514.6.2.el7.x86_64 # grubby --info=ALL index=0 kernel=/boot/vmlinuz-3.10.0-514.6.2.el7.x86_64 args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8" root=/dev/mapper/centos-root initrd=/boot/initramfs-3.10.0-514.6.2.el7.x86_64.img title=CentOS Linux (3.10.0-514.6.2.el7.x86_64) 7 (Core) index=1 kernel=/boot/vmlinuz-3.10.0-327.36.3.el7.x86_64 args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8" root=/dev/mapper/centos-root initrd=/boot/initramfs-3.10.0-327.36.3.el7.x86_64.img title=CentOS Linux (3.10.0-327.36.3.el7.x86_64) 7 (Core) index=2 kernel=/boot/vmlinuz-0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c args="ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" root=/dev/mapper/centos-root initrd=/boot/initramfs-0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c.img title=CentOS Linux (0-rescue-c4ec8a978ee746e09e40ce6ef7a9a79c) 7 (Core) index=3 non linux entry |
installonly_limitについて
/etc/yum.confにinstallonly_limit=3のように指定しておけば3世代管理してくれます。
ただCentOS 7のman yum.confを確認したら下記の記載がありました。
デフォルトが3だそうです。
installonly_limit Number of packages listed in installonlypkgs to keep installed at the same time. Setting to 0 disables this feature. Default is ‘3’.
ちなみにCentOS 5のman yum.confも確認したらデフォルト0なので世代管理しないです。
installonly_limit Number of packages listed in installonlypkgs to keep installed at the same time. Setting to 0 disables this feature. Default is ’0’.
ただ、yum.confには下記の記載がありました。
# Note: yum-RHN-plugin doesn’t honor this.
metadata_expire=1h
installonly_limit = 5
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
“installonlyn” pluginのインストール時に自動で追加してくれていたのかな。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# package-cleanup -h Loaded plugins: fastestmirror Usage: package-cleanup: helps find problems in the rpmdb of system and correct them usage: package-cleanup --problems or --leaves or --orphans or --oldkernels Options: Plugin Options: Yum Base Options: -h, --help show this help message and exit -t, --tolerant be tolerant of errors -C, --cacheonly run entirely from system cache, don't update cache -c [config file], --config=[config file] config file location -R [minutes], --randomwait=[minutes] maximum command wait time -d [debug level], --debuglevel=[debug level] debugging output level --showduplicates show duplicates, in repos, in list/search commands -e [error level], --errorlevel=[error level] error output level --rpmverbosity=[debug level name] debugging output level for rpm -q, --quiet quiet operation -v, --verbose verbose operation -y, --assumeyes answer yes for all questions --assumeno answer no for all questions --version show Yum version and exit --installroot=[path] set install root --enablerepo=[repo] enable one or more repositories (wildcards allowed) --disablerepo=[repo] disable one or more repositories (wildcards allowed) -x [package], --exclude=[package] exclude package(s) by name or glob --disableexcludes=[repo] disable exclude from main, for a repo or for everything --disableincludes=[repo] disable includepkgs for a repo or for everything --obsoletes enable obsoletes processing during updates --noplugins disable Yum plugins --nogpgcheck disable gpg signature checking --disableplugin=[plugin] disable plugins by name --enableplugin=[plugin] enable plugins by name --skip-broken skip packages with depsolving problems --color=COLOR control whether color is used --releasever=RELEASEVER set value of $releasever in yum config and repo files --downloadonly don't update, just download --downloaddir=DLDIR specifies an alternate directory to store packages --setopt=SETOPTS set arbitrary config and repo options --bugfix Include bugfix relevant packages, in updates --security Include security relevant packages, in updates --advisory=ADVS, --advisories=ADVS Include packages needed to fix the given advisory, in updates --bzs=BZS Include packages needed to fix the given BZ, in updates --cves=CVES Include packages needed to fix the given CVE, in updates --sec-severity=SEVS, --secseverity=SEVS Include security relevant packages matching the severity, in updates package-cleanup options: --problems List dependency problems in the local RPM database --qf=QF, --queryformat=QF Query format to use for output. --orphans List installed packages which are not available from currently configured repositories Duplicate Package Options: --dupes Scan for duplicates in your rpmdb --cleandupes Scan for duplicates in your rpmdb and remove older --noscripts disable rpm scriptlets from running when cleaning duplicates Leaf Node Options: --leaves List leaf nodes in the local RPM database --all list all packages leaf nodes that do not match leaf- regex --leaf-regex=LEAF_REGEX A package name that matches this regular expression (case insensitively) is a leaf --exclude-devel do not list development packages as leaf nodes --exclude-bin do not list packages with files in a bin dirs asleaf nodes Old Kernel Options: --oldkernels Remove old kernel and kernel-devel packages --count=KERNELCOUNT Number of kernel packages to keep on the system (default 2) --keepdevel Do not remove kernel-devel packages when removing kernels |