Linux file system and node table

Source: Internet
Author: User

Linux file System and node table

A Linux file system
1 We all know that when we install Linux we will first partition the system, and then we will format the partition into a EXT3 format file system. Then there is no other file system in the Linux system, we will briefly introduce the Linux system of several common file systems.
(1) EXT3 file system: ext3 (third-level extended Linux file system, third extended Linux filesystem). Unlike the EXT2 file, the log function is added.
(2) EXT2 and MSDOS: Generally used for floppy disks
(3) ISO9660: CD-ROM File system
(4) GFs and GFS2: File System (SAN) primarily for clustered servers
Two Linux file system nodes (Inodes)
1 Inode (index node) index nodes
2 First of all, let's be clear: a file is actually made up of two parts: a node table and a data area. Inodes Table (node table) contains all the properties of the ext2 and ext3 file systems. The node table contains the types of files, permissions, Uid,gid,link count, size and timestamp, where the data resides on the disk. The data area is where real data is stored.

The size of the 31 inodes (node number) is approximately 128B, and a file must occupy at least 1 inodes. by TUNE2FS
-l/dev/sda7 can view the Inode Size,inode count,block count for this partition.

We know that a computer identifies a user by its UID and identifies a process identified by a process number, and, similarly, the computer recognizes a file by identifying it with an inode. And the file name is just for people to recognize.

4 ways to view node numbers: #ls
-li

[Email protected] ~]# Ls-li

Total 56

533587-RW-------1 root root
1050
Mar
6 02:15 Anaconda-ks.cfg

919063 drwxr-xr-x 2 root root 4096
Mar
6 02:43 Desktop

524290-rw-r--r--1 root root
29302
Mar
6 02:15 Install.log

524291-rw-r--r--1 root root
3738
Mar
6 02:15 Install.log.syslog

The preceding number is the node number of the file,

In fact, our node number is allocated at the time of partition creation.

5 Let's learn to copy, cut, and delete the effect on the file Inode


(1) Effects of replication on file Inode

[Email protected] ~]# cd/boot/

[[email protected] boot]# Ls-li file

6030-rw-r--r--1 root root 0 Mar
6 13:26 File

A as you can see, the node number of this file is 6030, now we copy it to another partition

[email protected] boot]# CP file/var/

[Email protected] boot]# cd/var/

[[email protected] var]# Ls-li file

2115361-rw-r--r--1 root root 0 Mar
6 13:27 File

After copying this file to the/var partition, the inode number of this file is changed.

When a file is copied from one partition to another, the system allocates another inode to the file.

b So what happens when you copy a file node number in the same partition?

[[email protected] boot]# Ls-li file

6030-rw-r--r--1 root root 0 Mar
6 13:26 File

[email protected] boot]# CP file/boot/grub/

[Email protected] boot]# CD grub/

[[email protected] grub]# Ls-li file

22091-rw-r--r--1 root root 0 Mar
6 13:29 File

As you can see, the node number of this file is 6030, and now it becomes 22091.

Copy the file in the same partition, the node number of this file will also change. Because there are two copies of the same file in this partition, only the content of the file is the same, but the Inode property of the file is not the same.

2. The effect of clipping on the file inode

A clipping of the same partition

[Email protected] ~]# cd/boot/

[[email protected] boot]# Ls-li file

6030-rw-r--r--1 root root 0 Mar
6 13:26 File

As you can see, the node number of this file is 6030, and now we will cut one copy of the file in the same partition.

[Email protected] boot]# MV file/boot/test/

[[email protected] test]# Ls-li file

6030-rw-r--r--1 root root 0 Mar
6 13:26 File

As you can see, the node number of this file is unchanged.

When moving to a file within the same partition, the node number of the file does not change.

b different partition clipping

[Email protected] ~]# cd/boot/test/

[[email protected] test]# Ls-li file

6030-rw-r--r--1 root

[Email protected] test]# mv/boot/test/file/var/ftp/pub/

[Email protected] test]# cd/var/ftp/pub/

[[email protected] pub]# Ls-li file

325584-rw-r--r--1 root root 0 Mar
6 13:26 File

As you can see, the node number of this file is bound to change.

3 Removing the effect on the Inode

[Email protected] ~]# cd/boot/

[[email protected] boot]# Ls-li file

6030-rw-r--r--1 root root 0 Mar
6 13:44 File

[[email protected] boot]# RM-RF file

Now we have to delete the file files, in fact, we just will file the node table to delete, in fact, our data are still there. That's why when we delete a file, the file can be retrieved. Of course, if we were to write data into this partition, the original data would be overwritten.

[email protected] boot]# Touch file1

[Email protected] boot]# Ls-li file1

6030-rw-r--r--1 root root 0 Mar
6 13:49 File1

Now we have created a new file file1, the node number of this file is also 6030, it has overwritten the previous data node number. Then the previous data will not be found back.


4 Summary

Copy: In the same partition, the node number is changed.


In different partitions, the node number is changed.

Cut: The node number is unchanged in the same partition.


In different partitions, the node number is changed.

Delete: Just delete the node table of the file, the data is not really deleted, only when the partition is written to the data, it will overwrite the original data.

Key to the 2:inode-linux file system

[Command Basics]
$ ls-li
427333 drwx------2 Abao abao 4096 2009-08-12 20:19 amsn_received
989840-RWXRWXRWX 1 Abao Abao 144 2009-10-22 22:19 chroot-lfs.sh
1038353 drwxr-xr-x Abao abao 4096 2009-11-04 21:42 data
[Note: In the above example, the red is the inode number, and the blue is the current file's link count. ]

The inode is the core concept of understanding the Linux file system. The inode means index node, which is the meaning of indexing. Directories in Linux are also seen as broad-sense files, and understanding the Inode is the best way to understand this generalized file. Each file and directory corresponds to a inode,inode that is unique within a partition.
For a file, its information can be artificially viewed as three parts, filenames, file attributes, and file contents. FileName is the name we usually use, file attributes include file size, permission settings, modification time, and so on. The file content is what we can see with the cat command. File attributes are all stored in the file corresponding to the inode, the file content is physically and inode is not stored together, but placed in a slightly back disk area, also known as the data area. In the inode there is a pointer to the data area.
For a directory, the storage of the directory is also divided into three parts, but also the directory name, directory properties and directory content is referred to as the directory content is actually the directory contains all the files/subdirectories correspondence (file name-inode-relational table). The directory attributes are also stored in the inode, and the contents of the directory are stored in the data area corresponding to the inode.
You might ask, so what's the name? Where did the names of the files and directories go? In fact, this name is stored in the contents of its parent directory. Here's an example.
/tmp contains two files File1 and file2.
Then there will be three inode in the system, for example, their inode number is (/tmp), 10001 (/tmp/file1), 10002 (/tmp/file2).
In the 1000# inode, the Inode and the name of all subordinate files in/tmp are saved, and the attributes of the directory itself are already stored.
In the 10001# inode, the/tmp/file1 own file attributes and pointers to the data area are saved.
In the 10002# inode, the/tmp/file2 own file attributes and pointers to the data area are saved.
The directory name of/TMP is managed by its parent directory (that is,/).
As can be seen from the above example, the name, attributes and content, the latter two are linked together, the name is the parent directory to manage. When two directories point to the same inode, the same attribute + content appears in two different directories. It can even appear in the same directory with a different name. This is the concept of the connection, how many directories point to the current file (or current directory), and this is the number of link count. In a connection, the inode number is the key information for the parent directory to identify the child.
Notice that each partition (partition) has its own inode list, i.e. the inode system for each partition is independent. Then when we load a partitioned device into the currently used partition, the two inode systems overlap. For example, my Linux is mount on/dev/sda1 as root, and then I load the/dev/sda2 onto/home. You will find that the inode number for/home and/is 2. This is the representation of two partitioned inode tables that overlap together.
If you understand this example, you will be able to answer some of the seemingly difficult questions below.


In the above example, why can't I ln/home/abc/d/file? Because doing this is equivalent to having a directory in a/dev/sda1 to connect a file in the/dev/sda2, which is not allowed by the inode system.
Is it possible for LN to function in a directory? What about ln <dir1> <dir2>? This is not possible, because this will appear <dir1> there are two parent directories, from the intuitive, this is unreasonable.
I use the Ls-li command, why see the Empty directory Inode link count is 2? This is what Linux systems are designed to do. When a directory is created, its "file name-inode-relational table" has two elements, one is ".", which means pointing to itself, and the other is "..." The parent directory that points to it. And we see this 2, one is the link to itself, and the other is its parent directory to its link (think about "file name-inode-relational table"). Another interesting thing here is that this new directory points to its parent directory, and its parent directory also points to it, and the connection is bidirectional.
Why do I add a file to the directory, the link count for this file is 1, and the link count of its parent directory does not change? Since a file can be linked more than once, it implies that the file does not record the inode of its parent directory, so that the association between the directory and its sub-files is unidirectional. So that's where it happens.
What is the nature of ln-s? From a programmatic point of view, Symbolic link (symbolic Connection) and connection are fundamentally not the same, symbolic connections are actually shortcuts to names, similar to shortcuts in Windows. Symbolic connections are subordinate to the original file, and the files created by the connection are identical to the original files.
What is the use of ln-s? Ln-s has three main features, one that can cross-partition operations, and second, can be used in the directory, Sunline is a lot of Linux script running mechanism need such symbolic connection.
/What is the inode? I looked at a few systems, and the inode for the directory was 2, but for now I don't know why. /proc/sys's inode is 1, and I'll explain it later, but I don't quite understand it.
How do you know how many inode a system can use? Tune2fs-l/dev/sda1 with the following command, which is inside the E2fsprogs tool.
If there is a problem with the connection between the inode, how should it be resolved? This is a complex problem, simply put, can be repaired with the E2fsck tool, those who are not linked to the inode will be hung into the/lost+found directory.

Linux file system and node table

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.