updating the kernel without rebooting.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

updating the kernel without rebooting.

Post by 01000101 »

Hey, I've been thinking about implementing a way to compile my kernel on my dev machine, and (over ethernet) update my live kernel on my test machines without having to restart the PC.

One method I've been looking into was to recieve the kernel binary in a custom packet format, write it to HDD over the existing one and jump to a static area in memory that will re-start the kernel without 'restarting' the pc. But one main issue with that is, once i re-load the kernel off the HDD, the code that was loading the OS may not be in the same spot as it was before the update thus probably causing a triplefault. is there a way for me to do this from a static function address that wont get overwritten each time?

The other method I was thinking about was to take the kernel from the ethernet and put it into its own seperate area, and leave the live one where it is as well, and then jump to the new area and erase the old area, but that is a very wasteful (memory) way to do it and not my first choice.

any ideas?
User avatar
proxy
Member
Member
Posts: 108
Joined: Wed Jan 19, 2005 12:00 am
Contact:

Post by proxy »

I've have thought about this before and there is no simple answer. It will not be a simple task, but possibly doable. There are a few things that I believe must be done.

First thing that must be done, is you need to put all threads/processes into a suspended state. Obviously with the exception of the thread which is performing the switch.

You will need some mechanism which allows you to transfer all the kernel level structures representing the system state (processes, threads, file handles, etc).

Both of these things will need to be done VERY carefully, RAM state will be particularly sensitive.

After that, you can hopefully load the new kernel into memory (hard disk is kinda besides the point, doesn't matter until reboot) and hopefully resume all of your suspended processes/threads.

That is unless you are looking to simply update the kernel and plan to reset all processes state. In which case the task should be a bunch easier.
Just look at the kexec system call in linux.

Good luck!

proxy
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

I think I might do it a bit simpler.

I'm thinking about loading the update_kernel into memory after the live kernel, then switch to that kernel, and copy that kernel once more to overwrite the older kernel, erase the first copy and resume from the second copy.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

I don't know if this has any relevance, but Erlang touts its ability to dynamically upgrade its programs. You might be able to look into that and see how it does it. (Granted, it will be on a different level than an OS, but....why not?)

Good Luck. ;)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Updating the kernel on-the-fly is called a "patch", and there are lots of OSes than can accomodate them without a reboot. The question is: how small, and how modular is your kernel/OS? ... And especially whether you are actually changing the formats of any system tables.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

My OS is not modular at all. It is about 60k compiled and is one giant binary. I don't wish to patch, i wish to replace lol. I just want to replace the live kernel with a newer version.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

I can see very little problems, why do you not just replace the kernel off the hdd with new one, then do a

Code: Select all

        mov ax,201h
        mov bx,7c0h
        mov cx,1
        mov dx,80h
        push bx
        xor bx,bx
        pop es
        int 13h
        jmp 0:7c00h
or

Code: Select all

;Warm Boot By Dex (untested)
        xor   ax,ax            ;*SET FLAG FOR WARM REBOOT*
        mov   ds,ax            ; dos flags memory segment address
        mov   si,0x0472        ; dos reboot type flag offset
        mov   cx,0x1234        ; warm boot indicator
        mov   word[ds:si],cx   ; set the flag

                               ;*WARM REBOOT*
        db    0xea             ; Machine language to jump to
                               ; address FFFF:0000 (reboot)
        dw    0x0000
        dw    0xffff           ; No return required
       			       ; we're rebooting!

        jmp $		       ; Just incase ;-)

As you kernel is run from memory, so replacing the kernel on hdd is no problem.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

wow lol. thanks for making me feel like an idiot =).

that solves the issue entirely. thanks.
Kay
Posts: 1
Joined: Mon Jun 09, 2008 6:04 am
Contact:

Post by Kay »

I'd recommend checking out a working model, namely the Linux kernel's 'kexec' syscall.

Userland component
Kernel land component
---Kay
Post Reply