1、查看kernel版本:
rpm -qa kernel
[root@centos6 ~]# rpm -qa kernel
kernel-2.6.32-696.el6.x86_64
2、linux :kernel +rootfs
kernel: 進程管理,內存管理,網絡管理,驅動程序,文件系統,安全功能
rootfs:程序和glibc
庫:
程序:二進制執行文件
3、內核設計流派:
單內核:把所有功能集成於同一個程序 vmlinuz-2.6.32-696.el6.x86_64
微內核:每種功能使用一個單獨子系統
4、 linux 內核特點:
支持模塊化:.ko(內核對象)
如:文件系統,硬件驅動,網絡協議
支持內核模塊的動態裝載和卸載
[root@centos6 boot]# locate ext4.ko
/lib/modules/2.6.32-696.el6.x86_64/kernel/fs/ext4/ext4.ko
lsmod 加載的模塊:
modprobe:
[root@centos6 boot]# lsmod |grep e1000
e1000 134799 0
5、 內核核心文件
[root@centos6 boot]# ll -h /boot/vmlinuz-2.6.32-696.el6.x86_64
-rwxr-xr-x. 1 root root 4.1M Mar 22 2017 /boot/vmlinuz-2.6.32-696.el6.x86_64
centos6/7:輔助的僞跟系統:initramfs-2.6.32-696.el6.x86_64.img
centos5:initrd-2.6.18-164.el5.img
查看:輔助僞跟系統:
[root@rhel5 ~]# cp /boot/initrd-2.6.18-164.el5.img /root [root@rhel5 ~]# mv initrd-2.6.18-164.el5.img initrd-2.6.18-164.el5.img.gz [root@rhel5 ~]# gzip -d initrd-2.6.18-164.el5.img.gz [root@rhel5 ~]# cpio -tv < initrd-2.6.18-164.el5.img -rw------- 1 root root 29016 Nov 2 2010 lib/ohci-hcd.ko -rw------- 1 root root 96456 Nov 2 2010 lib/mptbase.ko -rw------- 1 root root 146792 Nov 2 2010 lib/ext3.ko
6、模塊文件:
[root@rhel5 ~]# ll /lib/modules/2.6.18-164.el5/
7、centos6啓動流程:
8、post
9、rpm -qa grub
[root@rhel5 ~]# rpm -qa grub
grub-0.97-13.5
10、啓動流程:mbr
第一個階段:446字節;
第1.5階段:
[root@centos6 ~]# locate ext4.ko
/lib/modules/2.6.32-696.el6.x86_64/kernel/fs/ext4/ext4.ko
第二階段:/dev/sda1 976M 40M 886M 5% /boot
第二階段的配置文件:進入grub之後,讀取boot 下vmlinuz 內核文件,初始化內核,隨後找根目錄
根目錄:
cat /boot/grub/grub.conf
根找到了,需要根的文件系統掛載:
問題:要掛載根,根的文件系統在哪,在跟下面:
[root@centos6 ~]# locate ext4.ko
/lib/modules/2.6.32-696.el6.x86_64/kernel/fs/ext4/ext4.ko
解決根的文件系統:
initramfs-2.6.32-696.el6.x86_64.img
[root@centos6 ~]# ls /boot/initramfs-2.6.32-696.el6.x86_64.img 根的文件系統存在initramfs輔助僞根文件系統
[root@centos6 ~]# cpio -tv < initramfs-2.6.32-696.el6.x86_64.img |grep ext4.ko --color -rwxr--r-- 1 root root 646648 Jan 25 09:53 lib/modules/2.6.32-696.el6.x86_64/kernel/fs/ext4/ext4.ko
vmlinuz 存在系統光盤上:
[root@centos6 isolinux]# ll /boot/initramfs-2.6.32-696.el6.x86_64.img vmlinuz -rw-------. 1 root root 26663543 Jan 25 09:54 /boot/initramfs-2.6.32-696.el6.x86_64.img -r-xr-xr-x. 4 root root 4274992 Mar 29 2017 vmlinuz
虛擬文件系統:initramfs-2.6.32-696.el6.x86_64.img
丟失創建initramfs:
mkinitrd /boot/initramfs-`uname -r`.imag `uname -r`
實驗:1、[root@centos6 boot]# rm -f initramfs-2.6.32-696.el6.x86_64.img
實驗:2、rm -f vmlinuz-2.6.32-696.el6.x86_64
1、光盤引導:ecs按鍵
2、cd-rom drive
3、進入救援模式:
4、英文
5、不需要設置網絡
6、
7、
8、
9、chroot /mnt/sysimage ;mkinitrd initramfs-`uname -r`.img `uname -r` ;sync;sync;
10、mount /dev/sr0 /mnt; cp vmlinuz /boot/vmlinuz-`uname -r`
11、
exit
exit
reboot
12、centos6:
rpm -qf /sbin/init
upstart
rpm -qi upstart (誰提供的包)
centos5;rpm -qf /sbin/init
rpm -qi SysVinit
centos7:which init
rpm -qf /lib/systemd/systemd
rpm -qi systemd
13、
centos6: vim /etc/inittab
0 halt
1 single user mode
2 multiuser (without nfs)
3 multiuser
4 unused
5 x11
6:reboot
id 5 initdefault
14:修改啓動內核啓動參數: a 字母鍵 , 1 進入單用戶;
15、修改centos6 密碼: 進入單用戶模式:1, passwd 修改root 密碼
16、centos5/6:系統初始化流程: ecs 模式進入啓動過程
/etc/rc.d/rc.sysinit -run once at boot time
/etc/rc.d/rc.sysinit :x系統初始化腳本:
1、設置主機名;
2、設置歡迎信息
3、激活udev和selinux
4、掛載/etc/fstab 文件中定義的文件系統
5、檢測根文件系統,並以讀寫方式重新掛載根文件系統
6、設置系統時鐘
7、激活swap 設備
8、根據/etc/sysctl.conf文件設置內核參數
9、激活lvm及software raid 設備
10、加載額外設備的驅動程序
11、清理操作
17、ls /etc/rc5.d/ 指向 /etc/init.d/ (軟連接的方式,控制服務的啓動與停止)
k01smartd
/etc/rc5.d/k01smartd stop
18、獨立服務:
ls /etc/init.d
19、 ls /etc/rc5.d/ 5模式下 cpus 是啓動的 s 開頭
ls /etc/rc1.d/ 1模式下:cpus 是停止的; k 開頭
20、服務開機啓動:
chkconfig --list atd
chkconfig atd on #開啓模式
chkconifg atd off #關閉模式
chkconfig --level 35 atd off #關閉模式
runlevel
chkconfig --list
chkconfig --add testsrv
chkconfig --del testsrv
21、ll /var/lock/subsys 是否有atd 服務; (linux 啓動)
subsys=${/etc/rc$runlevel.d/k??}
[ -f /var/lock/subsys/$sybsys -o -f /var/lock/subsys/$subsys.init ] || continue
service atd status
cat /sbin/service
22、服務名次序很重要
s10 network
s55 sshd
23、依賴服務開 關順序:
s1a s2b s3c 開順序:
k3c k2b k1a 關順序:
23、編寫服務腳本:
/etc/init.d/atd restart
service atd restart
chkconfig --list
cat /etc/init.d/atd
chkconfig :345(level on) 95(s) 5(k)
vim /etc/inti.d/testsrv #!/bin/bash #chkconfig: 35 96 4 #description:test service source /etc/init.d/functions case $1 in start) [ -f /var/lock/subsys/testsrv ] && action "testsrv is started " touch /var/lock/subsys/testsrv action "testsrv is starting /Starting sshd " sleep 3 ;; stop) rm -f /var/lock/subsys/testsrv action "testsrv is stopped" ;; status) [ -f /var/lock/subsys/testsrv ] && echo testsrv is starting || echo testsrv is stooped ;; *) echo "usage:service test start|stop|status" ;; esac
chmod +x /etc/init.d/testsrv
chkconfig --add testsrv
chkconfig --list testsrv
chkconfig --level 5 testsrv off /chkconfig testsrv off
ls /etc/rc5.d/
k03testsrv
ctrl +alt +delete 重啓
24、通用腳本:
ls /etc/rc{1,2,3,4,5}.d/
ll /etc/rc5.d/s99local
/etc/rc5.d/s99local --> ../rc.local
25、cat /etc/rc.local 開機自動啓動服務
26、service --status-all
27、centos6:xinetd
telnet-server 依賴與xineted 服務
yum install telnet-server
yum install telnet
telnet :off
chkconfig telnet on 啓動服務;
ll /etc/xineted.d/telent
service xineted start 啓動xineted 腳本;
ss -nlt 查看監聽端口:xineted 監聽23 端口;
28、cat /etc/initttab
ctrl+ alt |delete /etc/init/control-alt-delete.conf 重啓機器
exec /sbin/shutdown -r now "control-alt-delete pressed "
29、ups :機器停電,提供電池,讓機器正常關機,避免出現故障
30、pa aux |grep mingetty (負責登錄界面 )
respawn 再生
31、總結:centoss5;
/sbin/init --> (/etc/inittab)--> 設置默認運行級別-->運行胸痛初始化腳本、完成系統初始化--》 (關閉
對應下需要關閉的服務)啓動需要啓動服務-->--設置登錄終端
32、centos6
CentOS 6啓動流程:
POST --> Boot Sequence(BIOS) --> Boot Loader --> Kernel(ramdisk) -->
rootfs --> switchroot --> /sbin/init -->(/etc/inittab, /etc/init/*.conf) --> 設定默認
運行級別 --> 系統初始化腳本rc.sysinit --> 關閉或啓動對應級別的服務 --> 啓動終端
33、grub 0.97
hexdump -C -n 512 /dev/sda ddi if=/dev/sda of=/dev/data/mbr bs=1 count=446 dd if=/dev/zero of=/dev/sda bs=1 count=446 hexdump -C -n 512 /dev/sda -V reboot
34、修復grub
救援模式:
dd if=/dev/zero of=/dev/sda bs=1 count=446
chroot /mnt/sysimage
grub-install /dev/sda
sync
sync
35、單用戶模式:seliux=0
36、grub-install 修復grub
root@centos6 grub]# ls device.map grub.conf minix_stage1_5 stage2 e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5 fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5 ffs_stage1_5 menu.lst stage1 xfs_stage1_5 [root@centos6 grub]# dd if=/dev/zero of=/dev/sda bs=1 count=446 [root@centos6 grub]# grub-install /dev/sda [root@centos6 grub]# hexdump -C -n 512 /dev/sda
37、1.5階段修復:
grub-install ;救援模式;需要切根 ;
hexdump -C -n13824 /dev/sda -v (27(扇區)*512=13824)
dd if=/dev/zero of=/dev/sda bs=1 count=10000 skip=512 seek=512
[root@centos6 grub]# hexdump -C -n 13824 /dev/sda -v
進入磁盤救援模式:
grub
root (hd0,0) #第一個磁盤第一個分區
setup (hd0)
exit
exit
reboot
重啓機器: ecs 進入單用戶模式:a 字符,selinux=0 跳過selinux 檢查;
38、
[root@centos6 ~]# cat /boot/grub/grub.conf 配置文件詳解:
title CentOS 6 (2.6.32-696.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=rel=aut o KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-696.el6.x86_64.img title centos8 (sun-linux) kernel (hd0,0)/vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=c07de17f-dc51-47bc-9f43-68 b025026209 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashker nel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd (hd0,0)/initramfs-2.6.32-696.el6.x86_64.img title centos9 (sun-linux) kernel (hd0,0)/vmlinuz-2.6.32-696.el6.x86_64 root=/dev/sda2 (rhgb 去掉圖形界面;quiet 顯示內核輸出 ) initrd (hd0,0)/initramfs-2.6.32-696.el6.x86_64.img
40、
[root@centos6 ~]# cat /boot/grub/grub.conf 配置文件詳解:
title centos9 (sun-linux) initrd (hd0,0)/initramfs-2.6.32-696.el6.x86_64.img kernel (hd0,0)/vmlinuz-2.6.32-696.el6.x86_64 root=/dev/sda2 (rhgb 去掉圖形界面;quiet 顯示內核輸出 )
啓動菜單:
e 編輯 ,d
initrd (hd0,0)/initramfs-2.6.32-696.el6.x86_64.img
o 新增一行:
e 編輯 刪掉的那一行:支持自動補全
initrd /initramfs-2.6.32-696.el6.x86_64.img
b 啓動
grub 編輯二階段;
41、
windows 打開剪貼板:mspaint; 像素:640*480
splashimage=(hd0,0)/grub/splash.xpm.gz
[root@centos6 ~]# ls /boot//grub/splash.xpm.gz
gzip -d /boot//grub/splash.xpm.gz
gunzip /boot//grub/splash.xpm.gz
[root@centos6 app]# rpm -qa ImageMag*
ImageMagick-6.7.2.7-6.el6.x86_64
[root@centos6 app]# convert -resize 640x480 -colors 14 win.jpg win.xpm
head win.xpm
[root@centos6 app]# cp win.xpm.gz /boot/grub/
[root@centos6 ~]# vi /boot/grub/grub.conf
splashimage=(hd0,0)/grub/win.xpm.gz
reboot
42、單用戶增加密碼:
[root@centos6 ~]# vi /boot/grub/grub.conf
default=0
password centos
password --md5 $grub-md5-crypt
password --encrypted $grub-crypt
timeout=5
MD5生成密鑰口令;
grub-md5-crypt
grub-crypt