系統初始化

系統初始化
查看 uname –r
操作系統版本號 cat /etc/redhat-release
查看主機名uname -n
查看平臺 uname -p
進入 boot執行ll命令得到
 
第四行爲所需加載的驅動 最後一行爲虛擬內核
服務***************************************
chkconfig –list 查看服務
chkconfig --list |grep sendmail 查看郵件服務
rpm -e服務名, 卸載服務
rpm –q --scriptes httpd ,顯示動作
chkconfig --level 3(級別) sendmail(服務) off(狀態)
setup只能設置當前的級別
ntsysv
service httpd (服務) start(動作,stoprestart)
/etc/init.d/服務 動作
服務分兩類 獨立(存放於/etc/init.d/) 依賴於超級守護進程 (存放於 /etc/xinetd.d)
防火牆 以及selinux影響服務的執行
Init /etc/inittab 充電自檢
開機自檢(BIOS)》》MBR引導 (512字節)》》GRUB菜單》》加載內核(kernel)》》運行INIT進程》》讀取/etc/inittab配置文件,》》執行/etc/rc.d/rc.sysinit腳本
| i 》》執行/etc/rc.d/rc腳本
 
執行/etc/c.d/rc.local |
|
啓動mingetty進程
 
 
進入grub ,cd /boot/grub 查看 ll
grub-install /dev/sda 導入
grub-install –root-directory=/ /dev/sda 導入
vim /etc/grub.conf 查看配置腳本
[root@localhost ~]# vim /etc/grub.conf
 
# 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 等待時間過後5秒後自動選擇
splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz grub的背景圖片
hiddenmenu 隱藏grub菜單
title Red Hat Enterprise Linux Server (2.6.18-164.el5) title爲標籤
ro ot (hd0,0) 引導分區根
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet 內核爲kernel
initrd /initrd-2.6.18-164.el5.img驅動程序
[root@localhost ~]# findfs LABEL=/ 查找標籤爲 / 的所在
/dev/sda2
 
 
-rw------- 1 root root 2602240 02-21 15:10 initrd-2.6.18-164.el5.img
[root@localhost abc]# zcat initrd-2.6.18-164.el5.img |cpio –id 解壓驅動包
11611 blocks
[root@localhost abc]# ll
?昏. 2580
drwx------ 2 root root 4096 02-21 15:15 bin
drwx------ 3 root root 4096 02-21 15:15 dev
drwx------ 2 root root 4096 02-21 15:15 etc
-rwx------ 1 root root 2536 02-21 15:15 init
-rw------- 1 root root 2602240 02-21 15:10 initrd-2.6.18-164.el5.img
drwx------ 3 root root 4096 02-21 15:15 lib
drwx------ 2 root root 4096 02-21 15:15 proc
lrwxrwxrwx 1 root root 3 02-21 15:15 sbin -> bin
drwx------ 2 root root 4096 02-21 15:15 sys
drwx------ 2 root root 4096 02-21 15:15 sysroot
 
 
[root@localhost abc]# vim /etc/inittab 進入初始化表
 
1 #
2 # inittab This file describes how the INIT process should set up
3 # the system in a certain run-level.
4 #
5 # Author: Miquel van Smoorenburg, <[email protected]>
6 # Modified for RHS Linux by Marc Ewing and Donnie Barnes
7 #
8
9 # Default runlevel. The runlevels used by RHS are:
10 # 0 - halt (Do NOT set initdefault to this)
11 # 1 - Single user mode
13 # 3 - Full multiuser mode
14 # 4 - unused
15 # 5 - X11
16 # 6 - reboot (Do NOT set initdefault to this)
17 #
18 id:3:initdefault:
19
20 # System initialization.
21 si::sysinit:/etc/rc.d/rc.sysinit 進入級別前所需執行的腳本(初始化腳本)
22
23 l0:0:wait:/etc/rc.d/rc 0
24 l1:1:wait:/etc/rc.d/rc 1
25 l2:2:wait:/etc/rc.d/rc 2
26 l3:3:wait:/etc/rc.d/rc 3
27 l4:4:wait:/etc/rc.d/rc 4
28 l5:5:wait:/etc/rc.d/rc 5
29 l6:6:wait:/etc/rc.d/rc 6
30
31 # Trap CTRL-ALT-DELETE
32 ca::ctrlaltdel:/sbin/shutdown -t3 -r now 條件滿足可重啓
33
34 # When our UPS tells us power has failed, assume we have a few minutes
35 # of power left. Schedule a shutdown for 2 minutes from now.
36 # This does, of course, assume you have powerd installed and your
37 # UPS connected and working correctly. UPS備用電源
38 pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
39 電源失效執行動作 –f快速啓動
40 # If power was restored before the shutdown kicked in, cancel it.
41 pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
42 來電了 取消shutdown
43
44 # Run gettys in standard runlevels
45 1:2345:respawn:/sbin/mingetty tty1 (2345代表級別 啓動sbin/mingetty tty終端)
46 2:2345:respawn:/sbin/mingetty tty2 (respawn動作 註銷亦執行)
47 3:2345:respawn:/sbin/mingetty tty3
48 4:2345:respawn:/sbin/mingetty tty4
49 5:2345:respawn:/sbin/mingetty tty5
50 6:2345:respawn:/sbin/mingetty tty6
51
52 # Run xdm in runlevel 5
53 x:5:respawn:/etc/X11/prefdm –nodaemon進5級別所需執行的腳本
[root@localhost abc]# file /etc/rc.d/rc.sysinit 查詢其腳本類型
/etc/rc.d/rc.sysinit: Bourne-Again shell script text executable 可執行bash腳本
Im
 
[root@localhost abc]# vim /etc/rc.d/rc.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
"/etc/rc.d/rc.sysinit" 980L, 27239C

故障排除
事例1 模擬grub損壞
[root@localhost rc3.d]# dd if=/dev/zero of=/dev/sda bs=446 count=1
1+0 records in
1+0 records out
446 bytes (446 B) copied, 0.000131491 seconds, 3.4 MB/s
執行後 發現正常啓動不了



執行Linux rescue 緊急救援模式
進入sysp_w_picpath下 cd /mnt/sysp_w_picpath
Chroot /mnt/sysp_w_picpath
Grub-install /dev/sda
Exit
Exit
系統將會重啓 完畢
事例2
刪除boot/grub/下面的grub.conf
[root@localhost ~]# mv /boot/grub/grub.conf /boot/grub/grub.conf.old 改動grub.conf名=刪除
重新啓動後如下所示
進入grub下,執行如下命令,分別實現 找硬盤,加載內核,加載驅動,然後 boot重啓,

重啓後記得要將/boot/grub下的grub.conf恢復或者手工編輯




 





事例三 ,模擬啓動中加載的fstab文件出錯 先插入我姓名的拼音hanfang


 

重新啓動 發現failed 原因是未能識別“hanfangLABEL=/”輸入管理員口令進入命令行模式



修改權限,


編譯修改/etc/fstab文件,退出並保存然後重啓 ,OK了,

希望對您有所幫助(……)
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章