You are not logged in.

#1 2013-08-22 05:07:55

pelpix
Member
Registered: 2013-07-06
Posts: 23

How do I kexec unbelievably early without my cheap, broken hack?

In my vps, the hypervisor is set up in a way that does not allow custom kernels.  I solved this using kexec.  Looking to make it convenient, I invented a way to kexec so early that the entire system couldn't tell.  As a quick hack, I replaced /usr/sbin/init with a script to run my kexec.  It worked SO WELL that I can even seamlessly use the unmodified repo kernel updates.

My question is: how do I accomplish this in a way that isn't blindingly stupid?

Last edited by pelpix (2013-08-22 05:16:30)

Offline

#2 2013-08-22 05:11:13

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

The moment you decided to use kexec to work around the custom kernel limitation, it became a hack.

But if it were me, I would put all the necessary components into an initramfs and then have the /bin/init in there simply issue the kexec.  So that way it would load the kernel, and then just suddenly switch, no other system boot up would occur.

Offline

#3 2013-08-22 05:15:29

pelpix
Member
Registered: 2013-07-06
Posts: 23

Re: How do I kexec unbelievably early without my cheap, broken hack?

WonderWoofy wrote:

The moment you decided to use kexec to work around the custom kernel limitation, it became a hack.

But if it were me, I would put all the necessary components into an initramfs and then have the /bin/init in there simply issue the kexec.  So that way it would load the kernel, and then just suddenly switch, no other system boot up would occur.

That's what I did. I'm asking if there's a way to do it without completely overwriting init.

Offline

#4 2013-08-22 05:17:03

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

Right, because now that I think about it, if you had replaced your /sbin/init in the system with that script it would totally break the system…

Offline

#5 2013-08-22 05:22:17

pelpix
Member
Registered: 2013-07-06
Posts: 23

Re: How do I kexec unbelievably early without my cheap, broken hack?

WonderWoofy wrote:

Right, because now that I think about it, if you had replaced your /sbin/init in the system with that script it would totally break the system…

Yup. Need a way to Exec it that early with no breakage.  Think renaming init and putting the renamed init at the bottom of the script would work?

Offline

#6 2013-08-22 05:28:37

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

pelpix wrote:

Think renaming init and putting the renamed init at the bottom of the script would work?

I guess so, but I don't really see the point.  When you kexec, you should be loading a whole different kernel and initarmfs anyway, right?  So what does it matter if the /sbin/init kexec script is the only thing that is really run?  It is just a quick and dirty temporary environment that comes up simply to reboot into a different kernel.

Offline

#7 2013-08-22 05:34:51

pelpix
Member
Registered: 2013-07-06
Posts: 23

Re: How do I kexec unbelievably early without my cheap, broken hack?

But isn't the init program needed to start some system apps? Won't those fail to start because init is missing from the filesystem?  I thought the actual init bin file was on the drive, not in the initramfs.  If it wasn't, how am I replacing it?

Last edited by pelpix (2013-08-22 05:36:52)

Offline

#8 2013-08-22 05:39:41

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

Well, I was thinking that your setup would involve two initramfs'.  You have the one that launches with the provided kernel, and the /sbin/init simply launches a kexec.  Then a whole separate initramfs (to match the custom kernel) is loaded and then a whole separate /sbin/init is launched with it.

Ideally, the first initramfs won't even try to mount the filesystems or need to recognize their existence.  Having mounted filesystems when you launch the kexec can be akin to doing a hard shutdown, which is not a good thing to do every time you boot the machine.  So really that first initramfs should have as little capabilities as possible, while still allowing it to launch kexec.

That was my thinking anyway...

Offline

#9 2013-08-22 05:43:40

pelpix
Member
Registered: 2013-07-06
Posts: 23

Re: How do I kexec unbelievably early without my cheap, broken hack?

WonderWoofy wrote:

Well, I was thinking that your setup would involve two initramfs'.  You have the one that launches with the provided kernel, and the /sbin/init simply launches a kexec.  Then a whole separate initramfs (to match the custom kernel) is loaded and then a whole separate /sbin/init is launched with it.

Ideally, the first initramfs won't even try to mount the filesystems or need to recognize their existence.  Having mounted filesystems when you launch the kexec can be akin to doing a hard shutdown, which is not a good thing to do every time you boot the machine.  So really that first initramfs should have as little capabilities as possible, while still allowing it to launch kexec.

That was my thinking anyway...

Interesting thinking. I must investigate this further.

Offline

#10 2013-08-22 06:04:31

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

I would be interested to know what you end up with here… hack or not, this topic is intruiging.

Offline

#11 2013-08-22 16:31:46

pelpix
Member
Registered: 2013-07-06
Posts: 23

Re: How do I kexec unbelievably early without my cheap, broken hack?

Sorry to bother you, but do you have any tips as to how to pack kexec into the main kernel initramfs?  I've never made such a wildly custom initramfs before, because I've never needed to.

How would I go about getting it to be generated on kernel update without modifying the kernel package?

Last edited by pelpix (2013-08-22 16:47:27)

Offline

#12 2013-08-22 17:42:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: How do I kexec unbelievably early without my cheap, broken hack?

You would have to include kexec and all the things it depends on in order to make it work.  Mkinitpcio will actually do this for you if simply put it in the BINARIES variable.  So I think it would probably be easiest to just rip bits and pieces from mkinitcpio in order to achieve what you need.  Otherwise, you could just modify mkinitcpio itself in order to get it to include these basics.  That is, create your own init script and just have the bare minimum of stuffs (so basically no hooks… maybe base, and nothing but "BINARIES=/usr/bin/kexec").

Of course, this creates the issue of how your mkinitpcio would be generated in the event that you rebuild your custom kernel.

Otherwise, you could just create a super minimal mkinitcpio build as is, then unpack, modify /sbin/init, then repack it.

Offline

Board footer

Powered by FluxBB