在上一篇隨筆里面詳細講解了Linux系統的啟動過程、,我們知道Linux系統的啟動級別一共有6種級別,通過 /etc/inittab 這個文件我們就能看到:
[root@xiaoluo ~]# cat /etc/inittab# inittab is only used by upstart for the default runlevel.## ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.## System initialization is started by /etc/init/rcS.conf## Individual runlevels are started by /etc/init/rc.conf## Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf## Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,# with configuration in /etc/sysconfig/init.## For information on how to write upstart event handlers, or how# upstart works, see init(5), init(8), and initctl(8).## Default runlevel. The runlevels used are:# 0 - halt (Do NOT set initdefault to this)# 1 - Single user mode# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)# 3 - Full multiuser mode# 4 - unused# 5 - X11# 6 - reboot (Do NOT set initdefault to this)# id:5:initdefault:
這里我們看到系統的默認啟動級別是5,也就是有圖形界面的那個。
但是在現實生活中可能會出現這種問題,我們可能忘記了一臺主機的root密碼,但是我們又需要通過root用戶登錄該系統去處理一些事情,這個時候我們怎么辦呢?我們看到在Linux的啟動級別中有一個單用戶模式啟動,也就是啟動級別1,當我們如果忘記了root用戶的秘密,但是又需要修改root密碼的時候,這個時候我們就要通過在啟動的時候給系統的內核傳遞一個參數 1 或者 single 來告訴內核,我需要以單用戶模式登陸操作系統,這個時候我們就能能夠通過passwd 命令來重設root用戶的密碼。具體操作是怎樣的呢?咱們有圖有有真像!!
首先我們重啟我們的系統(我這里是CentOS),然后在界面啟動時讓它停留一下,隨便按一下鍵盤上的一個鍵,此時就會進入到操作系統配置引導界面
還記得上一篇隨筆里面/boot/grub/grub.conf這個文件里的第一個 title 字段嗎? 沒錯,每一個title都是一個操作系統的配置選項,這里我們只有一個,也就是上面圖片顯示的那個,如果有多個title字段,這里就會列出來供我們選擇不同的操作系統。
好了,通過下面的英文提示我們發現按下鍵盤上的 e 鍵就可以進入到編輯界面
[root@xiaoluo ~]# cat /boot/grub/grub.conf# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You do not have a /boot partition. This means that# all kernel and initrd paths are relative to /, eg.# root (hd0,1)# kernel /boot/vmlinuz-version ro root=/dev/sda2# initrd /boot/initrd-[generic-]version.img#boot=/dev/sdadefault=0timeout=5splashimage=(hd0,1)/boot/grub/splash.xpm.gzhiddenmenutitle CentOS (2.6.32-358.el6.x86_64) root (hd0,1) kernel /boot/vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=6e24ec7a-2d19-466e-bacc-92750b1f4bef rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /boot/initramfs-2.6.32-358.el6.x86_64.img
新聞熱點
疑難解答