linux disk and partition, the virtual file system

There are three major Linux operating system device file:

1. Character apparatus: sequential bytes of I / O operations of the apparatus;

2. The block device: receiving an input return in units of blocks, for the I / O request has a corresponding buffer, random access, the position of the block access device must be able to move back and forth in different sections of the media. In block apparatus, the smallest addressable unit is a sector, the sector size is typically an integer multiple of 2, the common size is 512 bytes;

3. The network device: a network providing data communication services.

Here to discuss the theme block device.
To disk as an example:

fd:软驱
hd:IDE 磁盘
sd:SCSI 磁盘
tty:terminals
vd:virtio 磁盘

1. sectors (Sectors): Any hardware block device basic unit of data processing. Typically, the size of a sector is 512byte.

2. Block (Blocks): developed by the basic unit of data processing Linux kernel or file system or the like. Typically, one block by one or more sectors.

Use virtio_blk disk drive is displayed as "/ dev / vda", which is different from the IDE hard disk "/ dev / hda" or SATA drives "/ dev / sda" identify such display.

Partition knowledge points
in the Linux system, all of the disks and disk each partition is used to represent the form of a file. For example, there is in your computer hard disk, divided into three partitions on your hard disk, then there will be a corresponding 4 device file in the Linux system, a hard disk device file, in addition to each partition also has a device file, all the files are stored in a unified device / dev directory.
Different types of hard disk and partition device file name has uniform rules, specific expressions of the form:
Hard disk: IDE interface for hard disk device, indicated as "hdX" in the form of a file name for SATA or SCSI hard disk interface device, He expressed as "sdX" filename of the form, wherein the "X" number of letters a, b, c, d and the like. For example, the system 1 of the IDE devices represented as "hda", the second SATA devices represented as "sdb".
Partition: the partition when expressed, a hard disk device file name as a basis to add a digital number corresponding to the partition to behind. For example, first an IDE hard disk in the first partition is represented as "hda1", the second partition is represented as "hda2", the second SATA disk of the third partition is represented as "sdb3", 4th partition He expressed as "sdb4" and so on.
Note that, since the number of at most four primary partitions, so the primary and extended partitions also limits the number between 1 and 4, the logical partition number will always start from the 5. For example, even if the first one IDE hard disk divided into only one primary partition, an extended partition, the new first logical partition number is still from 5 starts, should be indicated as "sda5", the second logical partition represented as "sda6".
Here Insert Picture Description
Here Insert Picture Description
In addition, for all removable storage devices using the USB interface, whether mobile hard disk, USB flash drives, or USB drive, you always use / dev / sdxx device file. CD-ROM (CD-ROM) device file generally default to / dev / cdrom, this is unrelated to the drive interface.

Each hard disk into several partitions, each partition has its own file system.

The so-called "mount" is the use of a directory as a point of entry, the data disk partition placed in the directory; that is, enter the directory can read the partition means. This operation we call "mount", the directory entry points we call "mount point." Since the most important of the entire Linux system is the root directory, so the root necessarily need to mount a partition. As for the other users of the directory is to follow their own needs to be given to mount a different partition.

Linux file structure of a single tree structure, the root directory is "/" directory should be located in the root directory other.

Every time we will install the system partition, the relationship under Linux disk partition and directory as follows:
Any partition must correspond to a directory in order to read and write operations, known as the "Mount."
Is mounted may be a root directory, and may be another two, three directories, any directory can be a mount point.
Directory is a logical distinction. To distinguish physical partition.
Linux root directory is where all files and directories are located, the need to mount a disk partition.

Below is the correspondence between common directory and partition:
Here Insert Picture Description
Why partition, how to partition?
You can put different information into separate partitions to manage and reduce risk.
Large hard drive large search range and low efficiency.
/ home, / var, / usr / local often separate partition, because the operation often prone to fragmentation.

The VFS (virtual file system)
the Linux allows many different file systems coexist, such as ext2, ext3, vfat like. By using the same set of calling file I / O system can be on any file in Linux operating without considering it in a specific file system format; further, operations on files across file system and execution. As shown below, we can use the cp command vfat hard copy data from the file system format to format the hard disk ext3 file system; and this operation involves two different file systems.
Here Insert Picture Description
Process: VFS file reading method call vfat a.txt data will be read into memory; a.txt then after mapping data in memory to the corresponding memory space b.txt, VFS call ext3 file writing method b. txt written to disk; in order to achieve the final copy operations across file systems.

"Everything is a file" is one of the basic philosophy of Unix / Linux is. Not only ordinary files, directories, character devices, block devices, sockets, etc. are treated in Unix / Linux are in a file; although they are different types, but it is provided with a user interface. For an operation to open a file; to open a file, the file will know VFS file system format corresponds; when VFS passes control to the actual file system, file system and then make the actual specific distinction, for different file types perform different operations. This is "Everything is a file" lies.

Here Insert Picture Description
From the specific physical media file reading process:
Here Insert Picture Description
When the user application calls the file I / O read () operation, the system calls SYS_READ () is excited, SYS_READ () to find the particular file system is located, which passes control to file system, and finally, the file system data is read out by the specific interaction with the physical medium from the medium.

See Related links:
https://www.cnblogs.com/sammyliu/p/4521315.html
https://www.cnblogs.com/okyoung188/p/7190409.html
https://blog.csdn.net/sdulibh/ article / details / 51802071

Guess you like

Origin blog.csdn.net/weixin_41490593/article/details/90701077