Page 1 of 1
Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 6:38 pm
by mutex
Anyone know if there is a tool for booting a multiboot image from within linux? Something like loadlin for dos...
-
Thomas
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 6:45 pm
by Owen
Yes. It's called QEMU, or Bochs, or Virtual Box, or VMWare. or <Favorite virtualization software here> and Grub.
I mean, seriously, what do you expect it to do? Boot it in an emulator, or replace the running Linux instance with the OS?
In the case of the former... use an emulator. In the case of the latter, it's not happening - applications don't have the privileges required to replace the running kernel, and it's also a technical impossibility for them to do so reliably.
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 6:56 pm
by mutex
Are you serious?
I need to boot my kernel (replace the running kernel)... Like Solaris does if you ask it to with the reboot option.
Linux have things like this for ARM etc but i cannot find anything for x86.
If you want understand you can read here;
http://www.embeddedarm.com/software/arm ... loader.php
-
Thomas
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 7:17 pm
by pcmattman
Like Solaris does if you ask it to with the reboot option.
... by jumping to a stub loaded in memory which brings down the kernel, unmaps it all, and then reloads it (iirc, been a while since I was at the seminar where it was explained in detail). To my understanding, you can't do that in userspace without specific kernel hooks... So unless you feel like modifying your Linux kernel, you will find it difficult to try this out. You are definitely better off just using an emulator, and it's faster to do that anyway.
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 7:32 pm
by mutex
Well,
I use emulators like vmware and bochs for normal development cycle for my kernel, but i'm experimenting with
something and i want to try it out;)
Seems that there are not anything made for x86 just for other more "embedded" architectures.
Im going to give it a shot myself. Should not be to hard actually;
1. Create a kernel module that reserves some physical memory when told to.
2. Userspace app that sends data to this buffer via the module.
3. Userspace app tells module to "boot"
4. kernel module disable all ints, etc, relocate code to where it was specified in multiboot info and then does a far jmp
-
Thomas
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 7:48 pm
by thepowersgang
Well, that seems to be the easiest way of doing it, but I suggest that you put some proper access controls on it. But, the reason loadlin exists for linux is that it was designed for machines that did not have a menu-based bootloader, so instead of installing LiLo or GrUB (did they even exist then?) you would use loadlin.
With modern machines it's just as easy to add your Multiboot kernel to the GrUB boot order and restart. In fact, it's even better, because doing it by just unloading the linux kernel and loading you own, quite likely linux will not be shut down properly and hence you could loose data. (Plus, linux might do things with hardware that requires special code to de- and re-init, making your OS run strangely
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 7:50 pm
by pcmattman
but i'm experimenting with something and i want to try it out
If it has anything to do with physical hardware, some emulators allow the guest to directly access certain hardware devices. That might be an easier solution, but I don't know what you're trying to do.
Re: Booting multiboot image from within Linux
Posted: Fri Nov 27, 2009 8:09 pm
by mutex
Hmm,
First of all the linux kernel cannot do anything after i have releaved it from its duties so to speak. Off course drivers etc can have initialised both hardware dma, and all sorts of other stuff BUT as far as my Linux kernel knowledge go im pretty sure i can force Linux to do the following after i have loaded my image;
1. Stopp all kmodules (device drivers) except my bootloading module. That means all cleanup / shutdown will be called on all devices. Pretty mouch stopping everything including hardware dma etc.
2. When that is done i can stop/halt the kernel also and execute my code that i just moved to the desired address.
I think since this has been done on arm and other architectures it should be fairly possible on x86 aswell. Of course the bios data stuff etc must be considered lost, but besides that i would be able to boot my kernel.
I think...