linux系统引导流程

更新时间:2023-05-27 03:43:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

linux系统引导流程

linux 查看软件时间 date

[root@localhost test]# date

Sun Jan 15 19:20:01 PST 2012

[root@localhost test]#

hwclock 软件时钟

[root@localhost test]# hwclock --help

hwclock - query and set the hardware clock (RTC)

Usage: hwclock [function] [options...]

Functions:

--help show this help

--show read hardware clock and print result

--set set the rtc to the time given with --date

--hctosys set the system time from the hardware clock 依据硬件时钟设置软件时钟 --systohc set the hardware clock to the current system time 依据软件时钟设置硬件时钟

--adjust adjust the rtc to account for systematic drift since

the clock was last set or adjusted

--getepoch print out the kernel's hardware clock epoch value

--setepoch set the kernel's hardware clock epoch value to the

value given with --epoch

--version print out the version of hwclock to stdout

Options:

--utc the hardware clock is kept in coordinated universal time

--localtime the hardware clock is kept in local time

--directisa access the ISA bus directly instead of /dev/rtc

--badyear ignore rtc's year because the bios is broken

--date specifies the time to which to set the hardware clock

--epoch=year specifies the year which is the beginning of the

hardware clock's epoch value

--noadjfile do not access /etc/adjtime. Requires the use of

either --utc or --localtime

[root@localhost test]#

Eg.

[root@localhost test]# date

Sun Jan 15 19:26:05 PST 2012

[root@localhost test]# hwclock

Sun 15 Jan 2012 07:26:10 PM PST -0.128598 seconds

[root@localhost test]# hwclock --hctosys

[root@localhost test]# date

linux系统引导流程

Sun Jan 15 19:26:50 PST 2012

[root@localhost test]# hwclock

Sun 15 Jan 2012 07:26:58 PM PST -0.997218 seconds

[root@localhost test]# hwclock --systohc

[root@localhost test]# date

Sun Jan 15 19:27:41 PST 2012

[root@localhost test]# hwclock

Sun 15 Jan 2012 07:27:48 PM PST -0.322978 seconds

[root@localhost test]#

内核 kernel

内核只有两个作用,载入驱动程序,驱动硬件

启动进程init (很重要的进程 ,其PID)始终为1

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,0)

# kernel /vmlinuz-version ro root=/dev/sda2

# initrd /initrd-version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.18-194.32.1.el5)

linux系统引导流程

root (hd0,0)

kernel /vmlinuz-2.6.18-194.32.1.el5 ro root=LABEL=/ rhgb quiet

initrd /initrd-2.6.18-194.32.1.el5.img

title CentOS (2.6.18-194.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet 为内核的版本号,为一个单独的文件,是可执行文件,主要放了硬件驱动2:表示主版本号,6:表示副版本号,18:表示末版本号,副版本号为奇数时为测试版,偶数的稳定版

initrd /initrd-2.6.18-194.el5.img

~

~

查看分别修改硬件时钟和软件时钟

Man date

Man hwclock

然后依据其中一个正确的进行修改

在进程中父进程终止,子进程由于某种特殊的原因没有终止,而存在,即变成孤儿进程,但linux 系统中不允许存在孤儿进程,这时孤儿进程会自动指向init 进成为init 的进程

另一种情况是子进程死亡,但父进程还尝试与子进程取得联系,这时子进程就是变成僵尸进程,Z

NFS: network files system 可以进行linux windows 文件共享

Init 进程 配置文件

9 # Default runlevel. The runlevels used by RHS are:

10 # 0 - halt (Do NOT set initdefault to this) 如果设置缺省为0 ,则在开机posts 自检,进入grub 引导kernel ,kernel 加载硬件驱动,加载init进程,这是缺省为0 ,刚在加载init进程时就会关机,缺省为5 为xwindos 图形环境,可用runlevel

11 # 1 - Single user mode

12 # 2 - Multiuser, without NFS (The same as 3, if you do not have networking)没有NFS服务

13 # 3 - Full multiuser mode

14 # 4 - unused

15 # 5 - X11

16 # 6 - reboot (Do NOT set initdefault to this)

17 #

18 id:5:initdefault:

19

20 # System initialization.

21 si::sysinit:/etc/rc.d/rc.sysinit

linux系统引导流程

22

Sysinit 脚本文件

#!/bin/bash

#

# /etc/rc.d/rc.sysinit - run once at boot time

#

# Taken in part from Miquel van Smoorenburg's bcheckrc.

#

HOSTNAME=`/bin/hostname`

HOSTTYPE=`uname -m`

unamer=`uname -r`

set -m

if [ -f /etc/sysconfig/network ]; then

. /etc/sysconfig/network

fi

if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then

HOSTNAME=localhost

fi

if [ ! -e /proc/mounts ]; then

mount -n -t proc /proc /proc

mount -n -t sysfs /sys /sys >/dev/null 2>&1

fi

if [ ! -d /proc/bus/usb ]; then

modprobe usbcore >/dev/null 2>&1 && mount -n -t usbfs /proc/bus/usb /proc/bus/usb else

mount -n -t usbfs /proc/bus/usb /proc/bus/usb

fi

. /etc/init.d/functions

# Check SELinux status

查看当前运行级别

Runlevel

[root@localhost test]# runlevel

S 5

[root@localhost test]#

可以切换运行级别

Init 3 加上运行级别就可以了

另telinit 实际上是init的一个软链接

linux系统引导流程

[root@localhost ~]# ls -l `which telinit`

lrwxrwxrwx 1 root root 4 Jan 10 11:30 /sbin/telinit -> init

[root@localhost ~]#

[root@localhost test]# grep -v "^#" inittab | more查看文件除去行首的#

Man 不写文件的绝对路径,只写文件名就可以

Man inittab

Inittab

Id:run-levels:action:process

Id:标识符,一般为两位字母或字符

Run-levels:指定运行的级别,可以指定多个

Action:指定运行时的状态

Process:指定要运行时的脚本/命令

关于系统启动

Firmware 启动固件,post加电自检,这个是在硬件层面的检测

Bootloader 加电自检没有问题时,加载硬盘上第一分区第一个位置,启用引导程

序,在widows中为bootini (NT) 在linux 中为grub

Kernel 加载内核,内核有两个作用,一个是加载系统的驱动程序 ,一个是加

载一个进程,init

Init 由内核加载的Init进程,其父进程为内核调度器

/etc/inittab 读取配置文件,Init进程加载/etc/inittab文件,其有7种运行级别 0-6

Initdefault 设置系统默认的运行级别缺省加载的选项

/etc/rc.d/rc.sysinit 加载系统默认加载的脚本,在每个运行级别都会加载,这个在第一次

启动都会加载,如果要某个

在每一个启动时都启动,可以把服务脚本写在该文件下方 /etc/rc.d/rc 判断系统默认的运行级别,以加载相应的运行级别

/etc/rc.d/rcn.d n=0-6 加载相应的级别下的服务,其有一个软链接在/etc/init.d Username 加载完成,登陆界面

Password

关于rcn.d文件

[toshiba@localhost ~]$ ls /etc/rc.d/rc3.d

K01dnsmasq K74ntpd S12restorecond S28autofs

K02avahi-dnsconfd K85mdmpd S12syslog S55sshd

K02NetworkManager K87multipathd S13cpuspeed S56cups

K02oddjobd K88wpa_supplicant S13irqbalance S56rawdevices

K05conman K89dund S13portmap S80sendmail

K05saslauthd K89netplugd S14nfslock S85gpm

K05wdaemon K89pand S15mdmonitor S90crond

K10psacct K89rdisc S18rpcidmapd S90xfs

K10tcsd K99readahead_later S19rpcgssd S95anacron

K15httpd S00microcode_ctl S22messagebus S95atd

K20nfs S03vmware-tools S25bluetooth S97yum-updatesd

K24irda S04readahead_early S25netfs S98avahi-daemon

linux系统引导流程

K35vncserver S05kudzu S25pcscd S99firstboot

K50ibmasm S08ip6tables S26acpid S99local

K50netconsole S08iptables S26apmd S99smartd

K69rpcsvcgssd S08mcstrans S26haldaemon

K73ypbind S10network S26hidd

K74nscd S11auditd S26lvm2-monitor

[toshiba@localhost ~]$

可以看到,K = kill S = start 大写开头时的时候是在这个运行级别上的启动的,数字越小越优先启动

K用来判断在切换运行别时,需要关闭的服务

对现在的服务进行打开或关闭

如果要关闭某一个服务,直接把名字前面的S改掉就可以,启动将K变成S 一般如果关闭某个服务,将S变成s即可,方便以后操作

设置自启动方法

1.ln –s 即创建一个软链接

2.chkconfig

3.ntsysv

1. Ln –s 创建一个软链接

Vi /etc/rc.d/init.d/msg.script 创建一个要启动的文件

Date >> /root/msg.today 将date 放入msg.today 文件中

Free >> /root/msg.today 查看内存情况

Who >> /root/msg.today 查看当前在线的管理员

Chmod u+x /etc/rc.d/init.d/msg.script 给这个文件以可执行权限

Ln –s /etc/rc.d/init.d/msg.script /etc/rc.d/rc3.d/S100msg.script 在运行级别下创建一个软链接,以在这个运行级别运行时,运行 如rc3.d/S100msg.script

S: start 后写文件名

2. [root@localhost ~]# chkconfig

chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.

This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]

chkconfig --add <name>

chkconfig --del <name>

chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

3.ntsysv

linux系统引导流程

另两个应用

Dmesg 内核驱动硬件的信息

[root@localhost ~]# dmesg | grep sda

SCSI device sda: 20971520 512-byte hdwr sectors (10737 MB)

sda: Write Protect is off

sda: Mode Sense: 61 00 00 00

sda: cache data unavailable

sda: assuming drive cache: write through

SCSI device sda: 20971520 512-byte hdwr sectors (10737 MB)

sda: Write Protect is off

sda: Mode Sense: 61 00 00 00

sda: cache data unavailable

sda: assuming drive cache: write through

sda: sda1 sda2 sda3 sda4 < sda5 >

sd 0:0:0:0: Attached scsi disk sda

SELinux: initialized (dev sda2, type ext3), uses xattr

EXT3 FS on sda2, internal journal

EXT3 FS on sda5, internal journal

SELinux: initialized (dev sda5, type ext3), uses xattr

EXT3 FS on sda1, internal journal

SELinux: initialized (dev sda1, type ext3), uses xattr

Adding 2096472k swap on /dev/sda3. Priority:-1 extents:1 across:2096472k

通过这个命令可以判断硬件是否可以被识别

/var/log 这个文件里放的都是系统的日志,文件

Grep sshd /var/log/messages

本文来源:https://www.bwwdw.com/article/xow4.html

Top