1. What cropping?
The main purpose of this article is to give the author and readers a deeper understanding of the operating methods of the Linux system. The general content is to separate Linux components and assemble them one by one, and then complete a micro Linux system. next, let's implement it .. please advise on poor writing.
2. Principles
As we all know, the operating system startup process is (mainly Linux): POST-> BIOS-> MBR-kernel --> initrd --> sbin/init,
POST, BIOS is not our management, so here we start from MBR, Linux System Boot is mainly the grub software, grub boot system, and then start the kernel, the kernel calls initrd to implement the most basic operating system,
3. Next, perform the actual operation (all operations are performed on the virtual machine)
3-1. First, we need to create a new disk to save key programs such as grub and kernel (directly add a new disk to the VM)
I have already added it here, so I will not demonstrate the process of adding it. My website is divided into two zones, namely, the master disk of MB and the master disk of 1 GB. The name is
/Dev/sdg1 and/dev/sdg2. First, create two folders in the/mnt directory:
3-2. Mount/dev/sdg1 to/mnt/boot, and mount/dev/sdg2 to/mnt/sysroot.
3-3. As you know, when starting the system, in addition to hardware, the first step is to have a boot program, so we install the boot program to/mnt/boot.
Run the following command: grub-install -- root-directory =/mnt/dev/sdg1.
3-4. with the boot program, we need to have our kernel. If there is no kernel, how can we start it? However, the kernel startup depends on initrd (CentOS6), so we need to copy both files, run the following command:
Cp/boot/vmlinuz-2.6.32-358.el6.x86_64/mnt/boot/vmlunuz
Cp/boot/initramfs-2.6.32-358.el6.x86_64.img/mnt/boot/initramfs. img
3-5. the prototype of such a simple operating system is ready, but OS operations depend on shell, so we have to copy the bash shell to the/dev/sgd2 directory, so we have to copy the/bin/bash and bash dependent libraries. You can use ldd 'which bash' to check which library files bash depends on, I have a simple script here, so I will not manually copy it.
3-6. Configure the grub file. Otherwise, how can the system find your hardware? So create a configuration file for grub. conf under/mnt/boot/grub, as follows:
3-7. next, create a proc folder under/mnt/sysroot. you can use this new hard disk as the boot disk of other systems. Let's try it. You don't have to teach you how to create an empty virtual machine. then, add this disk to start it.
3-8. next we will add commands to him. In fact, it is very simple to copy the directory where the command is located and all the dependent libraries of the command to the/mnt/sysroot directory. I will not demonstrate the script. I copied some common commands, such as ls.
3-9. I have created several directories for this small system. Of course, they are added on the original master machine. Is it more and more like a system?
3-10. All right! The system is almost the same here, but we have to repair it. We can see in 3-6 that our init =/bin/bash will be asked by some people at this time, does Linux systematic initialization call/sbin/init? How did you call/bin/bash? That's right. What is the point here, now let's re-point it to/sbin/init. First, create an init file under/mnt/sysroot and add the following characters to it: remember to give/sbin/init a quick execution permission, and then set/mnt/boot/grub. change the point in conf to init =/sbin/init.
3-11. For example, the execution is successful.
3-12. Finally, we should add a network module for him. Oh, in step 3-9, we found that the disk is still read-only, so we have to re-mount it to read/write, such:
3-13. finally, we can add a network module to him. The Linux system is a single kernel, But it supports modularity. So let's add a network module to him, we need to first copy the network module of the original system to our Microsystem. All Linux modules are in/lib/module/[kernel version number]. we first use lspci or lsmod to view the network module information and then copy it to the microsystem, as shown below:
Finally, install the network module and run the insmod [path] command.
Now, the entire system has been installed!