UbuntuやDebianにおいて古いKernelイメージの削除方法

Linux

UbuntuやDebianを運用していくと、古いkernelのイメージが溜まっていきます。気持ち悪いので古いのは消します。

まずは、一応、最新のkernelでシステムが起動していることを確認しておきましょう。

root@dell /h/matsu# ls /boot/
System.map-5.0.0-37-generic  System.map-5.3.0-26-generic  config-5.3.0-24-generic  efi/   initrd.img-5.0.0-37-generic  initrd.img-5.3.0-26-generic  vmlinuz-5.0.0-37-generic  vmlinuz-5.3.0-26-generic
System.map-5.3.0-24-generic  config-5.0.0-37-generic      config-5.3.0-26-generic  grub/  initrd.img-5.3.0-24-generic  lost+found/                  vmlinuz-5.3.0-24-generic
root@dell /h/matsu# dpkg -l |grep kernel
ii  kmod                                  26-1ubuntu1                            amd64        tools for managing Linux kernel modules
ii  libaio1:amd64                         0.3.112-5                              amd64        Linux kernel AIO access library - shared library
ii  libdrm-amdgpu1:amd64                  2.4.99-1ubuntu1                        amd64        Userspace interface to amdgpu-specific kernel DRM services -- runtime
ii  libdrm-common                         2.4.99-1ubuntu1                        all          Userspace interface to kernel DRM services -- common files
ii  libdrm-intel1:amd64                   2.4.99-1ubuntu1                        amd64        Userspace interface to intel-specific kernel DRM services -- runtime
ii  libdrm-nouveau2:amd64                 2.4.99-1ubuntu1                        amd64        Userspace interface to nouveau-specific kernel DRM services -- runtime
ii  libdrm-radeon1:amd64                  2.4.99-1ubuntu1                        amd64        Userspace interface to radeon-specific kernel DRM services -- runtime
ii  libdrm2:amd64                         2.4.99-1ubuntu1                        amd64        Userspace interface to kernel DRM services -- runtime
ii  linux-firmware                        1.183.3                                all          Firmware for Linux kernel drivers
ii  linux-generic                         5.3.0.26.30                            amd64        Complete Generic Linux kernel and headers
ii  linux-headers-5.3.0-24                5.3.0-24.26                            all          Header files related to Linux kernel version 5.3.0
ii  linux-headers-5.3.0-24-generic        5.3.0-24.26                            amd64        Linux kernel headers for version 5.3.0 on 64 bit x86 SMP
ii  linux-headers-5.3.0-26                5.3.0-26.28                            all          Header files related to Linux kernel version 5.3.0
ii  linux-headers-5.3.0-26-generic        5.3.0-26.28                            amd64        Linux kernel headers for version 5.3.0 on 64 bit x86 SMP
ii  linux-headers-generic                 5.3.0.26.30                            amd64        Generic Linux kernel headers
rc  linux-image-4.15.0-72-generic         4.15.0-72.81                           amd64        Signed kernel image generic
rc  linux-image-4.4.0-170-generic         4.4.0-170.199                          amd64        Signed kernel image generic
ii  linux-image-5.0.0-37-generic          5.0.0-37.40                            amd64        Signed kernel image generic
ii  linux-image-5.3.0-24-generic          5.3.0-24.26                            amd64        Signed kernel image generic
ii  linux-image-5.3.0-26-generic          5.3.0-26.28                            amd64        Signed kernel image generic
ii  linux-image-generic                   5.3.0.26.30                            amd64        Generic Linux kernel image
rc  linux-modules-4.15.0-72-generic       4.15.0-72.81                           amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-170-generic       4.4.0-170.199                          amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-modules-5.0.0-37-generic        5.0.0-37.40                            amd64        Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii  linux-modules-5.3.0-24-generic        5.3.0-24.26                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-modules-5.3.0-26-generic        5.3.0-26.28                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.15.0-72-generic 4.15.0-72.81                           amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-170-generic 4.4.0-170.199                          amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.0.0-37-generic  5.0.0-37.40                            amd64        Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.3.0-24-generic  5.3.0-24.26                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.3.0-26-generic  5.3.0-26.28                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-signed-generic                  5.3.0.26.30                            amd64        Complete Signed Generic Linux kernel and headers (dummy transitional package)
ii  rsyslog                               8.1901.0-1ubuntu4                      amd64        reliable system and kernel logging daemon

sudo apt-get --purge autoremove を打つだけです。

root@dell /h/matsu# sudo apt-get --purge autoremove

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-image-5.0.0-37-generic* linux-modules-5.0.0-37-generic* linux-modules-extra-5.0.0-37-generic*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 253 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 126511 files and directories currently installed.)
Removing linux-modules-extra-5.0.0-37-generic (5.0.0-37.40) ...
Removing linux-image-5.0.0-37-generic (5.0.0-37.40) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.0.0-37-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-5.3.0-26-generic
Found kernel: /vmlinuz-5.3.0-24-generic
Found kernel: /vmlinuz-5.0.0-37-generic
Replacing config file /run/grub/menu.lst with new version
Found kernel: /vmlinuz-5.3.0-26-generic
Found kernel: /vmlinuz-5.3.0-24-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done

/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.0-26-generic
Found initrd image: /boot/initrd.img-5.3.0-26-generic
Found linux image: /boot/vmlinuz-5.3.0-24-generic
Found initrd image: /boot/initrd.img-5.3.0-24-generic
done
Removing linux-modules-5.0.0-37-generic (5.0.0-37.40) ...
(Reading database ... 120073 files and directories currently installed.)
Purging configuration files for linux-modules-5.0.0-37-generic (5.0.0-37.40) ...
Purging configuration files for linux-modules-extra-5.0.0-37-generic (5.0.0-37.40) ...
dpkg: warning: while removing linux-modules-extra-5.0.0-37-generic, directory '/lib/modules/5.0.0-37-generic/kernel/drivers/net/wireless' not empty so not removed
Purging configuration files for linux-image-5.0.0-37-generic (5.0.0-37.40) ...
rmdir: failed to remove '/lib/modules/5.0.0-37-generic': Directory not empty

古いKernelが消えました。

root@dell /h/matsu# dpkg -l |grep kernel
ii  kmod                                  26-1ubuntu1                            amd64        tools for managing Linux kernel modules
ii  libaio1:amd64                         0.3.112-5                              amd64        Linux kernel AIO access library - shared library
ii  libdrm-amdgpu1:amd64                  2.4.99-1ubuntu1                        amd64        Userspace interface to amdgpu-specific kernel DRM services -- runtime
ii  libdrm-common                         2.4.99-1ubuntu1                        all          Userspace interface to kernel DRM services -- common files
ii  libdrm-intel1:amd64                   2.4.99-1ubuntu1                        amd64        Userspace interface to intel-specific kernel DRM services -- runtime
ii  libdrm-nouveau2:amd64                 2.4.99-1ubuntu1                        amd64        Userspace interface to nouveau-specific kernel DRM services -- runtime
ii  libdrm-radeon1:amd64                  2.4.99-1ubuntu1                        amd64        Userspace interface to radeon-specific kernel DRM services -- runtime
ii  libdrm2:amd64                         2.4.99-1ubuntu1                        amd64        Userspace interface to kernel DRM services -- runtime
ii  linux-firmware                        1.183.3                                all          Firmware for Linux kernel drivers
ii  linux-generic                         5.3.0.26.30                            amd64        Complete Generic Linux kernel and headers
ii  linux-headers-5.3.0-24                5.3.0-24.26                            all          Header files related to Linux kernel version 5.3.0
ii  linux-headers-5.3.0-24-generic        5.3.0-24.26                            amd64        Linux kernel headers for version 5.3.0 on 64 bit x86 SMP
ii  linux-headers-5.3.0-26                5.3.0-26.28                            all          Header files related to Linux kernel version 5.3.0
ii  linux-headers-5.3.0-26-generic        5.3.0-26.28                            amd64        Linux kernel headers for version 5.3.0 on 64 bit x86 SMP
ii  linux-headers-generic                 5.3.0.26.30                            amd64        Generic Linux kernel headers
rc  linux-image-4.15.0-72-generic         4.15.0-72.81                           amd64        Signed kernel image generic
rc  linux-image-4.4.0-170-generic         4.4.0-170.199                          amd64        Signed kernel image generic
ii  linux-image-5.3.0-24-generic          5.3.0-24.26                            amd64        Signed kernel image generic
ii  linux-image-5.3.0-26-generic          5.3.0-26.28                            amd64        Signed kernel image generic
ii  linux-image-generic                   5.3.0.26.30                            amd64        Generic Linux kernel image
rc  linux-modules-4.15.0-72-generic       4.15.0-72.81                           amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-170-generic       4.4.0-170.199                          amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-modules-5.3.0-24-generic        5.3.0-24.26                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-modules-5.3.0-26-generic        5.3.0-26.28                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.15.0-72-generic 4.15.0-72.81                           amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-170-generic 4.4.0-170.199                          amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.3.0-24-generic  5.3.0-24.26                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.3.0-26-generic  5.3.0-26.28                            amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-signed-generic                  5.3.0.26.30                            amd64        Complete Signed Generic Linux kernel and headers (dummy transitional package)
ii  rsyslog                               8.1901.0-1ubuntu4                      amd64        reliable system and kernel logging daemon

root@dell /h/matsu# ls /boot/
System.map-5.3.0-24-generic  config-5.3.0-24-generic  efi/   initrd.img-5.3.0-24-generic  lost+found/               vmlinuz-5.3.0-26-generic
System.map-5.3.0-26-generic  config-5.3.0-26-generic  grub/  initrd.img-5.3.0-26-generic  vmlinuz-5.3.0-24-generic
root@dell /h/matsu#

Comments

タイトルとURLをコピーしました