Enter Linux operating system

xiaoxiao2021-03-06  21

Author: Chen Wei: Dr. computers, has long been engaged linux Linux systems technology industrial research and development, the current Ministry of Information Industry Software and Integrated Circuit Promotion Center chief engineer, is the basis of China's Linux platform (china linux basic platform) project leader. If you need to contact him by chenwei@csip.org.cn: Master of computer, mainly engaged in the research and development of Linux operating system kernel, Linux technology standard, computer security, software testing, is currently the software and The Director of the MII-HP Linux Software Laboratory belonging to the integrated circuit promotion center. If you need to contact him via kangh@csip.org.cn.

Abstract: After the period of the operation system, it will join hands to join hands into the Linux world. We try to show a panoramic map of the Linux system and set up a test system that runs in memory in order to deepen a comprehensive approval of the Linux system. At the same time, I provide you with several shell scripts to help build a test system. The most familiar stranger describes the use of Xiao Yaxuan's song to describe the feeling of the operating system, but "the most familiar stranger". To be familiar, because in almost every day, we are intended to be unintentional and there is a hand. Whether it is daily office, or swim online, we can't leave the help of the operating system. The computer is started, and the first is the operation system. For many people, the computer is the "window". Even if you are far from your computer, we still can't escape the "Mao" of the operating system. When you send and receive text messages, when making a call, a embedded operating system behind the phone screen is silently serving you. More and more digital devices have started its own operating system, although they are different from BILL to our "window", but there is no essential difference. If one day, your TV starts to warm your cold, please don't forget, there is a thing called the operating system behind it. To be unfamiliar, because most of the applications are directly applied to our services, maybe text processing, maybe email, maybe online games. They are all running on the operating system, providing the services we need, which makes us rarely face the operating system. For most users, the details of the operating system are invisible, so, although we are not in the same way, there is a layer of separation between each other. For the awareness of the operating system, it is often only possible to stay on indirectly, on the basis of one-sided, and we cannot be able to make a look at it. Everywhere is not in front of it, so that the operating system has a "still" beauty, so the operating system is crowned with "the most mysterious" title. Uncovering this mystery of this layer is the original intention of our magazine. We hope to interpret operating system design ideas, and familiarize yourself with the various services provided by your operating system, learn how to use these services and how to use these services. We will combine examples in theoretical discussion, let you have the skills of operating system-level development software with us. Ok, start our kernel trip, approach this "most familiar stranger"!

This goal! In the first phase, we will: outline the basic concept of the operating system; it is clear that the relationship between the operating system and other system software or application software; understand the architecture of the operating system; on this basis, propose the operating system core concept . In short, I hope the reader can read the content of the operating system in my mind, and analyze the core, develop the core creation based on the future. The best way to learn is to practice. Our magazine will be based on practice, theory is supplemented. The experiments run through the study and analyze it. In this issue, in order to make the reader to comprehensively understand the operating system, and strengthen the sensibility of the operating system, we divide this period into two parts: the first part is theoretically introduced the concept of the operating system, revealing the operating system Special status in the software system, then discuss the architecture and evolution process of the operating system. The second focus analysis Linux operating system, introduces the origin, characteristics, and kernel structure of the Linux operating system. Finally, the reader has built an experimental operating system with the reader - a small Linux with basic functions, allowing readers to experience the architecture of the operating system from practice and the role of the computer system.

What is the concept of operating system operating system Although the definition is always hard, boring, it is aware, but it is the strongest in general, and it is best to give the operating system definition at the beginning: operating system It is the operating environment of the application. Enough! It is possible to run the environment. This term is like a cloud, it is too broad, too abstract. What is you must ask the running environment? Simply put, the operating environment is a service and controlled container. If you don't understand the concept of the environment, I can give a social example. In the development zone, many enterprise incubation or industrial parks can be seen in which a variety of enterprises, incubators or industrial park management agencies will be unified for companies to handle various industrial and commercial, insurance, health care, and health care. Provide basic services such as logistics, public security, and enterprises need certain government services, they can contact the government through the management agency, dealing with relevant matters, without having to personally deal with these and corporate business, so you can pick it up. Concentrates energy. The hatching pool and industrial park provide companies with unity, universal service and management, is an external environment for business operations. The operating system is similar to the management structure of the industrial park, providing basic services and management for the management structure of the industrial park. Of course, we don't expect you to immediately realize the profound connotation of the operating system, and the understanding of it needs to be digested and accumulated in the continuous use and thinking. In this issue, we will introduce "Operation Environment" from various perspectives. The true meaning of the term, and the field of learning the operating system is launched in the stage and level in the future magazine. I believe that in the near future, you can think of it with us. The operating system generates a background that you want to recognize one person, it is best to know him from a small. The same is true for technical understanding, we must understand its cause and development process, in order to fully understand the problem solved by this technology, and understand it in the development of discipline. The characteristics of various stages of technology development can we recognize the advantages and disadvantages of this technology. Similarly, we want to grasp the characteristics of the operating system, or first put the operating system on the timeline and look at its 来 龙 去! The operating system is not the beginning of the computer, and the initial computer science does not exist this concept, all tasks are running directly above the hardware. At that time, most of the tasks were concentrated in the field of scientific calculations, and the system hardware achieve relatively simple, direct, task requirements for I / O operations, and record the results to the simple equipment such as the tape drive. Most of the old programmers use handmade or punctuators to enter binary data and programs to enter machine memory, and then perform calculations, and finally saved the results on the tape drive. Once an error occurs, the debug light on the machine will be stored in the error code saved in the register, and the programmer will analyze the error. As scientific computing tasks become more complex, computers have gradually applied to other fields other than scientific calculations. Hardware devices are more abundant and complicated before, I / O operations have increased significantly, and the scale is rapidly expanded. The errors that need to be debugged is rising straight lines, direct operating hardware, and become more difficult to make programmers. So the advanced language, compilation system, help programmers simplify development work; the operating system, help programmers manage and operate hardware devices. Programmers can focus on the development needs of the tasks, cumbersome tasks such as task loading, allocation / release memory, memory addressing, device driver, data storage, etc. Hardware-related operations to the operating system management - I can say that A liberation of productivity. The times continued to develop, the coming of multi-tasking age, making system management more emphasizes resource sharing.

The user's direct operating system resources are obviously contrary to the above spirit, so the reasonable allocation and protection of resources provides new challenges and opportunities, which lays an indispensable status of the operating system. Since then, the operating system has become a software system. The most basic, the most important part of it. The operating system's task can be seen from the origin of the operating system, the core task of the operating system is an intermediate layer between the hardware and the application, or an operation platform of the application, separated by its application and system hardware. The application uses the service it provides to complete the hardware related operation. All in all, the operating system is convenient for the application to operate and protects system resources. Specifically, the operating system has brought several benefits to users: Easy Operation: The operating system is an interface between users and computers, which greatly simplifies the complexity of the user's implementation task. As an application's execution environment: It provides the programmer to establish an application to edit the environment, compile the environment, and debugging tools; provide loading services and resource allocation services for the execution of the program; for data access, I / O Access service; provide file operation services for data formats; providing permission control services for programs; providing error reporting services, etc., from this, from this, programmers and users no longer need Caring to develop applications with a daunting computer architecture, you can develop applications wholeheartedly. Validity: From another angle to the operating system, you can think it is a computer resource management system. Due to the different types of resources in the system, the usage is also very different. If these resources are managed directly, such as memory allocation, clock timing, I / O driver, storage maintenance, will require users to have rich hardware and software knowledge, deeply grasp the computer The system structure, otherwise the resource will be difficult to use reasonably, and finally cause system confusion, and even collapse. Moreover, modern multi-user operating systems require system resource sharing, resources must be reasonably assigned to multi-user, multitasking, only adopting a certain scheduling policy and allocation policy, can guarantee resource and effective utilization. Therefore, configuration resources become key to improve performance - as the resource configuration is the key to improving productivity. Security: Security is another important feature of the operating system to provide us, which provides us with a number of security assurance. First, the operating system is used as the intermediate platform of system hardware and user, and the application is prohibited from operating hardware, and the application is prohibited directly from accessing memory, and performs privileges. Most systems run the application to run in user space (low privilege level), and the operating system runs in the kernel space (high privilege level), the application can only be indirect via the operating system only through the system call request operating system. Execute and hardware-related operations or perform privileged instructions. Therefore, it is protected whether the system is corrupted or illegal. Second, multi-task multi-user operating system must guarantee that information between different tasks cannot be leaked, so you need to divide your respective private space and access control. Corresponding authorization and certifications for different users can protect users their lines, they do not violate each other. In short, operating system security involves aspects, and robust operating systems must be able to guarantee task security. Easy to expand: The rapid development of computer technology is increasingly popular, computer hardware equipment continues to introduce new, which requires the service provided by the operating system to videody, so it requires good scalability of the operating system.

Since the operating system has abstracted system resources and services, blocking the underlying detail, unifying the upper interface, adding a device or service into a light and easy thing, it is only necessary to do new in the interface specified by the device or service. Implementation immediately. What is the resources? The resource concept is used in the operating system, and the hardware, memory, disk, files, processors, clocks, etc., can be used in the operating system. The concept of resources is actually very well understood, in general, the resources in the system refers to the special entities that the system is provided to the process, and the process is to obtain these entities by requesting the operating system, and the system allocates these entities, the process needs Hang a wait. An entity that meets the above conditions is a resource. The operation system is the same as any other transaction, the operating system is not a constant. So far, it has experienced more than half a century, has formed a huge family. From a personal computer to the workstation, from a general system to a dedicated system, from embedded to a virtual machine, it is a variety of forms. We are difficult to cover all operating systems, and only hope that the outline is introduced in several systems with representative systems in the process of operating system development, and it is clarified its evolutionary context. Evolution History: The earliest operating system is a simple single-channel batch system. Its function is quite simple and can only serve serialize the pre-organized task group. The earlier system can only run a task at a time. Each task must be loaded first, then wait until the next task can be loaded, and the repeated load is a lot of time. The emergence of a single-way batch system has greatly improved system throughput. Things are not always as smooth as it is. Due to the time -i / O operation time consumed during data storage - compared to data processing time - CPU operation time - the program is running to I / O operation time (often more than 20 times) During the period, the CPU always needs to stop (hang) Waiting for the data transfer to complete, invisiblely wasting a lot of valuable time, and execution of subsequent programs in the task group is also delayed. How to avoid waste of data transmission waiting for? Can you liberate the CPU to implement other tasks during transmission? In order to solve this bottleneck, the single-way batch system has evolved into a multi-way batch system. The so-called multi-channel is actually said that the processor (Of course, now talking about a single processor system) can be interleaved to run multiple programs, and a task hangs, run another program. In this way, the time to wait for the time for data transmission to be wasted, and the system throughput has been improved again. The development of the computer makes the task no longer limited to scientific calculations, more and more applications in daily activities such as office, life. Most execution paths in scientific calculations are fixed, pre-defined, only given input, resulting in procedures during the results without external intervention, unlike many tasks in office, office, life must be The user is constantly interacting, and the task results will change because of the user's choice. The system at this time becomes more disclosed, more common, often allowing multiple users to use simultaneously. Interactive mode and shared mode requires the task response time as fast as possible (more than 20 seconds, people thinking is easy to interrupt or getting very impatient), so that multiple users are satisfied, so the operating system begins with division Time technology, the runtime of the processor is divided into a number of pieces, an equal division, or use the user in the system in accordance with a certain weight. This method of using the processor virtual to multi-user can not only meet the fast response, but also make all users get the description of the computer is completely served.

The mainstream route for operating system development: single-channel batch - multi-channel batch - Time-time system, there are now many distributed operating systems, embedding systems, but overall technical ideas are still out of date Can't make a multi-way, divided into concepts. The evolution of the operating system content operating system makes its function becomes more and more powerful, but the structure is increasingly complex. Under the idea of ​​facilitating users (including developers and end users), the operating system constantly integrates new features, new services. Recalling the DOS system used by everyone only needs a floppy disk, and today's Windows system or Linux system requires several discs. It can be seen from the past sparrow to dinosaur - although they have five internal organs. Although it turns into dinosaur, the structure is still relatively stable and clear. And the idea of ​​software engineering is consistent, the operating system has also taken a layered structure, the higher the upper abstraction, the closer the user; the more the next layer is close to the hardware, the abstraction is relatively close to the hardware. Moreover, high-level software relies on the service provided by the underlying software, plus itself to provide additional services as higher levels. Overall, presenting the form of a gold tower. Below we briefly analyze the architecture of the operating system, then talk about the problems that need to be mainly considered when the operating system design is designed. The operating system consists of a variant operating system that the composition structure is not the same. Because the means of achieving the same purpose can be freely selected, the composition also has a big difference, and we select the most common operating system (UNIX) structure, reveal the general framework of the architecture of the operating system. For specific differences between various operating systems, you can compare the structures described below. (Note that the operating system we mentioned here is macro concept, close to the operating system release, but not only the kernel is included, but also the multi-system software and basic application software.) We use a simple mathematical formula to describe the operating system Composition Elements: Operating System = Kernel System Program System Program = Compilation Environment API AUI Compile Environment = Compile Program Connection Program Loader API = System Call Logu Function (C, C , Java, etc) AUI = Shell System Services routines (such as X servers, etc.) applications (browser, word processing, editor) operating system The bottom-up component is the kernel, and the upper layer has built a lot of system software. The system program includes three parts. These three parts are: compilation environments, application interfaces, and user interfaces. Compilation Environment Contains Compilation, C, Connector, and Loaders, which are responsible for transforming text formats in text format to machine code; application interface (API) contains the system provided by the kernel Call the interface and language library, system calls are to allow applications to use kernel services, and the language library function is to facilitate application development, so prepare some common basic functions for use, such as common to C language. The C library has GUN C, etc .; User Interface (AUI) includes our familiar shell (About Shell should specifically write a tutorial), system service procedures and common applications.

These parts are not all of the operating systems must include, but most of them should be provided, especially core, system calls, shells these basic components, they all belong to the operating system essential components, and other components include need according to the needs The specific system requirements and application environment are determined, you can also return it to the additional section other than the operating system. The figure below describes the full conceptual structure of the operating system.

System Program: The system program is for the application, the application completes the functionality of the terminal user needs, and the system program is to simplify the development of the application, such as the database system provides effective data transmission for the application. Storage service; there is also a programming environment - it is implemented by the C library - a system program, which provides application development, such as I / O operation routines, graphics libraries, etc. . It can be seen that the system program range is widely covered, as long as the sequel service group is not the end user's software, it can be used in the system software. The core concept operating system is the core, and the most basic component is to be the core-core and other system software or application nature of the application in that the kernel runs in high privilege level, and the hardware is directly interactive. Any restriction, the kernel program is also required to be very cautious and must be guaranteed and reliable. Privilege Level: Modern architecture often uses data dedicated to protect operating system (kernel) to be accessed by application, so as not to avoid critical data disclosure or system being destroyed, the system (hardware mechanism) is divided into different privileged levels, and sensitive data is high Privilege-level, and some privileged instructions, other levels of tasks cannot access sensitive data and use these privileged instructions, only the tasks in the privileged level are only available. For example, there are 4 privilege levels (0, 1, 2, 3) Linux operating systems in the OX86 architecture, exist of the core, and other tasks run at level 3. The level 0 is called kernel space, and the 3-stage is called user space. The main task kernel design of the kernel is the core of the operating system, the run level is the highest. Other system programs must use it to use system resources to get system services. So the kernel is used in the most frequently used, and all system behaviors should participate through kernels regardless of the giants. Therefore, the kernel operation efficiency and correctness are important to the overall system of operation and reliability, if the kernel efficiency is slightly declining, then the layer is enlarged in the application. The kernel requires high efficiency, so it must be loaded into memory since the system is running, and it has been residing in memory during the run until the system is turned off. This is another significant difference between the kernel and other applications or system programs. Although memory is no longer a price today, the memory capacity is limited, so the kernel size cannot be too large (the Linux kernel is only a few M or more M, and even cut minus), the kernel should only contain the most basic and The core features, other additional features should try to mention the user space. So in the end, those functions are the most frequent use of operating systems, what is most needed in the kernel? The kernel direct architecture is above the hardware resources, so the first thing to do is the resource management of the hardware. Therefore, the kernel must be responsible for: memory management, process and process scheduling (management of CPU), file system management, I / O processing, etc. Our magazine is based on the interpretation of kernel principles, leading you to learning the development of the kernel level, that is, the core development. This issue only gives you a conceptual description, describing the main tasks that the kernel design needs to be completed, as for the detailed discussion of each part of the specific kernel, will gradually expand in subsequent journals. The kernel requires at least a few modules. Process Management: Process is the execution code in the operating system, which is the dynamic avatar of the task in the system. The kernel must be responsible for the abstraction of the task, and must be executed, can assign a resource for the process, the execution state of the maintenance process, and provide inter-process communication methods.

Furthermore, process management must ensure the reliability of the process, therefore need to provide process synchronization, mutual exclusion, anti-dead lock, etc., and other process schedules are also important tasks in process management. Memory Management: Computer storage components are slow to slow, by small to large cache, memory, and disks. The most important and must be memory, memory management includes memory allocation and release, and access protection, etc. In addition to the use of virtual memory systems, memory management also includes virtual memory management, disk exchange management, memory, etc. File System: Document is the main way for users in most systems, and the file system needs to be responsible for user file access, access rights control, file format conversion, data transmission, and other issues. Equipment Management: In addition to storage devices, there is still a large number of peripherals that require operating system management, such as clocks, network cards, keyboards, disks, etc., and equipment management needs to drive these devices to call services for the upper layer. I / O management: I / O management in the operating system is responsible for processing complex I / O operations, including I / O buffer and disk scheduling. In addition, interrupt management is also the function that the operating system kernel should be implemented. The above is the main problem for operating system kernel design, where various modules are interlaced with each other and utilized. However, the division of these modules is not absolute, and there may be different combinations or more detailed divisions in the actual system, so we don't have to pursue the specific content of the module, and it is necessary to pay attention to those functions that the kernel needs to complete those functions. The kernel module has roughly a level, we can understand the hierarchy: Direct and hardware is the hardware abstraction layer, and the user is closer to the logical abstraction layer. The so-called hardware abstraction layer refers to the module of managing hardware devices, such as storage management, and device management of these modules to abstract hardware features as kernel data structures and interface functions for upper. For example, disk device drivers, you need to abstall the disk device function to open Open, write (write), read (read) and other interface functions; memory management requires memory abstraction as a page, segment and other structures. Then allocate, merge, and release, etc., through operation of these abstract structures, and then refined to the physical entity of these structures to the physical entity of the memory. The main purpose of the so-called logical abstraction layer is to close the user needs, the most important logical abstraction module is the file system, the existence of the file system is completely designed from the user's perspective, as the user can accept information packaging with file form, Therefore, the file system is logical abstraction because there is no entity of the corresponding file in the physical device. For process management, the process execution and scheduling should be dealt with the processor, it should be said to be a hardware abstraction layer, but the process status maintenance, process communication, etc. are more close to the user, so it can be attributed to the logical abstraction layer. In addition I / O management and interrupt management modules, in the kernel belong to the borrowing force of other module services, they are mainly used by the file system or device management module, but in short, it is hardware, so it can also return it to hardware logic. Floor. The link between the main modules of the kernel is shown below.

The Linux operating system is in a wide range of commercial operating systems and free operating systems, which has unique position, which is not only powerful, close to industrial strength, but also structural design is elegant, with good scalability and portability, interface definition specification, basic and UNIX The system is compatible. More important advantage is that the Linux operating system is the most influential open source software. It has unveiled a new era of Kaiyuan movement, which has played a role in the development of free software. Linux openness, that is, it is uncharged, attracts the enthusiasm of countless software enthusiasts to its development, so Linux is one of the fastest growing and wide-wide software software today. It is a project that everyone is most willing to discuss and participated in the community. It is also this kind of open source spirit that makes Linux become the best good niece of operating system enthusiasts. Its contribution to the sense of education is unprecedented. From this section we will enter the Linux world to explore the rigor of operating system software and feel the love of Linux. The origin of Linux operating system was born in 1991, its author is now famous Linus Torvalds, which is said to be a school homework for a job scheduling system. Later, his sudden inspiration began to start The system is transformed into a practical operating system. He has used some ideas and achievements of the most prestigious education operating system MINX at that time, but his ambition is to make this system more practical than Minx, stronger Therefore, he decided to publish his system code to the public, and welcome any supporters to modify and expand the Linux system - this is the rights of the Gun protocol in our current ear, and I have chosen the most in the world. The respected UN IX system interface standard: POSIX.1 comes as its own kernel system call interface, since then Linux has become a new expensive in the UNIX style operating system family, and is a completely disclosed operating system. Linux's vitality comes from its open source ideology, from Linus public Linux code, software engineers and hobbies around the world constantly actively actively revise and strengthen the Linux system today, and have raised their versions from 0.1 to 2.0, 2.2, 2.4 to now 2.6, and Linux is also transplanted from the initial X86 platform to all architecture that PowerPC, SPARC, MIPS, 68K, etc. can be found. More people more excited, worship the new wind of the source, the number of applications appear on the Linux system, which greatly enhances the practical ability of the Linux system. As the laurel in the open source software, Linux is getting more popular, there is no doubt that it is the most popular, the most active Gun project, which has emerged around the spring of Linux's community, which indicates that Linux will be in the field of education. Industrial areas will have an unprecedented success in the political area. The technical characteristics of the Linux operating system linux system absorbed the essence of UNIX operating system - "Simple is beautiful", so it uses a tightening kernel structure, only those necessary functions in the kernel, try to keep the kernel and smaller. As for those rich attach features, all the library functions or other system software or application software that are handed over to the user space. Sometimes everyone will directly systemify the Linux kernel and Linux operation, which is not wrong. And the operating operating system mentioned above is not only the kernel but also the system program on the kernel, but it can be said that it is a generalized operating system concept. I hope everyone will distinguish. In order to benefit from the influence of the UNIX system, Linux uses UNIX system call interface standard Poxis.1, ensuring limited compatibility with UNIX systems, causing a large part of UNIX technicians.

In addition, Linux originated from small gauges, universal computers, is not designed for large and dedicated computer, so structural complexity and normative are compared. There is also the current version of the LINUX operating system is from the server as the starting point. Therefore, network function and system management ability are highlighted, most applications are specially designed for network management services, desktop applications for personal users and embedding applications. Real-time Supporting still is still limited (an important topic of this year Linux development is for desktops and embedding development corresponding kernel versions). The characteristics of the Linux kernel Linux are a very powerful modern operating system. Developing its backbone is a software engineer, so most of the practicality and efficiency is a starting point, many places also considers factors such as industrial norms and compatibility. Therefore, it is a practical and efficient problem that the core of the Linux system is most important than teaching operating system pursuit of theoretical theory. Below we briefly summarize the characteristics of the Linux kernel. First, the Linux kernel is designed to form a single huge core (in turn, the microoconuclear is a core software that is more closely to hardware. It generally includes primary memory management, synchronous primitives, interrupts Communication mechanism, I / O operation, and interrupt management, this is conducive to scalability and portability. However, the microelectronics need to have higher communication between other upper layer modules such as document management, device driver, virtual memory management, process management, etc. Overhead, there is currently more intensive in the field of theoretical teaching, and it is difficult for industrial application efficiency.), So high efficiency, compact compactness. Second, 2.6, the Linux kernel is a single-threaded structure - the so-called thread structure is that only one execution thread (executable program in the kernel) is allowed to run in the kernel, and it will not be interrupted to run other tasks. This kernel is becoming non-seized, and its advantage is that there is no concurrent task in the kernel (in a single processor), so many complex synchronization problems are avoided, but their adverse effect is that the non-seizure characteristics delay the system response speed, new task You must wait for the current task to perform an exit to get the running opportunity. The industrial control sector requires high response speed, so after the 2.6 version, due to the contribution of Robert Love et al., The Linux kernel will introduce the Linux kernel, which makes it become a kernel seizure system, and of course the cost of paying is further complicated by synchronous operations. Third, in order to ensure convenient support for new equipment, new features, the Linux system uses modular mode to device driver or new file system, etc., the user can be dynamically loaded on site, Can be uninstalled dynamically. At the same time, the kernel can also be customized, choose the function that suits you, and the unwanted part eliminates the kernel. Both techniques ensure compactness and scalability of the kernel. Fourth, Linux kernel is purely a passive call service object, the so-called passive is because it is the only way it serves the user service is that the user is invoked to run a function in the kernel space through system call. The kernel itself is a set of functions and data structures, and there is no running kernel process for user service (although Linux does exist a process called kernel threads, it is not used to serve users, just as a system Self-service purpose). Fifth, the use of virtual memory technology in the Linux kernel makes memory space virtual extension to 4GB, where 0-3g belongs to user space, called user segments, 3G-4G belongs to user space, called internal core segments. This allows the user writing program to use a storage space that is much larger than the actual memory. Sixth, the biggest feature of Linux's file system is to implement an abstract file model - VFS (virtual file system), which belongs to UNIX style.

The intrinsic differences of various different file systems are masked using the virtual file system, so that users can access various format file systems using the same manner, which can use VFS without distinguish between different media different format file systems. Unified interface switched data. This abstraction brings unlimited vitality for Linux. Seventh, Linux provides a very effective latency executive mechanism - the second half, soft interrupts, Tasklet, and 2.6 newly introduced work columns, these technologies ensure that the system can easily, finer granular selection execution of the task opportunity. It is guaranteed that the system is running as much as possible (not interrupted). In addition to the features mentioned above, Linux has many other outstanding features, we will introduce in order to introduce in the future. If you have questions about the above features, please don't worry, followed by learning will answer you. The Linux operating system kernel structure Linux kernel although the implementation and UNIX systems have great different, their structures have basically maintained and Unix mini, with the functionality and the operating system kernel requirements mentioned earlier. Please see the figure below. We briefly explain the link between modules. Any program of user space If you need a service provided by the kernel, you must pass system calls, so that most modules in the system call layer and kernel have interfaces, they or to control system service properties (such as Sys_fnctL setting file operation properties; SYS_NICE Settings Process Time Slices), or extracts data from kernel (such as Sys_TIME gets a system timing of time interrupt maintenance), or requests the kernel allocation resource (BRK extension process stack memory). The file system contains VFS and various actual file systems. VFS is an abstract interface for the actual file system, and the actual file system provides its own specific example operation method. In addition, in Linux and UNIX devices are clever belongings for special files, affixed and managed by file systems, so they are consistent with the file system. The file system will submit the operation of the device to the actual device driver. LINUX Device Management is distinguished into block devices - can be random access, such as disk-and character devices - can only access, such as keyboards. The character device structure is simple, the file system can submit the request directly to the character device driver, but for block devices, due to frequent random access needs to repeat disk addressing operations, this will bring a heavy burden on the system load core, so the kernel The request for block devices must be integrated, such as queuing, merging, and then selectively sending to physical devices; additionally reading device, the buffer disk block is required in memory. Therefore, the I / O layer processing must be preached before the request is submitted to the block device, and the block buffer processing must be performed by the I / O layer after the disk block is read. The interrupt management system is responsible for saving a CPU cycle for device services, it compared to polling, and the other clock interrupt is also responsible for updating system time and triggering process scheduling. Memory is one of the core resources in the system. It is a must-have condition for data storage and delivery, so the management system not only needs to be used, but also all modules in the system requires more functions of the memory management system. File system, I / O system is used to buffer data requires allocation of memory, process data storage in process management, and address shooting requires memory, and the growth of stacks also requires dynamic request memory; and there is an effective way in process communication. Implement with shared memory. Process Management In addition to the memory management and process communication, the process management is also important with the file system, because the files in the process resource have no doubt one of the most important parts, so the process management system must interact with the file system. One of these modules is not isolated, but in contact with thousands, for mystery, I hope the reader carefully chews.

The Linux operating system's file constitutes the core of the Linux operating system, is the foundation of other programs to run, but if a practical operating system only has only a kernel, there is no rich, powerful system program and application For users, it is better than building, but also electricity, but there is no elevator, telephone and office equipment, and users are still unable to stay. Therefore, the release of the Linux operating system has a large number of system programs and applications, such as the latest red hat system issued version sentences that require 2-3 light discs, most of which are applications. To learn the Linux kernel, first, you must first use the Linux operating system to understand the entire system file - the so-called, the shaker is cow, and you will see unparallelfes. - From the outside to learn Linux, then from the inside Extracry knocked; from rationality, it will be the most profound understanding of rationality. Many characteristics of the kernel are ultimately reflected in the user app, so familiar to the application will undoubtedly be a great benefit of kernel learning. Moreover, an important purpose of learning the kernel structure is to promote our more effective use of the Linux operating system, whether it is from the perspective of system management or from program development perspectives, master the kernel level system call, resource allocation, interrupt control or process Scheduling and other technologies are extraordinary value, which can help you develop and control your system. In this section, we will briefly introduce the file composition of the Linux system, show everyone the outside of the Linux operating system. After the system is started, it is a series of directories (using LS or DIR), which recognizes these directory is the first step in learning the Linux system. Let's list the main catalogs and briefly describe the respective content. Linux System Root Catalog / Under Contains: bin: This directory stores the most common basic command, such as copy command CP, editing command vi, deleting command RM, etc. Boot: This directory contains the configuration files required for the system, kernel (VMLiuxz), and system mirror (initrd ... .img). DEV: The external device file (FD represents the floppy disk, HD represents hard disk, etc.) in this directory (FD represents hard disk, etc.), using these device files to operate the device in mode of operation files. ETC: This directory contains all system services and system management configuration configuration files; such as system log service configuration file syslog.conf, system user password file passwd, etc. HOME: This directory contains all users except system administrators The home directory, the user main directory is usually named by the user login account. LIB: This directory contains the dynamic connection library (* .so) and kernel modules used by the system (under Modules). Host Found: This directory contains disk scan detected file fragments. If you illegally shut down, the system will perform disk scan when starting, saving damaged debris to this directory. MNT: This directory contains file systems that are dynamically mounted by users. If you want to use a disc, the U disk should generally be installed to a specific location in this directory. Proc: This directory belongs to a virtual directory of memory, which contains many system field data, such as process orders, interrupts, CPU information, etc., which are dynamically generated, not stored in the disk. Root: This directory is the main directory of the system administrator (root user). SBIN: This directory contains system management commands used by the system administrator, such as firewall settings command iptable, system shutdown command HALT, etc. TMP: This directory contains some temporary files.

USR: In this directory, it is generally included in the system published (but there is no clear requirement), which is the most explanation of three subdirectory / usr / src: Linux kernel source code exists. Directory / USR / MAN: Help files in Linux / USR / local: New installation applications are generally default in this directory in VAR: This directory stores continuously expanded information, such as log files. The above is the original composition of the Linux file system, familiar with them is the premise of applying the Linux operating system, I hope that everyone can open each directory to see. Before building a Linux test system instance, we will take a test operating system with the reader with the reader. This will help you familiarize yourself with the constituent structure of the Linux operating system, and learn some Linux commands and use skills during the construction process, deepen the way to understand the LINUX operating system. The experimental system will be as small as possible on the basis of ensuring practical value. I hope that through the process of building a system, it can eliminate the fear of Linux, and readers hope that readers can use the system of cut, bring their sense of accomplishment and learning. The necessary basic knowledge is for the first time to contact Linux friends, only see the following content clearly can't expect the Learn's operational methods and system behavior. I suggest you to find a LINUX system tutorial for this system. Chew. For this big cow like the system administrator, skip the following content, then go to see what Sina Sports News is, don't turn it on this :). In the process of building a system, you will not be inseparable from a variety of commands, and you cannot deliver a big size shell script. It is important to understand the system's operational ideas, and all the guiding ideas of all activities must focus on the steps of operation, and to "obey" system running their own and system running services. So the basic knowledge is also expanded from these perspectives. However, we will do it and don't do it. Basic commands We first introduce a set of basic commands that need to be used by Linux systems. When logging in to the Linux system, the appearance is a shell? Prompt (# or $, etc.), which tells us that the system is already ready to accept commands, you can use the keyboard to enter the command line to operate the system. The command you entered will be displayed on the screen, and it is discussed back to the end of the back, and send the command to the system's flag shell and shell programming shell? After you log in to the system, the system is first running a special application, which shows a prompt symbol indicating that the system is ready to start accepting your command, when you type you want to execute, the application will command Submit to the Linux system to process, then wait for the results to return to you, then she will return to the prompt, go waiting for you to enter the command next time. This special "reception" program is called the shell, which is equivalent to an interface with the user exchange, and she interprets the user command to the kernel, so shell is called a command interpreter. Shell is not only the only one. The current popular shell has Sh / Bash / KSH / TCSH / CSH, etc., they actually start an application, you can use the command whereis ksh / sh / bash View it exists in the specific location of the system.

Interested, you can observe the default shell belonging to the system by command Echo $ shell. You can also use Chsh after logging in (using Ctrl D to re-login) to change the choice of useless shell programs, or simply execute new shell programs directly on the default shell - just type new shell name and carriage return, If you want to launch a new shell, then execute the exit program. Various shell programs have their own characteristics, and the functions are strong and weak, but they need to be able to execute programs or commands in the same point; can handle input and output of programs or commands; be able to execute shell scripts. (Shell can perform three different concepts: 1 Command refers to the SHELL program own basic command - such as CD command, pipeline | command> redirect command - and system commands in binary form - such as LS CP Wait .2 procedures refer to user installation and compiling the binary files; 3 Script Refers to the program and command sequence containing logical relationships and command sequences) Shell executes the necessary environments, these environments include file search path, current directory, user home directory, default Editor, etc. (you can get this information from the Man shell). These information belong to the environment variable, which can observe the default environment variables of the current system via ENV, changing these variables can pass: variable = settings (such as path = / opt) command mode and modify the relevant profile existing in the user directory (such as Bash For configuration files, you love you to ~ / .bashrc, ~ / .bash_profile) shell programming shell programming simply manages the command serialization, without compiling into binary executables. This is similar to the DOS underground BAT batch file. The meaning of using the shell program is that some tasks cannot be completed through the existing commands, and a set of command collaboration must be used to complete, and the various commands are not simple columns but are organically combined in accordance with the set logic relationships. This shows that the shell program needs to be able to control the execution stream of various commands, and can read and write temporary data, so the shell program has its own control statements and variables, and it is also used by the relevant syntax. The shell program can also be a shell script that exists in a normal Linux text file. It can be generated with a text editor such as VI, and then change its attribute to executable to run. For example, Touch Test Generate File Test Chmod U X Test Modify Properties ./test Insurance can first use the #! Symbol, you can force the current shell to run the shell file to perform the script. Of course, shell programming is not as simple as above, and wants to really learn shell programming and use it. It is not so easy. Interested friends can refer to the relevant information to learn about Shell programming. System Services Installed Linux Friends must be familiar with the installation process The system will prompt you to choose what service, or if you have installed the SETUP command, you can also see a configuration interface containing the system service configuration. The system service contains a series of shape-colored services, and many service options we have never heard, or just have heard it. It is normal, because the service is too much too much, very few people can figure out what these services do. We don't pursue the detailed role of all services, just introduce these services from the system running perspective. (I want to know if the system has those services, try the setup command.) The system service program and normal application or system command essence is the same, all of which are some binaries. But its operational mode has some own characteristics.

In most cases, in the case of system services, it is running in the background, so the result is generally no longer screen display (often re-directionged to / dev / null), but for security purposes or analytical purposes, most records are required to be saved to related logs; System Server runs more configurable, such as the FTP server has user access, work directory configuration, so you need to get data initialization service from the configuration file. Finally, when the service program is running with the system, it will start running without the user's own startup. Since these feature system service programs are typically present, there are corresponding shell script file management, using these scripts to control the configuration, start, logging, and shutdown service and clean up temporary file operations. This is much more safe and secure than the user manual operation. Services in the Linux system are running scripts (boot or shutdown), all in the directory /etc/rc.d/init.d - LINUX system file organization hierarchical follows FHS specification, including script locations - such as we start / stop Networks and other scripts used in the network. These scripts have the same way of use: Service script {Start | Stop | Restart | Reload | status}. If you need to manually start or stop a service, type the /etc/rc.d/init.d/ service feet Name Start | START | START | STOP, you can use the command service service feet The same effect. In most cases, in most cases, the system starts running, the system is closed, which is why you can see a series of service on the screen when you boot or shut down [OK] or service stop [stop]. So how do you start and close these services? It is necessary to talk about this problem with the Linux system run here. The so-called running level is more popular is to specify the behavior of the system, each of which corresponds to a set of applications. We can use the command init (later explanation it) level to switch the system's run level. General Server System Using Level 3, if you need to use 5, you can use the run level 1 for single users or embedded systems. Among them, 0 and 6 can be used safely to stop the system, which will uninstall file system other than rooted directory, and reinstall the root file system in a read-only mode, which prevents the failure file system. Returning is correct, returning to the system service program. We should guess that different run levels also correspond to different system services collection. For example, the run level 5 at least needs to be more than 3 to start the X server and XFS (font servers), etc. You can use the command chkconfig -list to observe whether the various system services under each run level are allowed. Obviously the level 5 is open, the level is level 3. In short, the stronger the function requires more services. The following startup section tells you that after the system root file is installed, first look for the init program and run it. The task of the program is to determine the system's running level from the configuration file and start the corresponding service program based on the level. The specific process is as follows the initTab to get the system run level x, and then run /tc/rc.d/rcx.d/ in turn to start the corresponding service with the shell script starts with uppercase S. The standard process of the Linux system starts for the system loading process. We have not introduced the system loading process. We assume that the kernel has been loaded into memory and has completed an exception table, interrupt table, scheduler, clock, console, memory, etc. Initialization, and finally perform process management. Initialization of the device, from this kernel, you can start using a real process.

After the initialization is completed, the kernel creates the first process (initial process), which is the system's No. 0 process, which is represented by Task [0] or init_task in the process descriptor table. This process then creates a process to perform the initialization operation of the init () function for the second phase, and the initial process (init_task) will execute the IDLE loop, and the only role in the initial process is the only role after the initialization is to use free. CPU time. The initialization of the second phase is relaxed than the previous stage, because it is now done by a real process, and the previous stage is made manually by the "hardware process". This phase, this new process created by INI_TASK needs to initialize the bus, network and launch various system kernel background threads in the system, then initialize the outer, set file format, after this, it will be the final preparation for entering the system - Initialize file system, install root file, open / dev / console device, redirect Stdin, Stdout, and Stderr to the console, then search the init program in the file system, and use the Execve () system call to load the executing init program. The system has entered the user state here. The init program is submitted in accordance with the options in the initab configuration file: 1 Determine the Run Level (1-6) 2 Run the system service in the rc.system script, such as activating the exchange partition, check the disk, loading hardware module, etc. 3 operation regulations The service under the level: /etc/rc.d/rc*.d/ The head of the head under, such as the network service S * NetWork. 4 Run the getty program on the specified serial port, getty open the terminal, and set the mode, and then run the Login program. If the user account and password are correct (need to pass / etc / passwd verification), enter the user's working directory and perform the corresponding shell according to the settings in its working directory. You can really use the operating system here. The IDLE process is a strange process, which uses the CPU when there is no other task to use the CPU, and its existence value is said to extend the life of the CPU. The kernel background thread is a process of executing the internal nuclear state, and they are scheduled as scheduled programs as the user process, and the system uses their periodic (not necessarily fixed cycle) to perform some "housework" in their own management. The major several kernel threads are: BDFLUSH - Cleanled memory buffers; kupdate - updated information in the memory buffer to disk on time; KSWAPD - switched memory page to disk; keventd-- relationship System event; ksoftirq - execute software interrupt. Constructing an experimental system Sorry to build a Linux operating system, there is no very standard process or specification so far, but the general process is very different. It is nothing more than first compile the kernel - compile the kernel source code into an executable mirror file. Of course, it may also be compiled and installed in the same period when compiling kernels (whether there is a module depends on your specific selection). With the compiled kernel, then you need to create a root file system, which needs to create the necessary directories. As for the software and library functions used therein, you can choose to download the source code package, then cross-compile, and then install. Or we steal a lazy, copy the required software and library from a published full system, and copy the necessary equipment files, configuration files, and service scripts. You have to do it just to modify some related The profile can have a file system.

The kernel and file system can say that everything has only owed Dongfeng, you need to do only to bind the kernel and file system together, so that the system is booted into the kernel, and the root can be found after the kernel is loaded. File system and execute the initializer. Don't think that this ending movement can be easily set, and the beginners are often planted here. How can I build a system in the minimum price? Think about it is not every netizen to find an empty hard disk or disk (see your machine, maybe even the soft drive) to do new system, in order to protect the original system, even if you open a new partition, you can't encourage. So the best way is to use memory to simulate a disk, put the root file system created, after the system is boot, run on the disk to the memory simulation. At this time, you completely jumped out your physical hard drive. This method is sometimes used in the embedded system, or it is desirable to use the data wired after power-off data. Below we are doing such a test system, the only price you pay is to consume some time and countless times. The first step to compile the kernel is to select a suitable version of the kernel source code package and compile it. Don't think that compile the kernel is very mysterious. In fact, it is similar to the normal procedure, the kernel source code is actually a "a big" program, compiling it is equal to compiling one program, then link them into a single executable mirror file. This image is the VMLinuz - * (if you are careful, if you are careful, there must be a file called VMLinux in this directory. In fact, the two files are one thing, but the front is After compressed) as the first part said, the Linux kernel has strong scalability, and many functions in the kernel are optional. If necessary, it can be compiled into the kernel, but the kernel will become obese. An alternative way is to compile certain functions into a module in a file system, waiting for you to really need it, then it is loaded into the kernel, so that the kernel can be lightly installed, and there is a lot of fast start. Although it is a test system, it is still trying to make it function. So before compiling, in addition to supporting the most basic EXT2 file system, PCI interface, automatic installation of modules, etc., more common use of EXT3, JFS, plug, network, SCSI, USB, etc. Function is added. Otherwise, in order to achieve the establishment of root file system in our virtual memory, the kernel needs to support ramdisk and initrd. The kernel network device option contains a large number of NIC drivers. You must know that your own NIC can choose correctly. Generally, both network card driver compiles unmoduled, which is loaded after the system is started. Our test system runs under VMware, and the VMware virtual network card is driven to PCNET32, so this module is included. Compilation steps to download a kernel source, buy it, don't use it. If you are really a guy who reached out, let's tell you, go to the www.kernel.org website to overwhelmed the illegal source code. If it is the compressed source file ending at GZ, use tar xvzf linux-2.4.18.tar.gz, if it is the end of GZ2, use TAR XVJF Linux-2.4.18.tar.bz2 until it is unpredictable. The kernel version number is a bit more particular, simple, even as a stable version, odd number is the development version, so we use version 2.4.18, because it is a stable version, one will make my machine to download it before, I don't want to change again :).

Then enter the directory of the deposited kernel original code (the standard system is stored by default, the kernel source code of the system is stored under directory / usr / src / linux), execute the Make MenuConfig for kernel function configuration, select the required function The module is compiled or compiled directly into the kernel. Configuration information is recorded by default in the hidden file .config, you can also choose to record it into a custom file, such as recording the information in MiniSys.config. The specified profile can be easily imported when configuring the kernel later. make menucofig provides you with a text graphical interface configuration menu, which lists all the features that the kernel can provide, if you select the * number before the option, then this option is compiled into the kernel In that, if you are selected as a module, you can use it for your unclear options? View them explain. In addition to using Make Meunconfig, you can try using make config, it completes the same function, but you have enough to endure the conflict of the command line to select . If you can use the make Xconfig configuration if you can use the make Xconfig configuration, it is easier to see, it is easy to see, it is recommended to use it for your eyes. After saving the kernel configuration, make Make DEP / * to ensure that all dependence, such as include files. Unless your computer is really slow, otherwise it doesn't spend too long time * / make clean? / * Clear all the destinations and other things. Don't forget this step * / make bzimage or zimage / marker-BZ and Z format kernel is limit for the size of the kernel size. The Zimage kernel needs to be placed within 1MB of real mode, and its volume is limited. BZIMAGE kernel does not have 1MB memory restrictions * / Remember the kernel compilation, you must also compile the module, even if you do not use any modules when you configure the core, do not skip this step, compile and install the module immediately after compiling BZImage. It is a good habit. Moreover, if you really don't have a module to be compiled, this step is very fast. Make modules; / * Compile the kernel module, and if you configure the kernel to mark the M function, you will be compiled without module * / make modules_install. / * This will cause the module to be compiled and installed into the / usr / lib / directory. However, if you want to change the directory of the kernel mirror or module, you can reach the Makefile file in the kernel source code, such as modifying install_mod_path to change the module installation directory * / Waze the bucks, you stop, you now It has a new kernel. It is hidden in the internal nuclear source code directory. Arch / i386 / boot is called BZImage or Zimage. The new kernels are installed in the modules directory under lib. The establishment of the file system is built, it is simpler, and the host device of the file system is formatted. The second is the copy required. Simple and clear! Let's first copy the document, wait until you have finished talking about the problem of host equipment, don't forget that we are all over the gloves! (In addition to copying documents, a more standard method is to plant a variety of toolkits, cross-compiling locally, installation, but in order to save things, we use copy standard system files to construct file systems, not only convenient and different.

But the premise is the new system architecture - processor - consistent with our raw material system, if you want to compile the file system running on the ARM on the 0x86 system, then it is best to download the source code package to change the cross-compilation) The system basically requires the structure of the Linux file system. We have set up a streamlined file system here. It contains the most basic directory and files, and the configuration file is also as simple as possible. The contents of the file system must be included below. The file system minimal needs to include / dev, / proc, / bin, / sbin, etc, / lib, / usr, / tmp require a set of basic commands to support the runtime function of the above command, which also includes compiled kernel production. Module must have some necessary profiles. We must do the same place to generate and copy content according to the unit. The only thing is that you have to be fine enough. Create a root file system content Let's first create a new directory "rootfs" that will contain the root file system content, and then start all directories and files in which the root file system needs to be generated. The first step is of course necessary to establish the root directory in the rootfs directory, with a line of commands to complete MKDir dev, proc, bin, etc, lib, usr, tmp, and sbin. The second step is copied to the command you need. For example, if you need a ls command, you first determine where it is where the location where The LS (discovers in / bin / ls directory), then copy the command to your working directory CP / BIN / LS / WORKDIR / bin / ls, but only copying the command file is not enough, but also must be used to use the dynamic shared library file used by this command. How to find the command to use the dynamic shared library? Very simple, using the LDD / BIN / LS to see the shared library used by the command, displaying the shared library file used in the output right column (SO in the name). For example, in my system, the operation output is: libtermcap.so.2 => /lib/libtermcap.SO.2 (0x4001f000) libacl.so.1 => /lib/libacl.so.1 (0x40023000) libc. SO.6 => /Lib/libc.so.6 (0x40029000) libattr.so.1 => /Lib/Libattr.so.1 (0x40149000) /LIB/ld-linux.so. 2 => / lib / ld -linux.so.2 (0x40000000) We have to do the library files you want to use according to its library file to copy / lib or / lib / i386 in our working directory. (The command used by the user is in / bin and / sbin, and some scripts use some files that appear under / usr / bin and / usr / sbin, if you want to use these scripts, don't say these commands and The libraries they have to use cannot be less). But these files are not what we actually want. It is just a symbolic link for the actual library file. The system only uses a symbolic link, which does not affect the use of its application when the library file is upgraded. So we have no significant copy of the symbolic link, but also copy the actual library file points to the symbol link to Workdir / LIB. There is an important directory in the / lib directory is the modules directory, which contains the kernel compilation module, stored in the files named in the version number for different versions of the module. Don't forget to copy this directory into our new system.

These libraries under the original period / lib are sufficient, but the current Linux system has many requirements for security, especially the system from security, there is a number of verification methods, so you often have to be related to safety verification. Library. These libraries will not be used directly in commands, but indirectly want to be used by the system's security framework, most of them explain how to associate in the configuration file, the security framework is selected by viewing the configuration file (these configurations) Please refer to the file after the file). Safety framework topics, we don't say much, interested, can check the usage of PAM and NSS. Here we don't care about it in / lib / security / lower and PAM related gloices and / libs NSS all Libnss * libraries under our land / lib under / liburity under / lib under / lib . Although it is very stupid, it is universal. The Linux system will use the library function that will be frequently used by most applications, and most of them are compiled in a static manner, but to take a dynamic library, centrally store management. This way if you use a shared library, then the library file is only transferred once, residing in memory, so it is greatly saved by the shared library, and the execution file is reduced. Of course, there is no free lunch in the world, although the shared library is more like a static library, but the path search outside, and the transfer time is more time-consuming link file is one of the Unix style operating systems, which is specific. It can be divided into soft links and hard links. Soft link is also called a symbolic link, in fact, the only content of the file is the path to the actual additional file system. The hard link is and shared the index node with the linked file (index node concept is not clear, then you can find it). Therefore, the symbolic link is afraid to be actual files being deleted and transfer, then the symbolic link still exists but no longer valid; the opposite hard chain delete source file will reduce the index node count, and do not destroy the hard link file. The third step is established, which is important but not affairs. Since Linux inherits UNIX to use and manage the device as special files, you must use the system's peripherals, such as a soft hard disk, clock, system terminal, or even memory, can also be used to make the corresponding file to access. So we have to establish a device file corresponding to all devices that can be used. As for what device files you need, you can't generalize, you can open the / dev / directory to see if the files are more dazzling. However, it is not too much that most of them are used, and the equipment files we have to build will refer to the number of devices: console console equipment, TTY * is the virtual management by console (we use Ctrl- [1 -7] Switching is this device), the SDA1 SCSI interface device (because my Linux is running on the Vware virtual machine, while the storage device used by the VMware virtual machine is a virtual SCSI hard drive, so it requires this file. Its usage and Nothing to use standard IDE hard drives), RAM memory virtual disk devices (after our system run in the memory virtual disk), NULL empty devices (is a very useful character device file, all things sent to this device are ignored .

If any program's output result is redirected to / dev / null, you will not see any output information), ZERO zero device (read this device, only empty content, so sometimes to achieve high compression ratio, need to be A space will often use it to use it.) Initrd This is a special character device that is used to send switching operation level information from the user space to the system kernel, belonging to a virtual character device (such as changing Run the level of init 1-6 commands, all through this device to the kernel), and the virtual character device as a user's tool to the kernel command, you can take a look at this article. Clear that you need those device files, you can use the mknod command to build the required device files. Establish parameters required during the process. You can view the following equipment through the LS - LA / DEV / device name command, which is a block device or a sub-symbol device, and the master is obtained from the device number. If you feel annoying, use the copy command to copy these files directly from the standard system / dev / directory, but to match the parameters -R Otherwise, you can make the entire content of the file, not just the device file. If you can put yourself to your own clothes pocket, you can't go in. The Linux system divides the device into block devices and character devices, block devices can be randomly access (b), and the character device can only access C in order. Another device controller can control multiple devices, so there is a master number and from the device number. The main device number corresponds to the drive, from the device number to distinguish between specific devices. The fourth step is to establish a configuration file or script that the system runs needs. We are still useful files from simplified, copy standard systems, and then modify the modification. Our test system will be used in multi-task multi-user environments, so you need to log in to passwords, there is also a packet capability, so you need passwd and group files. If the system uses Shadow function to hide the password, then the file shadow is required. Log in to first execute the init file, it requires a lot of configuration files. The first brunt is the inittab file, which specifies the basic functions of many system operations (see details). The next step initially executes the rc.sysinit script to initialize the system, where the FSTAB configuration file is used, which contains the file system and directory mounted after the system startup, and only two of our test systems are / dev / The RAM is installed as the root file system and the other is to install the PROC file system into the / proc directory. INIT performs RC.Sysinit After entering the corresponding /etc/rc.d/ of the running level defined in inittab, execute the service run script. It's no longer to ask me, don't ask me, go to MAN IIIT. What you have to do is copy all things in / etc / underinitab, rc.system, and rc.d to your corresponding system. Our experimental system runs level 3, only starting the network service service, so you can delete the S scripting except S * Network. (Of course, you can also change the system's default startup process, let it perform your own initialization script, this only needs to modify the script name in "Sysinit: XXX" in the inittab). After performing the above initialization and service, the system finally runs the r.local file. Here you can put some commands you want to execute, we put a "ok you are well" !!! "for you to enter the system. Also know that the login is login to use the PAM to authenticate the module authentication user, so the PAM's configuration file is also best copied to the new system. Many systems are also available to NSS (Name Service Switch, this service to help client machines or applications get network information, can be obtained from DNS or NIS from locally or from the network.

For functions such as getXBYY () often use this service, login is likely to use when logging in, depending on your libc version), so /etc/nsswitch.conf needs to copy, as for how to use Man NSSwitch.conf. There is also a relying on the Terminfo / Termcap file, they are useful for setting the TERM terminal environment variable. Copy Modules.conf, which contains the module information, and the Modules.conf in our experimental system has planted a separate name. I said, I wi, I don't say any questions, I will find information. Almost finished, don't forget those below the / root / directory. The beginning of the hidden file used for Bash configuration is also taken to the new system, which is the environment parameters of Bash. End the action. LDConfig -r WorkDir / rootfs (Test File System Directory) Create a library file path cache, from this command to use a dynamic connection library without having to specify a directory because their paths are cached. (LDConfig wants to use dynamic library profile ld.so.conf, test system in the test system) Installing the root file system - the kernel and root file system bindings are not confused, just we do is the files that the file system should contain . The specific file system has only started. The above mentioned that the file system needs to be made on the future hostboard - formatted. If you don't have actual devices in your hand, Linux provides you with two ways: RamDisk and Loop devices (loopback equipment). Using the Loop device can install the file virtual into a file system, and RAMDisk is to store the memory to a block device to store data. Direct use of physical disk operations with RamDisk or Loop devices is relatively safe, and do not damage physical devices. Therefore, in the case where you need to create a file system, you will use the above two virtual techniques to create a file system, and then transfer the file system to the physical device. We take Ramdisk as a host of the file system, and make a file system above, then copy the file system content you created earlier to it. Then observe the size of the RAMDisk (not the size of the file content, because there is also some information on the file system itself), transfer the entire file system to a file (using the DD command, due to the DD command allows binary Way read and write, so it is especially suitable for input / output on the original physical device, making the mirroring of the entire file system), which is called a file system image. Although Linux has no requirements for file suffixes, we are here habits to name IMG.

This is the case: DD if = / dev / zero of = / dev / ram bs = 1k count = 20000 mke2fs -m0 / dev / ram 20000 mount / dev / ram / mnt / cp -av / rootfs / * / mNT / RAM runs DF, pay attention to the value of / dev / ram in the 1k-blocks column, assumes ramsize umount / dev / ram dd if = / dev / ram of = ramlinux.Img BS = 1K count = ramsize gzip -9v Ramlinux. The first step is to give the / dev / RAM device for 20M full space, and then format the / dev / ram device. The page is to write the format confidence in / dev / ram. Next, install the / dev / ram device to / mnt directory, then all the contents of the file system you created in. After completing this step, you can say that it is truly a file system (file system format information file system content) and then disguised device content (including file system format and content) to named Ramlinux.Img In the mirror file, the last compression mirror file (after compressed name is ramlinux.img.gz), starting using / dev / zero Clean / RAM device to increase the compression ratio, because the compression algorithm utilizes the statistics rules replace the character, so Unified to zero will greatly increase the compression ratio of Gzip. The RamDisk default size in the general standard system is 4098 bytes, and you cannot build a RAM disk that exceeds the size. But our system size exceeds 4096 bytes, so you must expand the size of RAMDISK. The easiest way is to specify the size when LILO is started, and the system is only used to use 20M large space in the system, so it should be added in lilo.conf "Append =" RAMDIZE = 20000 ", and the system will automatically change when the system starts. Ramdisk defaults. After the system boot boot process briefly describes the PC to perform the code in the BIOS in the ROM, the program is responsible for starting the first sector of the startup device (floppy disk, hard disk, disc) (0 sector) A magnetic data loaded into memory. Then the BIOS executes the code in the sector (introduces the kernel into memory from the startup device). So, in the sector, the operating system kernel is stored directly, or store the launch loader, For example, LILO, etc., the start-up loader is responsible for finding the kernel, logging within the system, then executing the kernel. The kernel is loaded into the memory. The above has been initially introduced. We have to emphasize it is that the kernel is beginning to install root. File system, how is the location of the root file system determined? (RAMDISK SIZE?) We must specify the drive device during the creation process, use the command RDEV FileName DeviceName setting or modify the relevant parameters in the Makefile under the core code directory, then compile, Because this information is in the kernel. In addition to following the file device, it needs to indicate the location of the root file system on the host device, which also needs to be implemented using RDEV. This information is also recorded in the kernel.

(RDEV command is very rich, recalling that the task of changing the RAM disk size can be modified by RDEV) Many friends have never used this order at all, so many years, there is no sample, no samples, countless times. I don't use this command because we have more cool tools (of course, GRUB seems to be more popular), in lilo.conf configuration, such as root = * These options are actually telling LILO to write the above information . Determine the root file system location, install it into the root directory, then locate the init program, start executing the system initialization. Install the launch image everyone should be = initrd.img. * INTRD = initrd.img. * I'm impressive. Do you know that initrd.img is used? This file is actually a file system image. If you are interested, you can log in / mnt, go see it, it is undoubtedly a minianted file system (this file is compressed by Gzip, so we must decompress first. It. (Mv init.img init.img.gz; gunzip init.img.gz; mount -o loop init.img / mnt). The directories in this file are exactly the same as our file system, but due to Initrd. IMG is running after the system starts in the RAM plate, so it only contains the minimum command and library required for the system startup. The purpose of using this shrinking file system is usually used to start the root file system before the system is not installed. Run the system to load the module required to install the root file system with the inSmod command - such as ext3.o, buslogic.o, etc. (if the root device is the SCSI or root file system is EXT3, the kernel is compiled into in, Can only be loaded in module), so the module that needs to be reinable under libs in libs. The system starts running the LinuxRC script in INTRD.IMG to execute the module to switch the root file system to the actual In the file system (using the pivot_root command). For our experimental system, because the SCSI and EXT3 modules have been directly compiled into the kernel, there is no need to carry out the prime module to be loaded with the itrd.img path. So normal in itrd .img is not required. But to know that the root file system mirroring is placed under the source standard system root file system. So make the system to take the actual physical device, enter the RAM disk work, you need to use INTRD. The IMG mirror file system loads the physical disk on the RAM disk during startup, and then enters the execution. This work we use the LinuxRC script to implement, specifically, the Mount source root file system, the test file system is mirroring unzipped Transfer to / dev / ram, then Umount source root file system. From this system entering our experimental file system start running. Initrd.img is also a file system image, its production method and production root file system Datong small. Copy Require files, in editing scripts, then make file system mirroring. The detailed process is no longer rosso. Don't worry, there is a key step that is to modify Lilo .conf to configure the launch option for the experimental system. Boot = Experiment system kernel Label = Ramlinux Initrd = Just made initrd mirror root = / dev / ram append = "ramdisk_size = 20000 "Finally, LILO -R / ROOTFS is executed. OK! See attachments for kernel guides. Downloading the construction script and the experimental system system although the system technology is simple, the process is very cumbersome, it is not good to lose three, the wrong is.

In order to save everyone's physical strength, we have written several small scripts help build systems. Using these scripts, you can easily establish an experimental system. Our production scripts can be divided into several parts: mkrootfs.sh--? Collect all the materials required to make root file systems to the specified directory. Mkinitrdfs.sh - Collect all the materials required to make the initrd mirror to the specified directory. Setup.sh - Making root file system mirroring and initrd mirroring, rewrite the LILO configuration file to add the RAMLINUX boot option. There is also myBoot, Myetc, and Myroot directories along with the script. Boot contains a compiled kernel (note the kernel is related to the system hardware, my machine is the three processor, if your system is different from me, then you still compile the test system core! But you can use We provide the kernel profile minsys.config to select the kernel function, compile completing the kernel to MYBOOT, or modify the mkimage.sh script, modify the lilo.conf section in the last place, will "boot = XXX in ××× "Use your own core instead of the kernel), module and kernel profile minisys.config. The ETC contains, have modified configuration files and service scripts for use in the test system. Boot is the configuration file of two bats - all scripts and the necessary profile packages for work.tar.gz. In addition, we will also put on the ROOTFS.TAR.GZ and ROOTFS.TAR.GZ) and root file system mirroring RAMLINUX.IMG.GZ on the above method for download, and the content of initrd (initrdfs.tar.gz) ) And mirror (initrd.img.gz) on the Internet. If you want to add or delete some of the files in the file system, you should expand ROOFS.TAR.GZ, then modify it in rootfs, do not modify the file system mirror file (IMG file) after the loop method is installed, because we used to use The zero device fills the file system, so if some content is added or deleted, some of the data inside may be destroyed, the system is reflected to you may have a class of inexplicable errors like "bus error". If you solve rootfs.tar.gz and initrdfs.tar.gz and initrdfs.tar.gz as required, then execute setup.sh, which can generate the corresponding image file Ramlinux.img.gz and init.img.gz, and will add good in LILO The options corresponding to the test system. STEP BY STEP - Enjoy your operating system, select Ramlinux from the boot menu to start running! Wait, want to enter the administrator password? Yes, we are cut from the original system, so the password will naturally be inherited. (If you use the system I do, then the username is naturally root, password threeyear) I saw it, the operating system created in hand has come to you, is there a sense of accomplishment? Enjoy your masterpiece! Attachment - The Standard Process System of the LaNUX system starts refers to the entire process of powering from a computer to a display user login prompt. We will discuss the entire process and some of the related contents here. The process can mainly be divided into two phases: load the kernel and prepare the operating environment, we discussed separately. The discussion of this section is only based on the I386 hardware architecture, but most of the content is common.

Fig Friends, please don't worry, we will discuss it in the next period. This stage is the main battlefield of Boot Loader. It must load the additional data information required for the executable kernel image and kernel to load the memory from the storage medium, which is not a simple job, because in addition to being loaded from the hard disk, it may also need to boot server from the network. Load on the external medium. Various file system types have also brought huge challenges to load. Boot Loader may also need to change the Run Right level of the CPU, and then allow the kernel to enter run. In addition, Boot Loader has to complete some other features, such as obtaining system information from the BIOS, or extracting information from the command line parameters at startup. Some Boot Loader also plays the role of the boot selection tool to make it easy for users to choose different operating systems. Boot Loader's responsibilities: Judging what to load, this can require users to choose to load kernels and related data that it may need to use, such as initrd or other parameters to prepare the kernel, for example, let CPU enter privilege Make the kernel to run Boot Loader History: Early Linux only supports floppy boot sectors and two boot loaders. Shielace is inherited from Minix, and Boot Loader related to the file system. It only supports the MiniX file system. At that time, Linux only used the Minix file system, so there was no problem in doing this. However, the MiniX file system exists unable to save creation, modify, and access time information; file name length is limited to 14 bytes. With the development of Linux, these defects with traditional UNIX file systems are more difficult to endure, it is not suitable for the main file system as Linux. In order to support the implementation of other file systems, Linux introduces VFS (virtual file system). This initiative will soon cause enthusiastic responses, and a large number of new file systems have appeared. One of the MINIX file systems, extended file system XIAFS (naming according to its author) Break through the length limit of the file name of the MiniX file system, raising this length to all 30 characters. At that time, the competition between the file system was intensive, it is difficult to see who will win, even if it is unclear, there will be no final "winner". Although it is very uncertain, it is clear: no matter which file system will be favored, but in addition to minix as a root file system, no one can start from the hard disk, because ShoeLace only supports the MiniX file system. LILO came out. Since supporting multiple file systems (the mainstream file system supported by the kernel has already had Minix, extended file system EXT, XIAFS. There are people who transplant BSD FFS, I can't see when I can't see it.) Is too difficult to implement and maintain. Boot Loader should not be a stumbling block for people to test new file systems, so LILO has adopted designs with document systems. This design has undergone time to test the time, proven to be very successful.

Even today, Lilo can still start from the hard disk of the most file system supported by the kernel. However, since EXT2 has never been able to evolve for such a long time, it has become the fact that the Boot Loader related to the file system is gradually popular. Although EXT2 has been able to meet the daily needs of most people, it is a new file system characterized by the document system, and has achieved considerable progress. Considering the current situation where the implementation of multiple file systems can occur simultaneously, the demand for Boot Loader-independent of the file system may become strong again. Initializing the basic operating environment Once the kernel starts running, it initializes the internal data structure, detects hardware, and activates the corresponding driver to operate for the application software. It includes an important operation - the operating environment of the application software must have a file system, so the kernel must first load the root file system. Since our goal is to introduce the foundation process, the relevant hardware initialization details will no longer discuss, and the relevant content will be described in detail in the next magazine. After the hardware is initialized, the kernel starts creates the first process - the initial process. Said to be created, in fact, this process is actually the continuation of the entire hardware power-on initialization process, but only the logic of the process is complete, so we will "specify" according to the process of process. " - We also called this initial process called "hardware process", which will occupy the first location of the process descriptor table, so you can use Task [0] or init_task. This process will then create a new process to perform the init () function. In fact, this new process is the first actual useful process of the system, which will follow the initialization operation of the next phase; and the initial process (init_task) You will start executing the IDLE loop, that is, after the kernel initialization is complete, the unique task of the initial process is to consume idle CPU time when there is no other process needs to be executed (so the initial process is also referred to as the IDLE process). The initialization of the next phase is relaxed than the previous stage, because it is now responsible for the completion of a real process, and the previous stage is hand-made manually by the "hardware process". At this stage, this new process created by init_task needs to initialize the bus, the network, and launch various system kernel background threads in the system, then initialize the outer, set file format, after which it is, it is the final Preparation - Initialization File System, Install the root file system, open / dev / console device, redirect stdin, stdout, and stderr to the console, then search the init program in the file system, and use the execve () system call to load the execution init program . The system has entered the user state here. Loading the root file system In order to load the file system, the kernel requires: 1 Know that the root file system is located on that storage medium; 2 There is a driver accessing the media. The most common situation is that root is an EXT2 file system, located on the IDE hard drive. In this case, the operation needs is simple: use the device number as the parameter to the kernel, the IDE device driver usually compiles the kernel. If the kernel does not have a related medium driver, the problem will become more complicated. And this situation is not rare, such as the "general" kernel used by Linux installation disks generally encounters. If the kernel contains all the device drivers of all supported hardware, it will become a homomized material; and some drivers affect other devices when detecting the hardware. This problem can be solved by the initrd mechanism, which allows the RAM file system to be used before loading the actual root file system.

In addition to the above two reasons, the introduction of initrd can also solve the dynamic synthesis of kernels. (For details, please refer to the reference, I should notice that INIT is not never since the entire startup process, it can be said to be a plugin, in order to solve the above problems, and is added to the startup process, the image is shown The Linux system can also do not select it at startup. Why introduce Initrd? The Linux startup process is definitely to load kernel mirror, some elements must be considered in this process: First, the kernel mirror cannot be too large. Due to the limits of various hardware and compatibility, Linux kernel mirrors cannot be too large, but this is not easy to do. The core part of the Linux kernel itself is not small; but also the driver that will be used. Second, support as many hardware devices as possible. We have an important task during the startup process: mount the root file system, because further data and application software are on it, so our kernel must be able to access the root file system. For general users, if they use the EXT2 file partition on the IDE hard drive as the root file system, there will be no problem. Because whether it is an IDE hard drive or an EXT2 file system, their driver will definitely contain inside the kernel. However, there are some special situations: For example, we want to issue a Linux system installation CD, then drive the disc, it is not necessarily included in the kernel. (Some people may be strange, 咦, 咦, 咦 内 内 像 像 读If there is no drive driver, how do we install the packages in the CD to the user's computer? Pre-compiling the driver into the kernel? It sounds good, but if we have some other installation media in addition to the CD, all of these drivers will make the kernels are huge. Moreover, there are more serious problems, and a variety of different drivers can conflict, especially when ISA devices account for the market dominance, this conflict is simply difficult to avoid. At that time, the solution was that the publisher provided a predetermined well-compiled different kernels, put each kernel into a floppy disk, handed over to the user with the issuing package, and the user chooses the soft disk with the appropriate kernel to boot . Or give the user a tool for making a boot disk, allowing users to make their own boot disk before installation. Of course, which method cannot be satisfied. The only hope is to use modular mechanisms. Call the corresponding module loading driver when the kernel is started, and then access the root file system. Whether it is through the kernel to make further analysis or directly from the user to configure information, first configure the method of loading the module, can effectively avoid the occurrence of conflicts. In addition to calling the corresponding module before installing, we may still need to call some modules before mount the root file system before installing the ROOT file system. This is mainly configured to configure computers - typically perform kernel configurations for different computers. Ideally, the user configures the compilation file according to its own actual situation, recompile the kernel, and complete this work. But there are no few users like this lengthy and very easy to have erroneous work. Moreover, compiling and generating kernels requires corresponding tools, but most users do not need these tools. In the installation process, you can directly build a monolithic kernel, but this does not solve the problem: First, all the compilation tools need, secondly, the error in the compilation process has caused the probability that the task cannot be completed too much.

转载请注明原文地址:https://www.9cbs.com/read-41493.html

New Post(0)