0

I recently reinstalled CentOS 7 on a lab/development machine. I wanted to keep the /home partition from the previous installation, so I manually configured the partitioning to allow me to do that. In the process, I accidentally also kept the previous installation's /boot partition.

After installation was successful, I have a very busy Grub2 boot screen. In addition to my "new" clean CentOS install, all of my old kernel images appear in the boot screen:

CentOS Linux (3.10.0-693.11.1.el7.x86_64) 7 (Core) CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core) CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core) <--- this is the new/reinstalled OS CentOS Linux (3.10.0-693.11.1.el7.x86_64.debug) 7 (Core) CentOS Linux (0-rescue-7859fc0fbe934b91b11ea69046b5d787) 7 (Core) CentOS Linux (0-rescue-6c92bef5457049e5a42e5609c540d753) 7 (Core) CentOS Linux (0-rescue-e7a05dc4cdda4e778a344945ef1ed391) 7 (Core) 

Simply running package-cleanup won't work, because there is really only one kernel installed (as far as the new OS is concerned):

$ package-cleanup --oldkernels --count=1 No old kernels to remove $ uname -r 3.10.0-693.el7.x86_64 $ rpm -qa kernel* kernel-debug-devel-3.10.0-693.11.6.el7.x86_64 kernel-3.10.0-693.el7.x86_64 kernel-headers-3.10.0-693.11.6.el7.x86_64 kernel-tools-libs-3.10.0-693.el7.x86_64 kernel-tools-3.10.0-693.el7.x86_64 

Thus, I don't believe this is a dupe of regular "how do I clean up my /boot partition?" questions (such as How do I safely delete old kernel versions in CentOS 7?)

Normally I'd be fine with just dealing with a messy Grub2 menu, but my /boot partition only has 11 MiB left, so I'm unable to update my kernel.

I'm not sure what is safe to delete from the /boot partition. How do I clean it up when package-cleanup won't?

2
  • 1
    Assuming your reused the /boot partition instead of created a second partition? Commented Jan 5, 2018 at 21:57
  • 1
    @jdwolf Correct. Sorry I didn’t make that clear. Commented Jan 5, 2018 at 21:59

2 Answers 2

2

You can use yum whatprovides /boot/* to determine which kernels are still installed and ones that are not owned by a package you can safely delete. However this assumes grub is being autoconfigured.

1
  • 1
    I'm not sure how you recreate the initrd on CentOS. But basically you can delete those and regenerate the latest one however you do it on CentOS. Commented Jan 5, 2018 at 22:05
2

jdwolf's answer produced a listing of which packages (on the old system) that provided the entries in /boot/*, but it was a bit voluminous, and not immediately apparent what files were not pertinent to my reinstall of CentOS. And example of some of the output:

$ yum whatprovides /boot/* kernel-3.10.0-693.5.2.el7.x86_64 : The Linux kernel Repo : updates Matched from: Filename : /boot/config-3.10.0-693.5.2.el7.x86_64 kernel-3.10.0-693.el7.x86_64 : The Linux kernel Repo : base Matched from: Filename : /boot/config-3.10.0-693.el7.x86_64 fwupdate-efi-9-8.el7.x86_64 : UEFI binaries used by libfwup Repo : base Matched from: Filename : /boot/efi [... truncated output ...] 

But that led me to use rpm -q --whatprovides /boot/* instead, which was much more useful to determine if the file was needed:

$ rpm -q --whatprovides /boot/* file /boot/config-3.10.0-693.11.1.el7.x86_64 is not owned by any package file /boot/config-3.10.0-693.11.1.el7.x86_64.debug is not owned by any package file /boot/config-3.10.0-693.5.2.el7.x86_64 is not owned by any package kernel-3.10.0-693.el7.x86_64 file /boot/efi is not owned by any package file /boot/elf-memtest86+-5.01 is not owned by any package file /boot/grub is not owned by any package grub2-common-2.02-0.65.el7.centos.2.noarch [... truncated output ...] 

Note that rpm -q --whatprovides doesn't print the name of the input file if it matches a package that provides it. But it does return 0 if the file is provided by a package, and 1 if the file is not provided by a package. Thus, solution was trivially:

$ for f in /boot/*; do rpm -q --whatprovides $f || rm -f $f; done file /boot/config-3.10.0-693.11.1.el7.x86_64 is not owned by any package file /boot/config-3.10.0-693.11.1.el7.x86_64.debug is not owned by any package file /boot/config-3.10.0-693.5.2.el7.x86_64 is not owned by any package kernel-3.10.0-693.el7.x86_64 file /boot/efi is not owned by any package rm: cannot remove ‘/boot/efi’: Is a directory file /boot/elf-memtest86+-5.01 is not owned by any package [... truncated output ...] $ ls -1 /boot config-3.10.0-693.el7.x86_64 efi grub grub2 initramfs-3.10.0-693.el7.x86_64.img symvers-3.10.0-693.el7.x86_64.gz System.map-3.10.0-693.el7.x86_64 vmlinuz-3.10.0-693.el7.x86_64 

After running grub2-mkconfig -o /boot/grub2/grub.cfg, my Grub menu is clean, and I have a clean /boot directory.

Note: It would probably have been better or safer to use find /boot -type f -exec ... (or perhaps find ... -xargs ...), but my solution worked fine enough since rm -f doesn't delete directories.

1
  • 1
    You made your /boot beautiful again :> Even if you borked the whole directory it should only be a matter of reinstalling linux package, generating initrd, installing grub and making grub config. Commented Jan 5, 2018 at 23:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.