Linux- File System - Study Notes (14): root file system principle and procedure of setting up nfs

Linux- File System - Study Notes (14): root file system principle and procedure of setting up nfs

First, the root file system

1, the root file system Introduction

Why do I need a root file system?
(1) application of the init process on the root file system, the root file system is necessary when switching to the user mode.
(2) the root file system provides a root directory / , equivalent to a number of the starting point, through this to find the location you want to find.
The application layer configuration (the (3) core promoter etc directory ) on the root file system. Almost can be considered: Release = kernel + rootfs.
(. 4) the shell command program on the root file system. For example ls, cd commands (which are in shell command / the bin).
Summary: a linux system, only the kernel itself is not working, we must rootfs configuration file in the etc directory (on, / bin / sbin and other directory under the command shell, and / library files in the lib directory, etc. * ·) cooperate to work.

The substance of the root file system
(1) root file system is a special-purpose file system . Relative to the root file system, the file system can provide root directory.
(2) the root file system must belong to a certain file system format . = rootfstype
(. 3) Because the storage device (block devices, like hard disks, flash, etc.) is a block (sector), to access the underlying physical storage devices in accordance with the block number (sector number) is accessed. File system is some code is a set of software , the software function is to manage the storage device sector,The access into these sectors access to the directory and file name. We in the upper layer in a specific directory and file name to access a file, the file system will access the directory + filename translate into this sector number . Bottom or by accessing the sector number, but only the top file name operations.
(4) differences file system is that different management strategies and methods for the sectors, such as bad block management, management of debris.

Root file system in the form of
the root file system has two forms, one is available to burn the image file format , you can download another folder form .

(1) image file format
we can use special tools to make the software available to burn the image file . Image file contains all of the files in the root file system, which means being able to see all the contents of the file system are there, that is, those files slashes / under. Burn this image format is similar to the corresponding partition. The system has a certain image file format, the format is internalized , with the file name suffix is irrelevant.
Main image file in the form of the root file system object block device is used to burn the kernel starts, to mount it on the device.Image file in the form of the root file system using a dedicated authoring tool by a mirror in the form of a folder created from the root file system

(2) a folder in the form of
files in the root file system is actually a folder containing specific content only. It can be any empty folder add the necessary documents constitute together (mkdir to create a empty folder, and then add this folder to something).
Initially in the development of the host casually mkdir to create an empty folder, and then add the necessary documents (including running etc directory configuration executable file under, / bin directory, etc. to which the / lib directory under the file library etc....) is formed after the form of a folder rootfs. Then this folder rootfs form may be used by the kernel to the remote mount nfs embodiment, but can not be used to burn a block device . To this we burned into rootfs block device so with some special software tools be made into the root file system image for burning a certain format.
rootfs folder form is not formatted, made into a mirror after a certain rootfs format, and the format is mirrored by our production processes and production tools to decide. Usage mirroring tools, each format is different.

What is the root file system have?
Here Insert Picture Description
(1) The most important thing is to linuxrc . Later it will be brief.
(2) the device file dev directory . Everything is in linux files, so a hardware device can also be virtualized into a device to access the file , in linux systems/ Dev / xxx says that a hardware deviceWhen we want to operate this hardware device is open to open the file, and then read / write / ioctl operation of this equipment, turn off the device last close.The minimum rootfs in the / dev directory is essential, and there are one or two device files rootfs is a must.
(3) SYS and proc directory . Rootfs is also the minimum can not be omitted, but as long as these two can create an empty folder, which is not something, they do not have something. Both directories and drives also related. Belonging to the virtual file system in linux.
(4) usr is the repository for all users of the system some files are automatically generated when this thing busybox installed in the future. For example, some libraries to install their own application ......
(5) etc directory is a very important key to a configuration file for all files in the directory are all running. All configuration files in the / etc directory will be called to perform directly or indirectly is / linuxrc, upon completion of the configuration to run the operating system. etc directory is the key to making the rootfs.
(6) lib directory rootfs is a very critical one, that can not be omitted. lib directory decentralization is dynamic and static link library files in the current operating system. We mainly to one of the dynamic link library.
(7) other opt, mnt, etc. are some of the temporary folder.

2, hands-on production root file system ext3 format

Production ext2, ext3, ext4 format needs a root filesystemmke2fsThe application program that is installed by default in ubuntu.
Rootfs generally used to make a variety of different formats of application names are very similar, similar mkfs.xxx.

Let's create the root file system is a hands-on format of ext3 and mount it to a directory to access it. Why do you want to mount it to a different directory? Because creating good content is the root file system can not be operated directly, we need to mount it, the equivalent of an entry to find it, you can view and modify the contents inside through the entrance .

Create a file system commands:

#创建并挂载
dd if=/dev/zero of=rootfs.ext2 bs=1024 count=2048
losetup  /dev/loop1 rootfs.ext2
mke2fs -m 0 /dev/loop1 2048
mount -t ext2 /dev/loop1 ./rootfs/

#卸载
umount /dev/loop1
losetup -d /dev/loop1

NOTE: the first step: if represents the input file, the file is empty; represents the output of the file; Block size is 1024 bytes, count 2048 block, so a total size of 2MB. The second step: rootfs.ext2 is the file name of the root file system. The third step: Use mke2fs indicates that the file format to format ext. Fourth step: ./ rootfs / representation mount rootfs dev / loop1 to the current directory, into rootfs write something equivalent to rootfs.ext2 write something (you need to create a good file to mount rootfs) .

Second, set up nfs server

nfs is a network communications protocol by the server and the client constitute. Use nfs protocol can make a lot of direct application, here we use mainly to do nfs rootfs mount .Development board running kernel do nfs client, nfs server set up in the host ubuntu. Export folder we created in the form of files in ubuntu nfs server host rootfs directory, in the development board can be remotely to mount rootfs folder form and then to start the system.

1, set up nfs server method

(1) Installation nfs

sudo apt-get install nfs-kernel-server
sudo apt-get install nfs-common

(2) Configuration / etc / exports

#打开这个文本
sudo vi /etc/exports
#在文本中添加挂载的目录路径,我这里路径为/root/porting_x210/rootfs/rootfs
/root/porting_x210/rootfs/rootfs *(rw,sync,no_root_squash,no_subtree_check)
#执行命令
chmod 777 -R /root/porting_x210/rootfs/rootfs
sudo showmount -e
#第一次会报错clnt-create : RPC : Program not registered,重启
sudo exportfs -r
sudo showmount localhost -e
#重启nfs服务
sudo /etc/init.d/nfs-kernel-server restart
#挂载,
mount -t nfs -o nolock localhost:/root/porting_x210/rootfs/rootfs /opt

After the mount is completed, go to the / opt folder to see the contents of rootfs.

2, configure the kernel to support as nfs rootfs

(1) First, configure the kernel to support nfs start-up mode. bymake menuconfigImplemented configuration.
Here Insert Picture Description

Networking support 
	Networking options 
		TCP/IP networking
				IP: kernel level autoconfiguration
					[*] IP: DHCP support
					[*] IP: BOOTP support

Here Insert Picture Description

File systems  --->	
	Network File Systems  --->
		<*> NFS client support 
		[*] NFS client support for NFS version 3                                  
		[*] NFS client support for the NFSv3 ACL protocol extension 
		[*] NFS client support for NFS version 4 (EXPERIMENTAL) 
		[] NFS client support for NFSv4.1 (DEVELOPER ONLY) 
		[*] Root file system on NFS  

(2) disposed in uboot bootargs.
Here Insert Picture Description

setenv bootargs root=/dev/nfs nfsroot=192.168.1.141:/root/porting_x210/rootfs/rootfs ip=192.168.1.20:192.168.1.141:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200

Here Insert Picture Description
After starting the kernel discovery, development board kernel to mount rootfs on the remote host , but failed to implement them / linuxrc file. Lite marks the rootfs we making remote mount successful.

Note: when therebash: cd: mnt: Stale file handleWhen the issue, tryumount -f /mnt

三、linuxrc

1. What is the linuxrc?

Back we were to mount the root filesystem successfully, but the display can not be performed linuxrc. So what is the linuxrc it?
(1)/linuxrcIs an executable application , is the application layer , and that the relationship between the kernel source code at all.
(2) / linuxrc in the current kernel development board system is executable to. Therefore, in the ARM SoC linux system, the application is to use arm-linux-gcc compiler links; if it is in the PC linux system, then this program is compiled with gcc connection.
(3) / linuxrc if it is statically compiled then you can run directly connected; if it is dynamically compiled connected then we must also provide the necessary libraries to run to him. But because we / linuxrc This program is called directly executed by the kernel, so users do not have the opportunity to export the path library files, so in fact this / linuxrc can not dynamically linked, are generally static connections .

2. What is the role linuxrc is?

(1) / lead-out user interface when performing the linuxrc . After the operating system starts after a series of their own run configuration, a user will eventually interface (perhaps cmdline, perhaps GUI), the user interface is the / linuxrc brought out (due to run linuxrc allows them to run ).
(2) the user interface, and many other things are not responsible for the / linuxrc program, the user interface has its own dedicated application, but the application's user interface is / linuxrc called directly or indirectly executed . The user interface programs and other applications that process 2,3,4 ?????, and linuxrc belong 1 (init process) process, so that the process is a process ancestor of all other application processes.
(3) Configure the start / linuxrc responsible for the system . Because it is not used directly after the operating system starts up, you need to configure. After the operating system starts to configure the application layer when (commonly called the running configuration, the English abbreviationetc) Is to enable our operating system more convenient to use, more suitable for my personal hobby or practicality.
(4) / linuxrc is generally in the embedded linux busybox . busybox is actually a project written in C language, we use arm-linux-gcc to compile busybox get a canApplications running on linux kernel development board. busybox developed this program is to build rootfs for use in embedded environment, that he is the init process applications specially developed .
busybox provides a set of command shell assembly to the current system . For example vi, cd, mkdir, ls like. In the desktop version of linux distributions (such as ubuntu, redhat, centOS, etc.) in vi, cd, ls, etc. are a a separate application. But in the embedded linux, in order to save our collection of vi, cd and all other common shell commands together to form a shell command packet, and called busybox, it does is linuxrc do.

Fourth, the supplement: VFS

1, VFS Introduction

Here Insert Picture Description
Linux kernel VFS is a design concept, design mechanism. VFS is vitrual file system, called a virtual file system.
Some specific file systems designed primarily as FAT, NTFS, ext2, ext3, jffs2, yaffs2, ubi management block to other devices (hard disks, Nand ···). VFS is a design concept borrowed from the file system (file system difficult to manage the underlying physical disk sector access type, are converted to directory + filename ways to access), access hardware devices also become a virtual file directory + Access. So after we had VFS can access the system hardware through device files (directory + file name, such as / dev / mmcblk0p2) way .

2, VFS role

Access and access to common files (1) will be a hardware device to interface to a unified (linux is everything session file).
(2) the operating system, the upper layer (application layer) for access to the details of the different types of file systems to shield off the lower layer. So if we did not write that VFS cp command (other commands, too) when you have to consider your cp this document under what file system type. So cp command is very complex, so consider specific file system type. Once you have VFS situation is different. VFS has become a spacer layer, the isolation of the underlying differences in different file systems, providing a unified interface to the upper layer application .It's like a master key, we can access a variety of different types of file systems in the same way by VFS.
(3) VFS different file systems and the underlying hardware (block device) between the drive also to the details of the shield. Different types of file system itself is not designed to consider a variety of specific operational differences of different hardware devices, there is a similar concept of VFS.

Published 78 original articles · won praise 102 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_42826337/article/details/105345836