Linux initrd has many things worth learning. Here we mainly introduce Linux initrd, including introduction to nash and so on. Linux initrd focuses on many important things, the execution of init is divided into the following operations. Please understand each part.
Define the path of the main directory (root)
The mkrootdev command is a function provided by the nash shell. The main function is to clearly define the main directory before conversion, by default, the xxx path in root = xxx set by the kernel command line in GRUB is created first.
Mount the root path to/sysroot and mount the root path you just found to/sysroot in Linux initrd, at this time,/sysroot is like the/mnt/sysimage directory of rescue mode, you only need to mount the Object Path of the object operating system to the temporary directory of a Virtual Operating System (initrd here), and then switch to the main directory of the object. The difference is that chroot is used in rescue mode, but switchroot is used in Linux initrd. The reason for this difference is that rescue mode directly uses OS commands, however, when loading initrd, there is no operating system instruction available, so it is implemented through the built-in instruction of nash. Someone may ask, isn't the rescue mode loaded in Linux initrd mode? Yes, but here I want to add that although all of them are Linux initrd, initrd in rescue mode is provided directly by the CD, the Linux initrd mentioned here is directly generated by the operating system after the operating system is installed. There are many differences between the two. If you are interested, open the initrd file on the CD (4-45) and you will find that the init file in the Linux initrd is not a script file, but a program that can actually be executed in the operating system.
Of course, the Linux initrd file stored in CD or DVD is used by users to install the operating system, and many different requirements for software and hardware are met. Therefore, initrd files require much more information (such as module) than Linux initrd files to be loaded when the operating system starts up. As shown in Figure 4-46, the initrd file in the ora Core 6 installation disc is almost four times the number of initrd files in the operating system.
Create other file systems
After the main directory (/sysroot in initrd stage) is created, the setuproot command starts to run, transfers all the data in the/proc,/sys, And/de directories established by Linux initrd through init to/sysroot to facilitate conversion to the new real operating system. This is also the built-in function of nash, however, I cannot find any descriptions about setuproot In the nash user manual, and I do not know why this one is missing.
Switch to the new root directory and start executing the init file in the object system.
Switchroot is a new function that can be used by nash Versions later than kernel 2.6. Just now, setuproot created all operating system-related directories in/sysroot, setuproot will switch/sysroot to the main directory (/) in the real operating system. After this is done, all the information in the memory of Linux initrd will be cleared by the way, as with all data in a Virtual File System (including/sys,/proc, or/dev), when switchroot is executed, in the memory, there will be no directories and files created by Linux initrd, and they are fully run by the real operating system.
Summary
Do not use the setuproot and switchroot functions supported by nash in your computer experiment, although this chapter describes how to execute nash and how to actually use features in nash, if setuproot and switchroot are used, they will cause damage to the operating system, especially switchroot. The reason is that the two are originally to be prepared for switching to the real operating system, but it is not true that the path itself exists is a memory or a real hard disk.
When the user executes the command, the setuproot will force the file/proc,/sys, And/dev in the operating system to be moved first, many important files will be deleted, leading to the failure to boot normally. Even worse, switchroot will be executed. we mentioned that this function will clear all the files left after switching, in the real operating system, this means to delete all the data in the hard disk. Therefore, after executing switchroot, only the original console screen will accompany you, after the reboot, there will be no more users. If you want to experiment, you must be clear about it before you start.
Of course, after switchroot executes the program, it enters the operating system program, and this important responsibility is handed over to the init program in the real operating system. The next chapter will start with init, every step of the login screen will be clearly explained. Of course, Linux initrd has different versions and operating system vendors (such as Red Hat, SuSE, and Debian) in each version) there are more or less differences, but after all, they all use the kernel of Linux initrd. After learning about one of them, they will certainly have a clear understanding of each version.
- Brief Introduction to Linux kernel system applications
- Linux Command Line Kernel System
- Install Linux on the network
- Stable and easy-to-use Linux Desktop System
- Brief Introduction to Linux Application