Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Removing bootctl entries automatically
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
fkobi
n00b
n00b


Joined: 21 Jul 2024
Posts: 4
Location: Poland

PostPosted: Tue Apr 01, 2025 9:38 am    Post subject: Removing bootctl entries automatically Reply with quote

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?
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2889

PostPosted: Tue Apr 01, 2025 10:36 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23287

PostPosted: Tue Apr 01, 2025 1:51 pm    Post subject: Re: Removing bootctl entries automatically Reply with quote

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:
# 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.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2889

PostPosted: Tue Apr 01, 2025 3:45 pm    Post subject: Re: Removing bootctl entries automatically Reply with quote

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
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23287

PostPosted: Tue Apr 01, 2025 4:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum