ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
First, thanks to all that took an interest in my question. Secondly, I want to inform all that I have found a solution.
Research went as follows:
After all the round about, I found that mem address 0x472 need to be set to 0x1234 to tell your BIOS that you want to do an <CTRL><ALT><DEL> type restart, or 0 for cold boot and would do system check. Armed with this knowledge, I once again Googled the 'net and found countless references of code like
*(unsigned short)0x472 = 0x1234;
or
mov [$0x472],#$0x1234
Althoug this does not work (core dump) if you have the memory protection of a full running kernel. But I also noticed that this code exist inside of process.c of LINUX itself. Searching through the full LINUX code also resulted in my finding system calles that does not interact with init, but forces the memory access to 0x472.
So, the code as follows. WARNING! Running this code WILL also restart your running LINUX without warking, or disc sync.
CODE:
//-------------------------------------------
// version 1.0 24 Oct 2006
#include <sys/reboot.h>
#include <iostream>
using namespace std;
int main() {
cout << "Reboot...\n";
reboot(RB_AUTOBOOT);
}
//-------------------------------------------
PS. Don't you hate it when you struggle with a problem for months on end, and then the solution can be written in only a few lines of code?
You didn't disagree with me. Whether or not it is actually called "init", it still has to exist. In that case, all "init" actually has to do is probably just die. Or the OP should actually do what he needs to do to get a real OS running. My point stands, it isn't *nix without some kind of init.
Looking further, it really does look like you have init. How else does linuxrc get called? I know for certain that the bootdisks I've messed with did things that way, and there was an init by the time linuxrc happened.
I don't have init in any directory in my boot.img. It is not running when consulting ps either. So, either the LINUX kernel has a very low key init built in, or it is replaced by nash (as in my case). The boot loader is instructed where to find the kernel, and then what the initrd is (boot.img). It starts linuxrc when mounting boot.img under /, because that is the default.
/usr/src/linux/init/main.c should end any question about whether or not a binary called init needs to exist. The system will try /sbin/init, /etc/init, /bin/init, and then /bin/sh in that order. UNLESS, you pass init= to the kernel.
By default, many architectures automatically configure the init= option to be /linuxrc. Further though, if you have an initrd filesystem, the kernel will automatically execute it in a separate thread. (see /usr/src/linux/init/do_mounts_initrd.c)
What this means is, you don't need a binary called init. You don't even need a binary that does any kind of system initialization. You just need a binary to invoke as the INITial process (hence where init comes from).
So, do you need init as a binary, or concept of initialization? No.
Quote:
Looking further, it really does look like you have init. How else does linuxrc get called? I know for certain that the bootdisks I've messed with did things that way, and there was an init by the time linuxrc happened.
Actually, he doesn't have init, and might not even have an init= line. If /bin/sh exists, and he's mounting an initial ramdisk, the kernel executes /linuxrc and then executes initial processes in the order I noted above. That's for a 2.6 kernel, and a 2.4 kernel. I think 2.0 and 2.2 had /linuxrc in the init list like they are (meaning that there was no need to extract an initrd), but I'd have to look at my old hal91 and redhat sources.
The Linux boot sequence is more complicated than your average embedded operating system, and there are many more options for configuring things. In general, the boot sequence goes like this:
Processor comes out of reset and branches to the ROM startup code.
The ROM startup code initializes the CPU and memory controller, performing only minimal initialization of on-chip devices, such as the console serial port (typically SMC1 on 8xx devices) to provide boot diagnostic messages. It also sets up the memory map for the kernel to use in a format that is consistent across platforms, and then jumps to the boot loader.
The boot loader decompresses the kernel into RAM, and jumps to it.
The kernel sets up the caches, initializes each of the hardware devices via the init function in each driver, mounts the root filesystem and execs the init process, which is the ultimate parent of all user mode processes, typically /sbin/initd.
Executing the first program linked against the shared C runtime library (often init) causes the shared runtime library to be loaded.
In a typical Linux system, init reads /etc/inittab to execute the appropriate run control script from /etc/rc.d, which execute the start scripts to initialize networking and other system services.
In minimal embedded systems, init is commonly replaced with a simple C program or shell script to start the appropriate services and application programs, since the conventional rc scripts are often overkill.
Acording to this there is a init function in each driver but ultametly init gets run on a normal system from somewhere. Acording to this and what i suppect the OP has done is remove init with the simple C program. In that case his question is valid as to how to shut it down via the C program instead of the mainstream init. Im not sure how thats done and that was the question orignally asked by the OP.
Just an aside, many year after the original question:
Using reboot (from busybox) with option "-f" will call reboot system call instead sending a signal to init.
This way it is possible to restart the system from a /linuxrc script (no init process running).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.