Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Removing bootctl entries automatically

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
fkobi
n00b
n00b
Posts: 5
Joined: Sun Jul 21, 2024 5:51 pm
Location: Poland

Removing bootctl entries automatically

  • Quote

Post by fkobi » Tue Apr 01, 2025 9:38 am

Hello everyone,

recently I have decided to clean my /efi.
It seems that I have 20 kernel entries:

# bootctl list | grep title | wc -l
21

The oldest one is 6.10.11(!).
Right now I would do something like this

# bootctl unlink gentoo-6.13.7-gentoo-dist.conf
Removed "/efi/gentoo/6.13.7-gentoo-dist/linux"
Removed "/efi/gentoo/6.13.7-gentoo-dist/microcode-amd"
Removed "/efi/gentoo/6.13.7-gentoo-dist/microcode-intel"
Removed "/efi/gentoo/6.13.7-gentoo-dist/initrd"
Removed /efi/loader/entries/gentoo-6.13.7-gentoo-dist.conf

This however is a bit tiring to do it for all the entries.
Is there a better way to delete those?
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3534
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Tue Apr 01, 2025 10:36 am

Have a single entry (maybe two for backup) and a single image file name (and another if you have an initramfs)(and maybe a second set of those for the backup entry) and then just override the image(and the initramfs) without modifying your boot entries. Have a default one that boots automatically, press F12 or whatever the shortcut for that for your EFI is to select the backup. Have a grub entry so that you don't need to mount /efi every time you just want to test the new kernel and when you decide, copy the default image (initramf) over the backup and the one(s) from /boot you tested over the default. This is how I do it. No need to mess with EFI boot entries.

The only thing is I use the grub entry for backup and don't have backup entries in the EFI menu. Only the default and the grub ones. I don't use initramfs and thus I have only a single image file in /efi aside from grub.

NOTE: if you have more than one image per kernel version set CONFIG_LOCALVERSION to different values for those as they'll install modules in the same place (/lib/modules<kernel version>) if you don't set a different local version for each one and this way you may break the backup.

For example I use "-default" and "-test" so that I don't mix their modules. I don't do changes to my config anymore so that's not a problem, but when I was actively modifying the config in the first months of owning this computer this is how I kept working kernels from testing ones.

Best Regards,
Georgi
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

Re: Removing bootctl entries automatically

  • Quote

Post by Hu » Tue Apr 01, 2025 1:51 pm

fkobi wrote:# bootctl list | grep title | wc -l
This could be simplified to: bootctl list | grep -c title, rather than relying on a separate wc.
fkobi wrote:# bootctl unlink gentoo-6.13.7-gentoo-dist.conf
Removed "/efi/gentoo/6.13.7-gentoo-dist/linux"
Removed "/efi/gentoo/6.13.7-gentoo-dist/microcode-amd"
Removed "/efi/gentoo/6.13.7-gentoo-dist/microcode-intel"
Removed "/efi/gentoo/6.13.7-gentoo-dist/initrd"
Removed /efi/loader/entries/gentoo-6.13.7-gentoo-dist.conf

This however is a bit tiring to do it for all the entries.
Is there a better way to delete those?
logrusx addressed how you can avoid this situation in the future. Are you also asking for a way to clean up all the old entries without typing them all individually? If yes, consider using a bit of shell text processing. As an untested starting point:

Code: Select all

# Assume that . has the relevant conf files
printf '%s\n' *-gentoo-dist.conf > /tmp/all-installed-kernels
# Use $EDITOR to remove the ones you want to keep.
$EDITOR /tmp/all-installed-kernels
# Review the file to verify it does not contain anything important.  Check that
# the uname of the running kernel is NOT printed, as a baseline safety.
# Further review may be warranted.
grep -F "$(uname -r)" /tmp/all-installed-kernels
# Repeatedly invoke `bootctl unlink` to remove them.  If bootctl can take more
# than one kernel at a time, remove the `-n1`.
xargs -n1 -tr -a /tmp/all-installed-kernels bootctl unlink
This is completely untested, and is based on what I inferred from your post. Review its plans carefully before executing.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3534
Joined: Thu Feb 22, 2018 2:29 pm

Re: Removing bootctl entries automatically

  • Quote

Post by logrusx » Tue Apr 01, 2025 3:45 pm

Hu wrote:logrusx addressed how you can avoid this situation in the future. Are you also asking for a way to clean up all the old entries without typing them all individually?
Yes, it seems I didn't initially understand OP... :)

Best Regards,
Georgi
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Apr 01, 2025 4:41 pm

Nor did I. It's not clear to me whether he was complaining about how much trouble he had to go through right now to wipe out all the old entries or complaining about the need to do regular maintenance on this, but I decided to post my fragment for a bulk cleanup in case it was useful.
Top
Post Reply

5 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic