The debian system initialization

 The debian system initialization  

    It is wise for you as the system administrator to know roughly how the debian is started and configured.Although the exact details are in the source files of the packages installed and their doucumentations,it is a bit overwhelming for most of us.

   Since the debian system is a moving target,the situtation over the system may have been changed.Before making any changes to the system,you should refer to the latest documentation for each package.

1.An overview of the boot strap process

    The computer system undergoes several phases of boot strap processes from the power-on event until it offers the fully functional operating system(OS) to the user.

    For simplicity,I limit discussion to the typical PC platform with the default installation.

    The typical boot strap process is like a four-stage rocket.Each stage rocket.Each stage rocket hands over the system control to the next stage one.

Stage 1:the BIOS

    The BIOS is the 1st stage of the boot process which is started by the power-on event.The BIOS residing on the read only memory(ROM) is executed from the particular memory address to which the program counter of CPU is initialized by the power-on event.

    This BIOS performs the basic initialization of the hardware(POST:power on self test) and hands the system control to the next step which you provide.The BIOS is usually provided with the hardware.

    The BIOS startup screen usually indicates what key(s) to press enter the BIOS setup screen to configure the BIOS behavior.Popular keys used are F1,F2,F10,Esc,Ins,and Del.If your BIOS startup screen is hidden by a nice graphics screen,you may press some keys such as Esc to disable this.These keys are highly dependent on the hardware.

    The hardware location and the priority of the code started by the BIOS can be selected from the BIOS setup system.Typically,the first few sectors of the first found selected device(hard disk,floppy disk,CD-ROM....) are loaded to the memory and this initial code is executed.This initial code can be any one of the following:

  • The boot loader code
  • The kernel code of the stepping stone OS such as FreeOS
  • The kernel code of the target OS if it fits in this small space

  Typically,the system is booted from the specified partition of the primary hard disk partition.First 2 sectors of the hard disk on legacy PC contain the master boot record(MBR).The disk partition information including the boot selection is recorded at the end of this MBR.The first boot loader code executed from the BIOS occupies the rest of this MBR.

Stage 2:the boot loader

  The boot loader is the 2nd stage of the boot process which is started by the BIOS.It loads the system kernel image and the initrd image to the memory and hands control over to them.This initrd image is the root filesystem image and its support depends on the bootloader used.

  The debian system nromally uses the Linux kernel as the default system kernel.The initrd image for the current 2.6/3.x Linux kernel is technically the initramfs(initial RAM filesystem) image.The initramfs image is a gzipped cpio archive of files in the root filesystem.

  The default install of the Debian system places first-stage GRUB boot loader code into the MBR for the PC platform.There are many boot loaders and configuration options avaliable.

Table: List of boot loaders

package popcon size initrd bootloader description
grub-legacy V:1, I:4 1747 Supported GRUB Legacy This is smart enough to understand disk partitions and filesystems such as vfat, ext3, ….
grub-pc V:72, I:867 550 Supported GRUB 2 This is smart enough to understand disk partitions and filesystems such as vfat, ext4, …. (default)
grub-rescue-pc V:0, I:2 4478 Supported GRUB 2 This is GRUB 2 bootable rescue images (CD and floppy) (PC/BIOS version)
lilo V:2, I:10 594 Supported Lilo This relies on the sector locations of data on the hard disk. (Old)
syslinux V:13, I:90 134 Supported Isolinux This understands the ISO9660 filesystem. This is used by the boot CD.
syslinux V:13, I:90 134 Supported Syslinux This understands the MSDOS filesystem (FAT). This is used by the boot floppy.
loadlin V:0, I:2 105 Supported Loadlin New system is started from the FreeDOS/MSDOS system.
mbr V:1, I:19 72 Not supported MBR by Neil Turton This is free software which substitutes MSDOS MBR. This only understands disk partitions.

 

  For GRUB Legacy,the menu configuration file is located at "/boot/grub/menu.lst".For example,it has entries as the following.

title           Debian GNU/Linux
root            (hd0,2)
kernel          /vmlinuz root=/dev/hda3 ro
initrd          /initrd.img

  For GRUB 2,the menu configuration file is located at "/boot/grub/grub.cfg".It is automatically generated by "/usr/sbin/update-grub" using templates from "/etc/grub.d/*" and settings from "/etc/default/grub".For example,it has entries as the following.

menuentry "Debian GNU/Linux" {
        set root=(hd0,3)
        linux /vmlinuz root=/dev/hda3
        initrd /initrd.img
}
  For these examples,these GRUB parameters mean the following.

Table  The meaning of GRUB parameters

GRUB parameter meaning
root use 3rd partition on the primary disk by setting it as "(hd0,2)" in GRUB legacy or as "(hd0,3)" in GRUB 2
kernel use kernel located at "/vmlinuz" with kernel parameter: "root=/dev/hda3 ro"
initrd use initrd/initramfs image located at "/initrd.img"

Stage 3:the mimi-Debian system

  The mini-Debian system is the 3rd stage of the boot process which is started by the boot loader.It runs the system kernel with its root filesystem on the memory.This is an optional preparatory stage of the boot process.

   The "/init" script is executed as the first program in this root filesystem on the memory.It is a shell script program which initializes the kernel in user space and hands control over to the next stage.This mini-Debian system offers flexibility to the boot process such as adding kernel modules before the main boot process or mounting the root filesystem as an encrypted one.

  You can interrupt this part of the boot process to gain root shell by providing "break=init" etc. to the kernel boot parameter.See the "/init" script for more break conditions.This shell environment is sophisticated enough to make a good inspection of your machine's hardware.

Stage 4:the normal Debian system

  The normal Debian system is the 4th stage of the boot process which is started by the mini-Debian system.The system kernel for the mini-Debian system continues to run in this environment.The root filesystem is switched from the one on the memory to the one on the real hard disk filesystem.

  The init program is executed as the first program with PID=1 to perform the main boot process of starting man programs.The default file path for the init program is "/sbin/init" but it can be changed by the kernel boot parameter as "init=/path/to/init_program".

  The default init program has been change:

  • Debian before squeeze uses the simple SysV-style init.
  • Debian from wheezy improves the SysV-style init by ordering the boot sequence with LSB header and starting boot scripts in parallel.
  • Debian after wheezy may switch its init system to the newer one such as upstart,systemd,...

note:

  • All boot mechanisms are compatible through "/etc/init.d/rc","/etc/init.d/rcS","/usr/sbin/update-rc.d",and "/usr/sbin/invokde-rc.d" scripts.
  • If GRUB is used,the kernel boot parameter is set in /boot/grub/grub.cfg.On Debian system,you should not edit /boot/grub/grub.cfg directly.You should edit the GRUB_CMDLINE_LINUX_DEFAULT value in /etc/default/grub  and run update-grub to update /boot/grub/grub.cfg


2.SysV-style init

  This section describes how the good old SysV-style init used to boot the system.Your Debian syttem does not function exactly as described here but it is quite educational to know this basics since the newer init system tends to offer equivalent fucntionlities.

  The SysV-style boot process essentially goes through the following.

  1. The debian system goes into runlevel N(none) to initialize the system by following the "/etc/inittab" description.
  2. The debian system goes into runlevel S to initialize the system under the single-user mode to complete hardware initlization etc.
  3. The debian system goes into one of the specified multi-user runlevels(2 to 5) to start the system servicves.

  The initial runlevel used for multi-user mode is specified with the "init=" kernel boot parameter or in the "initdefault" line of the "initdefault" line of the "/etc/inittab".The debian system as installed starts at the runlevel 2.

   something about init

   Init is the parent of all processes.Its primary role is to create processes from a script stored in the file /etc/inittab.This file usually has entries which cause init to spawn gettys on each line that users can log in.It also controls autonomous processes required by any particular system.

   something about /etc/inittab

    The default runlevel.        id:2:initdefault:

    Boot-time system configuration/initialization script.This is run first except when booting in emergency(-b) mode.           si::sysinit:/etc/init.d/rcS


    /etc/init.d/rcS

#! /bin/sh
#
# rcS
#
# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order
#

exec /etc/inti.d/rc S





exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]

    Replace the shell with the given command.

    Execute COMMAND,replacing this shell with the specified program.

    ARGUMENTS become the arguments to COMMAND.If COMMAND is not specified,any redirections take effect in the current shell.

    Options:

    -a name    pass NAME as the zeroth argument to COMMAND    

    -c             execute COMMAND with an empty environment

    -l              place a dash in the zeroth argument to COMMAND

     If the command cannot be executed,a non-interactive shell exits,unless the shell option `execfail` is set.

     Exit Status:

     Returns success unless COMMAND is not found or a redirection error occurs.


    /etc/init.d/rc     Start/stops services on runlevel changes


    Optimization: A start script is not run when the service was already configured to run in the previous runlevel.A stop script is not run when the service was already configured not to run in the previous runlevel.

PATH=/sbin:/usr/sbin:/bin:/usr/bin

export PATH (declare -x PATH)



export: export [-fn] [name[=value] ...] or export -p

    Set export attribute for shell variables

    Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied,assign VALUE before exporting.

    Options:

        -f        refer to shell functions

        -n        remove the export property from each NAME

        -p        display a list of all exported variables and functions

    An  argument of '--'  disables further option processing.

    Exit status:

    Return success unless an invalid option is given or NAME is invalid.




    





转载于:https://my.oschina.net/huihu/blog/187328

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值