LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-24-2006, 09:20 AM   #16
khtw
LQ Newbie
 
Registered: Oct 2006
Distribution: NEBULA First 2.2 OS
Posts: 12

Original Poster
Rep: Reputation: 0
Solution At Last!


Hi All,

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?

khtw
 
Old 10-24-2006, 09:28 AM   #17
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.

Last edited by tuxdev; 10-24-2006 at 10:01 AM.
 
Old 10-24-2006, 02:33 PM   #18
khtw
LQ Newbie
 
Registered: Oct 2006
Distribution: NEBULA First 2.2 OS
Posts: 12

Original Poster
Rep: Reputation: 0
Hay,

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.

khtw
 
Old 10-24-2006, 03:53 PM   #19
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
/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.
 
Old 10-24-2006, 11:07 PM   #20
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
oops, hehe, posted without reading page 2

Last edited by PatrickNew; 10-24-2006 at 11:11 PM.
 
Old 10-25-2006, 11:50 AM   #21
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
This should put any discussion to an end.

Quote:

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.
 
Old 07-13-2011, 04:22 PM   #22
Marcelo Barros
LQ Newbie
 
Registered: Jul 2011
Posts: 1

Rep: Reputation: Disabled
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).

Cheers
 
  


Reply

Tags
rebooting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linuxrc:please help in editing bongski55 Red Hat 3 06-11-2009 05:29 AM
What is the meaning of 'linuxrc'? leonzheng Linux - Newbie 4 11-13-2006 09:04 AM
linuxrc problem? cstovall Linux - Software 0 11-08-2005 07:22 PM
when linuxrc will get crash? alwar Linux - Software 0 01-19-2005 11:56 PM
GENTOO - "init=/linuxrc" (/linuxrc: not found | kernel panic!!) halo14 Linux - Distributions 6 01-14-2005 01:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration