在上一篇随笔里面详细讲解了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
新闻热点
疑难解答