文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Linux Startup Scripts

Linux Startup Scripts

时间:2010-08-17  来源:kevin_0608

Linux Startup Scripts

or
What happens before the login prompt!

Kim Oldfield, [email protected]

Presented to Linux Users of Victoria.

Original presentation created using MagicPoint.

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


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载