Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the Linux peripheral file system

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to customize the Linux peripheral file system, the article is very detailed, has a certain reference value, interested friends must read it!

Train of thought

Copy the necessary components to the new memory using the original system

Testing in RAM Disk using initrd.img Mechanism

Match the original file kernel and module startup

Step1: get the shell version of initrd.img

First, we can write a script init so that the kernel can get a Bash directly after booting with the file system.

Create script init

Among them: / bin directory is the common command, init is the script written by yourself, / lib64 directory is the dynamic library that the application depends on.

Init content

Now we need to use the command line to create the bin and sbin directories and add basic commands such as bash, ls, rm, cp, mv, echo, cat, less, and so on. Since these commands rely on some dynamically linked shared libraries in directories such as / lib64, you need to copy the dependent libraries to the corresponding directory of the small system, and use the ldd command to query the application and its dependent dynamic libraries. When complete, execute:

Find. | | cpio-H newc-o | gzip > / boot/initrd.img |

Package the root file system as initrd.img and put it in the / boot directory. The system automatically executes init in initrd.img at startup.

After so much effort to generate initrd.img, how to test the newly created initrd.img, you need to add an entry to the grub startup configuration file for testing.

Title CentOS 6 Miniroot (hd0,0) kernel / vmlinuz-2.6.32-642.el6.x86_64initrd / initrd.img

In this way, the startup option will appear after the restart.

Step2: complete the ability to mount the original system

In order to mount the original system, you must load the driver modules necessary for the original system to run in initrd.img, such as the driver of the ext4 file system, the driver of the scsi device, etc., / sbin/modinfo with / sbin/insmod, and the driver into / module

Step3: complete the ability to own and manage devices (udev)

It is more reliable than our own implementation to automatically load the required driver module by using the service program udevd, which manages and monitors the host equipment. The rule file of udevd is in the / lib/udev/ directory, the configuration file is in the / etc/udev/ directory, and the name service exchange of the / etc/nsswitch.conf configuration is also required. The dependent library is the file that starts with libnss in the / lib directory. Copy the above files to our directory, and then use the command / sbin/start\ _ udev to start the udevd service. Udevd needs to call some other system commands, such as / sbin/modprobe, which can be traced and fetched by strace.

Directory file of the mini system

Where: / dev directory is the directory where the system stores available devices, and / log is the log record file generated using the strace command.

Step4: complete the login login capability

Because the mechanism of login is complex, involving many aspects such as process management mechanism, process group, console and so on, we use * M2 * to copy the / sbin/init command to the mini system directory, and the init script is changed to

#! / bin/bashexec / sbin/init

After giving control to / sbin/init, the system must wait until it completes a series of calls and enter the login interface before the user can regain control.

The process of / sbin/init is roughly divided into three parts: * block is the udevd load driver module, file system check and root switch, and the relevant configuration is in / etc/rc.sysinit; the second block is to start various services, which is configured in the / etc/rc.d/ directory; the third block is the login part, which needs to call commands such as / sbin/mingetty and / bin/login. Copy the above-mentioned commands and files to the corresponding directory of the small system, and modify the configuration.

Since initrd.img runs directly in memory as a temporary root file system after the mini system starts, and our small system does not need to make a root switch, note the body of the remount\ _ needed () function in / etc/rc.sysinit, so that the root switch will not be done.

Since the system uses a new Upstart startup method (/ sbin/init program has been provided by the upstart software package), copy the configuration files related to Upstart startup to the mini system directory:

/ etc/inittab configuration default run level / etc/init/rcS.conf loads rc.sysinit script to complete system initialization task / etc/init/rc.conf compatible script Responsible for call processing at each run level / etc/init/rcS-sulogin.conf starts for single user mode / sbin/sushell environment / etc/init/control-alt-delete.conf control terminal Ctrl+Alt+Del hotkey operation / etc/init/start-ttys.conf configuration tty terminal open number, device file / etc/sysconfig/init control tty terminal open number, terminal color scheme / etc/init/tty.conf control tty terminal open

Change the running priority of bootmini/etc/inittab to 2, then / sbin/init will execute files in the bootmini/etc/rc.d/rc2.d/ directory that start with S and change the names of some service files that do not need to be opened to start with K.

The operation that the user needs to perform automatically after the system is booted can be added to the bootmini/etc/rc.d/rc.local file.

Login program is based on authentication system PAM, configuration files are in / etc/pam.d/ directory, related library files are / lib64/security/ and its dependent library files; login also involves user group management / bin/chgrp, / bin/chown, / bin/chmod, etc., saving user name files / etc/passwd, / etc/group, user password file is / etc/shadow. Some of the other files involved can be analyzed through strace.

A complete version of the mini system that can be run on a real machine

Some directory files:

/ etc

/ bin

/ sbin

/ usr/bin

/ usr/sbin

At this point, the file system is ready to run.

The above is all the contents of the article "how to customize the Linux Peripheral File system". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report