Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

[Request] kexec based bootloader/grub replacement

Fri Sep 07, 2012 1:34 pm

Hello,

is it possible to create a kexec based grub-like bootloader for the Raspi so you can boot different(also non-linux) OSes and/or kernels via a menu?
I read in Chris Boot's blog that there's a working kexec-pathch for the RasPi and Berryboot does OS selection via a initramfs based menu.
I don't have the necessary skills nor the time to do this myself so I hope somebody thinks this a worthwile project.

Regards
Aydan

summers
Posts: 63
Joined: Mon Jan 30, 2012 4:27 pm

Re: [Request] kexec based bootloader/grub replacement

Sat Sep 08, 2012 2:12 pm

IIRC standard linux bootloaders like LILO and GRUB are x86 based, don't know I've heard of them working on arm machines.

Most people using arms, seem to go towards uboot. Now I just use uboot to boot directly into linux, so I'm not sure if it has a menu mode to it. Anyway uboot does have a command line, so you could explicitly type the command for whichever OS you wanted to boot, if nothing else.

To my mind though, its getting a bit silly on the raspbery pi, e.g. you need to use the binary blob to pass control from the GPU to the CPU. This closed source blob already sets up the various things you need to do before passing things across to the linux kernel. Now whilst I guess you could have the blob passing control acros to uboot (or some other boot loader), you would then effectivly go through two boot loaders - both capable of doing the same thing.

So ideally what you would do is rewrite the binary blob, such that it gave boot options and a command line. Has of course though is its closed source, so that isn't possible. So I guess which ever direction you go on RPi would end up being a bit of a botch.

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Sat Sep 08, 2012 2:20 pm

That's why I suggested kexec and something like Berryboot as the basis.
Berryboot gives you a menu to select which OS image to boot. But it doesn't allow for different kernels.
Combining a berryboot-like menu with kexec functionality would be perfect.
There would also not be any need to modify the binary blob.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: [Request] kexec based bootloader/grub replacement

Sat Sep 08, 2012 5:52 pm

It's definitely possible. What you want is a small initramfs that will boot up a menu, which will then execute kexec with commandline arguments etc.
I was going to make something like this, but when I was messing around with it, found out that back then the kernel did not support kexec.
Not sure about now though...
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Sat Sep 08, 2012 7:48 pm

it seems chris boot managed to incorporate kexec into the raspi kernel: http://www.bootc.net/archives/2012/05/2 ... pi-kernel/

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: [Request] kexec based bootloader/grub replacement

Sun Sep 09, 2012 1:11 pm

Ah awesome. Didn't realise that he had it going.
In that case, what you can do is use the bootc kernel, and make a small initramfs consisting of a shell of some sort, kexec, and a menu script that executes kexec with the kernel parameters required.

I had a base install of Raspbian down to under 100 megabytes for the initramfs, and it could go smaller still with busybox to replace some of the other programs.

My plan was to use an initramfs that would boot up into a busybox shell, with a shell script to act as the menu.
The cmdline.txt file would point to the custom initramfs kernel, but the default kernel would be used to start up the distro that you choose.
The shell script would read from a configuration file in /boot/bootmenu/ and would use kernels from /boot/ to separate the initramfs kernel from the kernel that the distro would use.
The busybox shell would also give a sort of recovery environment also, so that if you stuffed up a distro, you could use the busybox shell to do some basic troubleshooting.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Sun Sep 09, 2012 7:10 pm

It seems the current kernel has kexec enabled, but I haven't managed to actually make it work.
I tried this:

Code: Select all

kexec -l /boot/kernel.img --append="\"$(< /boot/cmdline.txt)\""
kexec -e
The only thing I got was "Starting new kernel" and nothing afterward. :(
I'm a bit out of my depth here.

Regards
Aydan

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Sun Sep 09, 2012 7:45 pm

I just tried it with:

Code: Select all

kexec -l /boot/kernel.img --append="\"$(< /proc/cmdline)\""
but that didn't work either :(

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: [Request] kexec based bootloader/grub replacement

Mon Sep 10, 2012 1:48 am

Tried with just a plain path rather than scripting ?
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

summers
Posts: 63
Joined: Mon Jan 30, 2012 4:27 pm

Re: [Request] kexec based bootloader/grub replacement

Mon Sep 10, 2012 8:21 am

SirLagz wrote:Ah awesome. Didn't realise that he had it going.
In that case, what you can do is use the bootc kernel, and make a small initramfs consisting of a shell of some sort, kexec, and a menu script that executes kexec with the kernel parameters required.

I had a base install of Raspbian down to under 100 megabytes for the initramfs, and it could go smaller still with busybox to replace some of the other programs.

My plan was to use an initramfs that would boot up into a busybox shell, with a shell script to act as the menu.
The cmdline.txt file would point to the custom initramfs kernel, but the default kernel would be used to start up the distro that you choose.
That should work.

Think I've got the initramfs on a workable system (busy box + uClibC) down to something like 1MB ... So you can go small. Guess if pushing the idea hard you could go for a minimal kernel, e.g. no need to bring up USB and ethernet etc ...

Guess you could have one boot option just to mount a file system over the initramfs.

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Mon Sep 10, 2012 10:26 am

summers wrote:Guess if pushing the idea hard you could go for a minimal kernel, e.g. no need to bring up USB and ethernet etc ...
You do need USB for the keyboard at least and probably network also as well as ssh for headless usage.

summers
Posts: 63
Joined: Mon Jan 30, 2012 4:27 pm

Re: [Request] kexec based bootloader/grub replacement

Mon Sep 10, 2012 11:11 am

Aydan wrote:
summers wrote:Guess if pushing the idea hard you could go for a minimal kernel, e.g. no need to bring up USB and ethernet etc ...
You do need USB for the keyboard at least and probably network also as well as ssh for headless usage.
Good point. Pity though as its the external hardware that seems the slow stuff to bring up. Still I guess bring up MMC cards has to be done, and thats slow as well ...

Seems daft on my pandaboard that I can boot into an initramfs before the kernel has managed to bring up MMC ...

And if ssh(d) is needed, you need more than busybox+uClibc - that doesn't ship with ssh(d). Think though there are some light weight versions, that aren't too dependent on libs .... dropbear comes to mind (http://matt.ucc.asn.au/dropbear/dropbear.html)

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Mon Sep 10, 2012 4:32 pm

SirLagz wrote:Tried with just a plain path rather than scripting ?

Code: Select all

[email protected]:~# kexec -l /boot/kernel.img --append="dma.dmachans=0x3c bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1200 bcm2708.boardrev=0x2 bcm2708.serial=0xefa2094 smsc95xx.macaddr=B8:27:EB:FA:20:94 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait dwc_otg.microframe_schedule=1"
[email protected]aspberrypi:~# kexec -e
didn't work either.
Do I need to set the kernel type?

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: [Request] kexec based bootloader/grub replacement

Tue Sep 11, 2012 7:44 am

Aydan wrote:
summers wrote:Guess if pushing the idea hard you could go for a minimal kernel, e.g. no need to bring up USB and ethernet etc ...
You do need USB for the keyboard at least and probably network also as well as ssh for headless usage.
You could *possibly* build a timeout...If nothing is selected then boot up the first entry.
That way you don't need USB or SSH if you're not going to be interactive, though USB will definitely be needed for most use cases.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Aydan
Posts: 710
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: [Request] kexec based bootloader/grub replacement

Tue Sep 11, 2012 4:50 pm

I just tried again with the serial console and it gets as far as this:

Code: Select all

[email protected]:~# kexec -e
[   97.981115] Starting new kernel

Message from sy
Yep, broke off in the middle and no reaction at all afterwards.
It looks like the old kernel doesn't get to shut down and the new one doesn't start at all.
I'm implying a shutdown since i didn't specify

Code: Select all

 -f, --force          Force an immediate kexec,
                      don't call shutdown.

Return to “Linux Kernel”