Linux file system

Source: Internet
Author: User

Today I learned the Linux file system, and now I want to make a small summary.

First, everything in Linux is a file, and the following list is the top-level directory structure of the Linux system.

Listing 1. Top-level directory structure for Linux systems
/root directory ├──bin store user binaries ├──boot store kernel boot profile ├──dev store device files ├──etc Storage System configuration file ├──home  Home directory ├──lib dynamic shared library ├──lost+found file system Recovery file ├──media Removable Storage media mount point ├──mnt File System temporary mount point ├──opt Additional application package ├──proc system Memory Mapping directory, providing kernel and process information ├──root root user home directory ├──sbin storage System binaries ├──SRV store service related data ├──sys sys virtual paper System mount point ├──tmp Storage temporary file ├──usr store user Application └──var store mail, System log and other change files
 
In the Linux system, usually in advance to give it a piece of hard disk (100G), and then start with a USB stick, enter the custom options, this will be the 100G hard disk partition, generally divided into/boot,/,/home, swap,/usr, the 5 partitions.
The Linux kernel treats each partition as a separate device located under the/dev path. (sda1 sda2 SDA3......SD10)
Each disk partition is either a file system (which holds regular files) or a swap area (swap for kernel memory management)
On my computer, I have 4 file systems (/boot,//////usr) and one swap space (swap)
In a file system, the basic unit used to allocate space is a logical block, that is, a number of contiguous physical blocks on the disk device where the file system resides.
Disk partition is composed of disk partitions, each disk partition is a file system, the file system consists of a boot block, super block, I node table, data blocks.
Here is a very detailed explanation of the file system structure I read on the Internet.





In the last picture, the disk is divided into 3 zones, with 3 file systems, which are expanded for the second file system.
The diagram below is the original of the Linux system Programming manual, the data block pointer of the I node in the first picture, and the second is mount, which lists all the file systems and mounts of the current host, and is represented by a vivid graph.


It must be here that everyone has a clear idea of the structure of the file system. Next, we will explain the knowledge of the hard and soft connections of the Linux file system, which are closely related to the use of the Linux file system, especially the I node.
First of all, the following image will be how to find the corresponding file data block based on the file name, through the directory table and the I node table.
We know that files have filenames and data, which are divided into two parts on Linux: User data and metadata (metadata). User data, which is the file block (data block), is where the real content of the file is recorded, while metadata is an attached property of the file, such as file size, creation time, owner, and so on. In Linux, the inode number in the metadata (the Inode is part of the file metadata but does not contain a file name, the inode number is the index node number) is the unique identifier of the file and not the filename. The file name is only for the convenience of people's memory and use, the system or program through the inode number to find the correct file data block shows the program through the file name to obtain the contents of the process.



The next step is to explain what a hard connection is and what a soft connection is.

There are two types of 1.Linux links, one called hard link, and the other is called symbolic symbolic link. By default, the LN command produces a hard link.

"Hard Connect"
A hard connection is a connection that is made through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). In Linux, multiple file names point to the same index node that exists. In general, this connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathname, so that users can establish a hard connection to important files to prevent "accidental deletion" of the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, and the connection to the file's data block and directory will be released only if the last connection is deleted. That is, the condition that the file is actually deleted is that all the hard connection files associated with it are deleted.

"Soft Connect"
Another connection is called a symbolic connection (symbolic link), also known as a soft connection. A soft-link file has a shortcut similar to Windows. It's actually a special file. In a symbolic connection, a file is actually a text file that contains location information for another file.



If you think that through the above examples there are still some do not understand, then the following through a more specific example to tell you thoroughly.
 








Finally, add a little bit of knowledge to the Linux system Programming manual.

In this picture, the main point is how to find the corresponding/etc/passwd file through the I node table and directory table, first find/directory, and then find/etc directory, and finally find the passwd file, file data content and table of contents are placed in the data block.

The final picture shows you the difference between a hard link and a soft connection.
A hard connection is actually a file alias, and two files are the same I node.
But a soft connection (symbolic connection) is the location of the original file where the new file is created, and the new file's data block content is the address.
Hope this summary, can better help you understand the Linux file system.

Linux file system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.