Chinaunix首页 | 论坛 | 博客
  • 博客访问: 281884
  • 博文数量: 176
  • 博客积分: 2516
  • 博客等级: 少校
  • 技术积分: 1350
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-01 11:18
文章分类
文章存档

2011年(1)

2010年(18)

2009年(157)

我的朋友

分类: LINUX

2009-09-22 17:12:07

Linux Startup Scripts

or
What happens before the login prompt!

Kim Oldfield, kimo@debian.lib.monash.edu.au

Presented to .

Original presentation created using .

it is very useful for learn initrd.



Boot sequence summary

  • BIOS
  • Master Boot Record (MBR)
  • Kernel
  • init

BIOS

Load boot sector from one of:

  • Floppy
  • CDROM
  • SCSI drive
  • IDE drive

Master Boot Record

  • MBR (loaded from /dev/hda or /dev/sda) contains:
    • lilo
      • load kernel (image=), or
      • load partition boot sector (other=)
    • DOS
      • load "bootable" partition boot sector (set with fdisk)
  • partition boot sector (eg /dev/hda2) contains:
    • DOS
      • loadlin
    • lilo
      • kernel

LILO

One minute guide to installing a new kernel

  • edit /etc/lilo.conf
    • duplicate image= section, eg:

      image=/bzImage-2.2.12

      label=12

      read-only

    • man lilo.conf for details
  • run /sbin/lilo
  • (copy modules)
  • reboot to test

Kernel

  • initialise devices
  • (optionally loads initrd, see below)
  • mount root FS
    • specified by lilo or loadin
    • kernel prints:
      • VFS: Mounted root (ext2 filesystem) readonly.
  • run /sbin/init, PID 1
    • can be changed with boot=
    • init prints:
      • INIT: version 2.76 booting

initrd

Allows setup to be performed before root FS is mounted

  • lilo or loadlin loads ram disk image
  • kernel runs /linuxrc
    • load modules
    • initialise devices
    • /linuxrc exits
  • "real" root is mounted
  • kernel runs /sbin/init

Details in /usr/src/linux/Documentation/initrd.txt


/sbin/init

  • reads /etc/inittab
  • runs script defined by this line:
    • si::sysinit:/etc/init.d/rcS
  • switches to runlevel defined by
    • id:3:initdefault:

sysinit

  • debian: /etc/init.d/rcS which runs
    • /etc/rcS.d/S* scripts
      • symlinks to /etc/init.d/*
    • /etc/rc.boot/* (depreciated)
  • redhat: /etc/rc.d/rc.sysinit script which
    • load modules
    • check root FS and mount RW
    • mount local FS
    • setup network
    • mount remote FS

Example Debian /etc/rcS.d/ directory

README

S05keymaps-lct.sh -> ../init.d/keymaps-lct.sh

S10checkroot.sh -> ../init.d/checkroot.sh

S20modutils -> ../init.d/modutils

S30checkfs.sh -> ../init.d/checkfs.sh

S35devpts.sh -> ../init.d/devpts.sh

S35mountall.sh -> ../init.d/mountall.sh

S35umsdos -> ../init.d/umsdos

S40hostname.sh -> ../init.d/hostname.sh

S40network -> ../init.d/network

S41ipmasq -> ../init.d/ipmasq

S45mountnfs.sh -> ../init.d/mountnfs.sh

S48console-screen.sh -> ../init.d/console-screen.sh

S50hwclock.sh -> ../init.d/hwclock.sh

S55bootmisc.sh -> ../init.d/bootmisc.sh

S55urandom -> ../init.d/urandom


Run Levels

  • 0 halt
  • 1 single user
  • 2-4 user defined
  • 5 X11
  • 6 Reboot
  • Default in /etc/inittab, eg
    • id:3:initdefault:
  • Change using /sbin/telinit

Run Level programs

  • Run programs for specified run level
  • /etc/inittab lines:
    • 1:2345:respawn:/sbin/getty 9600 tty1
      • Always running in runlevels 2, 3, 4, or 5
      • Displays login on console (tty1)
    • 2:234:respawn:/sbin/getty 9600 tty2
      • Always running in runlevels 2, 3, or 4
      • Displays login on console (tty2)
    • l3:3:wait:/etc/init.d/rc 3
      • Run once when switching to runlevel 3.
      • Uses scripts stored in /etc/rc3.d/
    • ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
      • Run when control-alt-delete is pressed

Typical /etc/rc3.d/ directory

When changing runlevels /etc/init.d/rc 3:
  • Kills K##scripts
  • Starts S##scripts

K25nfs-server -< ../init.d/nfs-server

K99xdm -< ../init.d/xdm

S10sysklogd -< ../init.d/sysklogd

S12kerneld -< ../init.d/kerneld

S15netstd_init -< ../init.d/netstd_init

S18netbase -< ../init.d/netbase

S20acct -< ../init.d/acct

S20anacron -< ../init.d/anacron

S20gpm -< ../init.d/gpm

S20postfix -< ../init.d/postfix

S20ppp -< ../init.d/ppp

S20ssh -< ../init.d/ssh

S20xfs -< ../init.d/xfs

S20xfstt -< ../init.d/xfstt

S20xntp3 -< ../init.d/xntp3

S89atd -< ../init.d/atd

S89cron -< ../init.d/cron

S99rmnologin -< ../init.d/rmnologin


Boot Summary

  • lilo
    • /etc/lilo.conf
  • debian runs
    • /etc/rcS.d/S* and /etc/rc.boot/
    • /etc/rc3.d/S* scripts
  • redhat runs
    • /etc/rc.d/rc.sysinit
    • /etc/rc.d/rc3.d/S* scripts
阅读(928) | 评论(0) | 转发(0) |
0

上一篇:gdb调试

下一篇:The Linux Project Documents

给主人留下些什么吧!~~