1、請詳細描述CentOS系統的啟動流程(詳細到每個過程系統做了哪些事情)
a,post:加電自檢,通電搜索并檢查物理設備的狀態
b,bootsequeence(BIOS):選擇啟動順序
c,bootloader(MBR):加載主引導程序 bootloader,硬盤分區表到內存
d,加載內核kernel
e,只讀方式掛載根分區文件系統(rootfs)
f,系統初始化(運行/sbin/init)
g,根據 /etc/inittab 中的啟動級別,運行系統初始化腳本 /etc/rc.d/rc.sysinit,打開或關閉對應啟動級別下的服務(運行 /etc/rc.d/rcx.d/ 下的腳本)
h,啟動終端
2、為運行于虛擬機上的CentOS 6添加一塊新硬件,提供兩個主分區;
(1) 為硬盤新建兩個主分區;并為其安裝grub;
(2) 為硬盤的第一個主分區提供內核和ramdisk文件; 為第二個分區提供rootfs;
(3) 為rootfs提供bash、ls、cat程序及所依賴的庫文件;
(4) 為grub提供配置文件;
(5) 將新的硬盤設置為第一啟動項并能夠正常啟動目標主機;
[root@server ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9056db41.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088): +256M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (35-2088, default 35):
Using default value 35
Last cylinder, +cylinders or +size{K,M,G} (35-2088, default 2088): +4G
Command (m for help): w
The partition table has been altered!
[root@server ~]# mkfs.ext4 /dev/sdb1;mkfs.ext4 /dev/sdb2
[root@server ~]# mkdir /mnt/{boot,sysroot}
[root@server ~]# mount /dev/sdb1 /mnt/boot/ ; mount /dev/sdb2 /mnt/sysroot/
[root@server ~]# ls /mnt/{boot,sysroot}
[root@server ~]# grub-install –root-directory=/mnt /dev/sdb #復制 GRUB 鏡像到 /mnt 的 boot 目錄下
[root@server ~]# cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /mnt/boot/
[root@server ~]# cp /boot/initramfs-2.6.32-431.el6.x86_64.img /mnt/boot/
[root@server ~]# vim /mnt/boot/grub/grub.conf #新建一個 grub 配置文件
default=0
timeout=15
title CentOS6.5 homemake
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sdb2 selinux=0 init=/bin/bash
initrd /initramfs-2.6.32-431.el6.x86_64.img
使用第8題的腳本復制bash、ls、cat響應文件到 rootfs
新建一個虛擬機掛載此虛擬機的sdb磁盤啟動
3、制作一個kickstart文件以及一個引導鏡像。描述其過程。
####制作 ks 文件的方法
a 通過 system-config-kickstart 生成ks配置文件
b 通過復制已有系統ks配置文件并自定義配置
[root@cent7-server ~]# cp /root/anaconda-ks.cfg myks.cfg #復制root目錄下的ks配置文件,修改其中選項
[root@cent7-server ~]# vim myks.cfg
#version=RHEL7
# System authorization information
auth –enableshadow –passalgo=sha512
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot –enable
ignoredisk –only-use=sda
# Keyboard layouts
keyboard –vckeymap=us –xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network –bootproto=static –device=ens160 –onboot=on –ipv6=auto
network –hostname=localhost.localdomain
# System timezone
timezone China/Beijing –isUtc
# System bootloader configuration
bootloader –location=mbr –boot-drive=sda
# Partition clearing information
clearpart –none –initlabel
part /boot –fstype=ext4 –size=200
part / –fstype=ext4 –size=16000
part /swap –size=1024
repo –name="CentOS" –baseurl=cdrom:sr0 –cost=100
%packages
@base
@core
%end
[root@cent7-server ~]# ksvalidator myks.cfg #檢查配置文件語法
#### 制作引導盤
[root@cent7-server ~]# mkdir /media/test-cdrom
[root@cent7-server ~]# mount /dev/cdrom /media/test-cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@cent7-server ~]# mkdir /tmp/test-iso
[root@cent7-server ~]# cd /tmp/test-iso/
[root@cent7-server test-iso]# cp -a -r /media/test-cdrom/isolinux/ .
[root@cent7-server test-iso]# cp ~/myks.cfg .
[root@cent7-server test-iso]# ll
total 8
drwxr-xr-x. 2 root root 4096 Jul 4 2014 isolinux
-rw——-. 1 root root 804 Oct 17 10:03 myks.cfg
[root@cent7-server test-iso]# mkisofs -R -J -T -v –no-emul-boot –boot-load-size 4 –boot-info-table -V "my-test-Cent7-boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /tmp/test-iso/
4、寫一個腳本
(1) 能接受四個參數:start, stop, restart, status
start: 輸出“starting 腳本名 finished.”
…
(2) 其它任意參數,均報錯退出;
#!/bin/bash # if [ $# -ne 1 ];then echo "Usage: $0 start|stop|restart|status" exit fi case $1 in start) echo "starting $0 finished" ;; stop) echo "stop $0 finished" ;; restart) echo "restart $0 finished" ;; status) echo "$0 status" ;; *) echo "wrong argument" echo "Usage: $0 start|stop|restart|status" ;; esac
5、寫一個腳本,判斷給定的用戶是否登錄了當前系統;
(1) 如果登錄了,則顯示用戶登錄,腳本終止;
(2) 每3秒鐘,查看一次用戶是否登錄;
#!/bin/bash # if [ $# -ne 1 ];then echo "Usage: $0 username" exit fi while id $1 &> /dev/null ;do if who | grep "\<$1\>" &> /dev/null;then echo "User $1 is online" exit else sleep 3 echo "User $1 is offline" fi done
6、寫一個腳本,顯示用戶選定要查看的信息;
cpu) display cpu info
mem) display memory info
disk) display disk info
quit) quit
非此四項選擇,則提示錯誤,并要求用戶重新選擇,只到其給出正確的選擇為止;
#!/bin/bash # while true;do read -p "input your select: cpu|mem|disk|quit " text case $text in cpu) cat /proc/cpuinfo && exit;; mem) free -m && exit;; disk) df -h && exit;; quit) exit ;; *) echo "wrong choice" continue ;; esac done
7、寫一個腳本
(1) 用函數實現返回一個用戶的UID和SHELL;用戶名通過參數傳遞而來;
(2) 提示用戶輸入一個用戶名或輸入“quit”退出;
當輸入的是用戶名,則調用函數顯示用戶信息;
當用戶輸入quit,則退出腳本;進一步地:顯示鍵入的用戶相關信息后,再次提醒輸出用戶名或quit:
#!/bin/bash # UserInfo () { id -u $username sed -n "/\<$username\>/p" /etc/passwd | awk -F: '{print $7}' } while true;do read -p "pls input username: " username if [ -z "$username" ];then echo "you must input username" exit fi if id $username &> /dev/null;then UserInfo $username continue elif [ "$username" == "quit" ];then exit else echo "invaild username" fi done
8、寫一個腳本,完成如下功能(使用函數)
(1) 提示用戶輸入一個可執行命令的名字;獲取此命令依賴的所有庫文件;
(2) 復制命令文件至/mnt/sysroot目錄下的對應的rootfs的路徑上,例如,如果復制的文件原路徑是/usr/bin/useradd,則復制到/mnt/sysroot/usr/bin/目錄中;
(3) 復制此命令依賴的各庫文件至/mnt/sysroot目錄下的對應的rootfs的路徑上;規則同上面命令相關的要求;
#!/bin/bash # Judge () { if [ -z "$cmd" ] || ! which $cmd &> /dev/null ;then echo "wrong command!" exit fi } Copy_cmd () { [ ! -d $cmd_dir ] && mkdir -p $cmd_dir &> /dev/null cp $(which $cmd) $cmd_dir } Copy_lib () { echo $lib_path mkdir -p /mnt/sysroot/lib{,64} for list in $lib_path;do cp $list /mnt/sysroot$list done } read -p "pls input an executable command: " cmd cmd_path=$(which $cmd | grep -o "^/.*\/") cmd_dir=/mnt/sysroot$(dirname $(which $cmd)) lib_path=$(ldd $(which $cmd) | grep -o "/[^[:space:]]\{1,\}") Judge Copy_cmd Copy_lib
原創文章,作者:Net21_木頭,如若轉載,請注明出處:http://www.www58058.com/47488
開機啟動流程 如果能用圖來說明就更好了,還有你的每一條命令,如果是為同一問題的答案,可以用“代碼”美化一下