On 4/21/07, Varga-Háli Dániel <[EMAIL PROTECTED]> wrote: > Hi, > > I am very much interested in building my own custom Linux firmware for > specific reasons. Unfortunately I am not familiar how is an OS booted. > I know that the MBR is the first 512bytes or KBs of the bootable HDD > and the grub or LILO or whatever needs to be there. That's ok. > > My question would be that after the grub is loaded and I am about > ready to boot the system what is happening. Loads the kernel, runs > initrd or what? What are those init things? What are runlevels? What > is very necessary and required to boot a system? > > Thanx: > Dani
In which part are you interested?, it is a very very long process (executed in a few seconds). I'll explain the big lines here, just tell me where you need more info, and i hope i can help you :) I studied the boot process a few years ago, so i might forget something. boot (GRUB) It starts, like you said, with the MBR, the MBR is 512bytes, and does the very basic actions. When your computer starts, it is running in 16bit mode, and inside the MBR, the computer is changing to 32bit (protected)mode. Also it enables the A20 gate. If that is done, it loads stage1_5 file(talking about GRUB here, but it is smiliar for other bootloaders) to be able to read from a filesystem. If it can read from the filesystem, it can read the stage2 file. After it has loaded the stge2 file, it will execute :). This load the "graphical" GRUB, it reads the /boot/grub/menu.lst file. There you make your option, and GRUB(stage2) does what is in your menu.lst. I'm refering to the default menu.lst file from the LFS book. It reads your "root (hd?,?)" option, and tries to read it's filesystem. Then it reads your kernel= option from the menu.lst file. It loads the first item after the = to the RAM, and executes it with the options that are also on the kernel= line. These options passed to the kernel are called the command line options for the kernel. Kernel The first thing the kernel does is communicating with the BIOS, it tries to get some information, like the RAM size. Then it is parsing your command line, and when done, it starts initializing the core hardware (except things disabled by command line). All it does is loading builtin drivers and probably uses some generic drivers for some things. Then it will initialize builtin filesystems. Now it starts loading all other hardware (also except things disabled by the command line of course). It mounts the root filesystem read only, (The one specified on the command line).and it will load all modules located on the hard drive. This might register some more hardware, and this might also replace some generic drivers used at start (A specific graphics driver probably replaces the generic vga driver here). Now the kernel will execute /sbin/init (or the program given with init= on the command line) Init I'm talking about the standard /sbin/init program here, which is used by the LFS book. The program reads the /etc/inittab file, and searches for this line: si::sysinit:/etc/rc.d/init.d/rc sysinit A line starting with si, the sysinit line. The last option passed is the script executed, including it's command line options. so /etc/rc.d/init.d/rc gets executed with the command line option sysinit. The rc scripts does not very much, it kills all processes started in the previous runlevel (but the system starts, so it skips this part). and then starts every script in /etc/rc.d/rc${runlevel}.d starting with S (S=Start, K=Kill. The 2 digits after that define the order.). $runlevel is the argument passed to it throught the command line, sysinit here, so it will execute all files in /etc/rc.d/rcsysinit.d starting with S. If you're using the LFS bootscripts, you probably have 12 files in that directory. Note that these are symlinks to files in /etc/init.d. Because they start with S, the script in /etc/init.d will be executed with start on the command line. Small explanation of all 12.: S00mountkernfs: mounts /proc and /sys S05modules: Loads all modules in /etc/sysconfig/modules (it's empty for me) S10udev: Mounts a tmp filesystem on /dev, copies the static devices in /lib/udev/devices to /dev. Then it starts udev daemon, udevtrigger to register new devices, and udevsettle to wait for udev to finish. S20swap: Enables all swap space. S30checkfs: Remounts root filesystem in read only mode and checks the filesystem for errors. S40mountfs: Remounts root filesystem in read-write mode, creates a new /etc/mtab file, according to the currently mounted /, /proc and /sys and then it mounts all remaining unmounted filesystems in /etc/fstab. S45udev_retry: This will check for any failed udev events, and retry them. S50cleanfs: This cleans up /tmp and some directorys in /var. Also this script creates files/directorys/devices in /etc/sysconfig/createfiles S60setclock: This will set the hardware clock to the software clock. (On shutdown this is reversed) S70console: This setups the console by parsing the /etc/sysconfig/console file. S80localnet: Setups the loopback device and the hostname. (reads /etc/sysconfig/network) S90sysctl: calls the sysctl program to set kernel runtime parameters. Now, when all these scripts are done, the init program (/sbin/init) searches for another line /etc/inittab. In the default LFS /etc/inittab it is this line: id:3:initdefault: It searches for the line that starts with id, the init default runlevel. The second argument is the runlevel, which init will boot now. Init does boot this by reading another line in the /etc/inittab file, and that is this: l3:3:wait:/etc/rc.d/init.d/rc 3 The line starting with l3.Because the default runlevel is 3. It will also execute the last argument here, so /etc/rc.d/init.d/rc again, but this time with command line argument 3. It is the same as with the sysinit, but now it will load all files in /etc/rc.d/rc3.d starting with S. Note that sysinit is not a runlevel, and that the rc script does not kill all programs started with the scripts in /etc/rc.d/rcsysinit.d. If you change to another runlevel now, it will kill all programs started with the scripts in /etc/rc.d/rc3.d But well, a little explanation of the files in /etc/rc.d/rc3.d: S10sysklogd: loads processes syslogd and klogd. S20network: Starts up all network interfaces configured. (\\server\root\etc\sysconfig\network-devices) There might be more, like i have one for mdns and one for cups, but above 2 are installed by the LFS bootscripts. Finally it will start /bin/login, and show you a login box asking your username and password :) If you have things like X/KDE/Gnome installed, you probably won't notice it is starting, because X starts inside the bootscripts (rc3.d, rc4.d or rc5.d). The meaning of each runlevel: 0: halt the computer 1: single-user mode 2: multi-user mode without networking 3: multi-user mode with networking 4: reserved for customization, otherwise does the same as 3 5: same as 4, it is usually used for GUI login (like X's xdm or KDE's kdm) 6: reboot the computer (from: http://www.linuxfromscratch.org/lfs/view/stable/chapter07/usage.html, a lot info about the LFS bootscripts.) initrd is an extra option, it is not required, but it is sometimes useful for loading drivers before actually loading the rest. It is used by some distributions, mostly because it speeds up the system, as an RAM disk is a lot faster then a regular disk. But a normal LFS system is very fast, so there's not a really good reason to use it. Unless you are trying to do some sh*t, like i want. Booting linux from an floppy, and using initrd to load some drivers for my USB pen drive, and then boot the actual pen drive. So for your firmware, you probably want to interact with the kernel in the boot process, so you should probably write an Linux kernel module (one that can be compiled into the kernel too). So you might want to look at The Linux Kernel Module Programming Guide: http://tldp.org/LDP/lkmpg/2.6/html/index.html I hope this helps you, like i said at top, if you need to know more about a specific part, just tell me ;) Best Regards, Tijnema -- http://linuxfromscratch.org/mailman/listinfo/lfs-support FAQ: http://www.linuxfromscratch.org/lfs/faq.html Unsubscribe: See the above information page