Linux's interesting single-user mode analysis

Source: Internet
Author: User
Linux's interesting single-user mode analysis-Linux general technology-Linux programming and kernel information. The following is a detailed description. Single User Mode
If run-level is equal to 1, it will enter the single-user mode. Generally, you do not need to enter the password when entering the single-user mode. Therefore, if you forget the root password, you can enter the single-user mode and change it with passwd.

In single-user mode, there is no network, and the services seen in chkconfig are not started. Go to/etc/rc. d/rc1.d and run the ls command to see what files are in it:

We will find that there are only two files starting with S, and all others are files starting with K. S indicates start, and K indicates kill.

In Bootloader, we have mentioned that the single parameter passed to the kernel will enter the single-user mode. Is there any difference between the single-user mode and the single-user mode with run-level = 1?

In addition, we can pass init =/bin/bash to the kernel in bootloader. What is the difference with single-user mode.

The second problem is to let the kernel start bash as init, So What init does will not be done either, after the kernel is loaded, the control is handed over to the shell. The startup information is much shorter:

At this time, the loaded/should be only the/loaded by the kernel. Generally, we load it with readonly (remember the parameters in chapter 1 ), therefore, all files in this environment are readonly. Of course, if we want to change the file content, we can remount the root directory /.

First, let's see what the system is mounted at this time:
$ Mount
/Dev/mapper/VolGroup00 on/type ext3 (rw)
None on/proc type proc (rw)

I don't quite understand whether the first row of the result (rw) is the meaning of read write, but the/at this time is indeed readonly.

Re-mount the root directory/to read write: $ mount? O remount rw/

Everything is okay. Now we can edit the files we need. However, remember that the functions of init and shell are very different. This is just a very incomplete Linux environment, and many things cannot be used.

So the single and run-level parameters of bootloader are equal to 1. We assume that/etc/inittab is lost for various reasons. After restarting, after init is controlled, the/etc/inittab cannot be found. Therefore, you must enter runlevel. No matter what you enter, 1-5 will crash, because init does not know what to do.

What should we do?
Try to pass the single parameter to the kernel (don't forget it). We will find that although init cannot find the/etc/inittab, the control is handed to the shell.

It's really interesting.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.