Forums

Skip to content

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

Question: how kexec?

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
14 posts • Page 1 of 1
Author
Message
leyvi
l33t
l33t
Posts: 719
Joined: Fri Sep 08, 2023 1:22 pm

Question: how kexec?

  • Quote

Post by leyvi » Mon Jan 06, 2025 6:19 pm

Hello Gentoo community.
I heard about this cool thing called `kexec` which allows you to (from my understanding) reload the kernel without rebooting. This is a really cool idea, but what I've discovered is that it's actually really inconvenient. The only practical way I've found of using `kexec` is through the `reboot` command, using the `-k` option. When I tried it, it didn't work too well, probably didn't configure it right, but that's not why I'm here. Is there a better way to do the same thing?
What I really want to do is this: with one command, hot-swap the kernel currently in RAM for a different one.
Not a problem that I need solving per-se, but I'd like some advice.
Top
gentoo_ram
Guru
Guru
Posts: 528
Joined: Thu Oct 25, 2007 10:04 pm
Location: San Diego, California USA

  • Quote

Post by gentoo_ram » Mon Jan 06, 2025 7:11 pm

Kexec is not about hot-swapping kernels. All processes and hardware state are maintained by the current running kernel. If you start a new one, all that needs to be done again by the new kernel. So all processes need to go down and back up again. Maybe you save a couple seconds by not re-running EFI but you're not going to save much more than that. It's just like rebooting your machine either way.

I can only think of a couple scenarios where kexec might be useful:
1. Crash dumps. Maybe start a new minimal kernel that is just there to help perform a crash dump from memory to disk for kernel debugging.
2. Linux kernel in firmware of an embedded device wants to load a new kernel off storage.
3. Chain loading kernels. Maybe full-disk encryption? Boot a non-encrypted kernel and get enough authentication to be able to un-encrypt storage containing the "true" kernel.

There are other projects looking into hot-swapping but I don't think it involves Kexec.
Top
grknight
Retired Dev
Retired Dev
Posts: 2564
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Mon Jan 06, 2025 7:33 pm

kexec is much more useful in the server hardware space where reboot times can be literal minutes to probe everything.
I would like to have this work for me, but have not had success on my servers. (Use case being using a new kernel version, it always loads the old one)
Top
leyvi
l33t
l33t
Posts: 719
Joined: Fri Sep 08, 2023 1:22 pm

  • Quote

Post by leyvi » Mon Jan 06, 2025 7:40 pm

Alright, thanks for the insight everyone!
I understand it a lot better now.
Just to clarify: there is no way that I can hot-swap my kernel?
Maybe that should be a feature.
Top
grknight
Retired Dev
Retired Dev
Posts: 2564
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Mon Jan 06, 2025 7:46 pm

leyvi wrote:Alright, thanks for the insight everyone!
I understand it a lot better now.
Just to clarify: there is no way that I can hot-swap my kernel?
Maybe that should be a feature.
You cannot hot-swap a kernel because it is running the disks and other hardware and running processes depend on it. It would be like swapping aircraft mid-flight.

You can hot-patch a kernel using special tools. Patching a live kernel is not for the feint of heart and requires extremely tight conditions including the build tools being the same and the kernel minimally changed.
Top
leyvi
l33t
l33t
Posts: 719
Joined: Fri Sep 08, 2023 1:22 pm

  • Quote

Post by leyvi » Tue Jan 07, 2025 5:29 am

Maybe the kernel devs should change that.
I'll bet there's a bunch of important structures in the kernel that represent hardware, processes, memory, etc and that's (from my understanding) the limiting factor. I wonder: Rust has these traits called `From<>` and `Into<>`, maybe we could make these critical structs somehow polymorphic (or more realistically, make it so that one struct can be made `::from()` the equivalent struct from a different kernel version). I imagine that these structs rarely change that much. Pointers to these structures could be passed to the new kernel, which could move them out of the way, somewhere else in kernel space, while it initializes, then these structs could be morphed into the proper types for that kernel version. Just an idea.
While all this happens, I seem to remember a signal (was it `SIGHALT`?) that can "pause" a process, maybe this could be used to block all processes in userspace while the kernel hot-swaps?
I seriously hope this isn't completely deluded.
Top
gentoo_ram
Guru
Guru
Posts: 528
Joined: Thu Oct 25, 2007 10:04 pm
Location: San Diego, California USA

  • Quote

Post by gentoo_ram » Tue Jan 07, 2025 7:00 am

Is it theoretically possible? Sure, I suppose so. But it would be a pretty complicated engineering effort. And given the number of platforms the Linux kernel runs on, very, very tricky. It would take hardware support which might only be possible on some specific hardware platforms. The question is: who would use this and would they rather have other solutions that might be more useful?

Obviously, high availability servers would be an interested demographic. But maybe they'd be more interested in engineering effort getting spent on more distributed computing type projects. Think clusters of computers working together. That might give you higher overall service availability.

Or maybe you'd treat it more like when you suspend a computer and bring it out of sleep. Except you suspend with one kernel version, write state to swap, block all hardware operations, then restart with a new kernel and resume the state from non-volatile storage. It wouldn't be hot-swapping, but it could be faster than a full reboot.
Top
leyvi
l33t
l33t
Posts: 719
Joined: Fri Sep 08, 2023 1:22 pm

  • Quote

Post by leyvi » Tue Jan 07, 2025 8:17 am

Huh.
All these ideas are certainly interesting.
I hope a kernel dev stumbles across this thread, I think that if these features were included in the kernel, it could be nice quality of life improvement for everyone. Obviously, like gentoo_ram said, high-availability servers, mainframes, and supercomputers could be very interested in this, but also, think of it like this: more mainstream distributions like Fedora could integrate it with their package managers to allow for full system updates without a reboot. Think of it: just run `sudo dnf upgrade` (or whatever they do) and your kernel automagically gets upgraded, no reboot required. Could be great for small security updates or performance optimizations.
They would probably want to implement it on AMD64 first, then ARM64, then RISCV64, given those are some of the most used architectures. More obscure architectures like MIPS and x86 could come later.
Would also be nice to have on Android. Kernel version bumps on GrapheneOS always make my phone reboot way slower.
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

Re: Question: how kexec?

  • Quote

Post by Goverp » Tue Jan 07, 2025 10:29 am

leyvi wrote:... What I really want to do is this: with one command, hot-swap the kernel currently in RAM for a different one.
Not a problem that I need solving per-se, but I'd like some advice.
As others have said, it's not hot-swap, it's reboot without the BIOS/EFI stage. The new kernel does not have to be the same as the previous one, but it does have to be Linux.
On my desktop that's something between 5 and 10 seconds off a 20-40 second boot (I'm guessing, on another box, and no stop watch...). It's useful when running "git bisect", when the time saved accumulates!
To change kernels, using the Gentoo setup for OpenRc (I think it should also work for Systemd, but I don't use that), you configure /etc/kexec.conf, start the kexec service, and then reboot. I think there's some way to pass the name of the desired new kernel in the service start, but I've not tried it.
Alternatively, you should be able to load a new kernel with "kexec -l <kernelname> ...." with other appropriate parameters, and then issue "reboot -k".
Greybeard
Top
Hu
Administrator
Administrator
Posts: 24395
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Jan 07, 2025 1:29 pm

Kpatch and similar mechanisms for applying minor (usually security) fixes to a running kernel were already years in the making have substantial limitations on when they can be used. A hot kernel upgrade would avoid the need to use those tools, so it seems reasonable to think that if hot kernel upgrade were easy, that would have been developed instead of these limited and finicky mechanisms. I think gentoo_ram's comment is on point that this is a massive amount of work. Even user-space checkpointing of individual programs is rarely done due to the workload and ongoing test requirements, and that would be a substantially easier project than swapping out a running kernel.

I expect the kernel developers have at least idly thought of this years ago, and promptly written it off as a massive amount of trouble for the gains it would bring them.
Top
leyvi
l33t
l33t
Posts: 719
Joined: Fri Sep 08, 2023 1:22 pm

  • Quote

Post by leyvi » Tue Jan 07, 2025 2:15 pm

Yeah, Hu is probably right.
Still fun to think about though.
Top
gentoo_ram
Guru
Guru
Posts: 528
Joined: Thu Oct 25, 2007 10:04 pm
Location: San Diego, California USA

  • Quote

Post by gentoo_ram » Tue Jan 07, 2025 6:39 pm

Ironically, this type of kernel hot-swap would probably be more feasible using more of a micro-kernel type of design at least in theory. As long as the dependencies between the different parts of the kernel were minimized then I bet you'd be able to, say, replace some problematic hardware driver relatively independently of other parts of the kernel. Or maybe there's a memory bug in the IPv4 TCP packet parser. Maybe you could replace just that component. That's what a micro-kernel is all about.

I say ironically because Linus himself famously railed against the micro-kernel design as an acedemic computer scientist's fairy tale of inefficiencies. And thus we are left with the "optimized" monolithic kernel that Linux is today that requires a restart in order to update.
Top
hujuice
Guru
Guru
User avatar
Posts: 354
Joined: Tue Oct 16, 2007 12:57 pm
Location: Nicosia, Cyprus

  • Quote

Post by hujuice » Mon Jan 20, 2025 11:50 am

grknight wrote:kexec is much more useful in the server hardware space where reboot times can be literal minutes to probe everything.
I would like to have this work for me, but have not had success on my servers. (Use case being using a new kernel version, it always loads the old one)
I was using kexec years ago, with easy success. I don't have any memory or saved configurations now.
HUjuice
Those who lack character must at least have a method.
Chi non ha carattere, deve pur avere un metodo.
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

  • Quote

Post by Goverp » Mon Jan 20, 2025 6:05 pm

I had it broken for some time, turning out to be a bug in kexec-tools on AMD Zen 3 cpus that was recently fixed. I had it working with the patch from that bug, but not as of the last time I updated my system (a couple of weeks ago) without the patch.
Greybeard
Top
Post Reply

14 posts • Page 1 of 1

Return to “Kernel & Hardware”

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