Partitioning, hard links, soft links for Linux file systems

Source: Internet
Author: User

Start with the disk structure. Differentiated by structure from small to large:
    • sector, fixed 512 bytes
    • Track
    • Cylinder, minimum unit at partition, start cylinder to end cylinder for one partition
The first sector is important, and it includes:
    • The master boot partition MBR (446 bytes) contains the boot loader boot loader. It has the following functions:
      • Menus available: Different systems can be selected for loading, multi-os based
      • Load kernel file: Directly load the operating system kernel program that can be used
      • Transfer to other boot loader: Jump to another partition, execute the boot loader of that partition, use to start different operating systems
    • Partition table (64 bytes), which holds the starting and ending cylinders for each partition. Suppose the hard disk has only 400 cylinders:
      • P1:1~100 (/DEV/SDA1 or C-plate)
      • P2:101~200 (/dev/sda2 or D-plate)
      • P3:201~300 (/dev/sda3 or e-disk)
      • p4:301~400 (/DEV/SDA4 or F-plate)

Here is the boot process:
    1. Running the BIOS
    2. Run the MBR boot loader
    3. The boot loader reads the kernel
    4. Operating system starts running
    5. Individual application launches
Linux uses an indexed file system, with each partition containing a file system. A file occupies a inode,inode that contains most of the file's attributes and points to a block of data that contains actual data. In a Linux system,The inode number is the unique identifier of the file, and the content that you want to get from the file must pass the Inode:
A file contains an inode number and a file name, as shown in the file, which is pointed to by the inode number to find the corresponding inode. The file name is simply user-friendly and the inode number does not change after changing the name:
The-I option displays the inode number of the file, and you can see that the inode number does not change after the filename is modified.
Hard links and soft links for Linux file systems are described below.
If an inode number corresponds to more than one file name, these files are called hard links。 In other words, a hard link is the same file that uses multiple aliases. You can create a hard link by using the link or ln command:
Using the stat command to view the properties of a file, you are actually reading the various fields in the STAT structure:
Creating a hard-link hard_link, you can see that the Inode number and properties of the two files are exactly the same. In fact, two files with different names point to the same inode, and the inode contains most of the file information, so the two file attributes of LS come out exactly the same. The links field is also displayed as 2, which indicates that there are two hard links pointing to the inode.
Next is a soft link (symbolic link).A soft link is a separate file with its own inode and data block, except that the contents of the data block are the path names of the linked files.。 To create a soft link by using the ln-s command:
As you can see, the inode for the two files is different. Soft_link has a hard link number of 1, indicating that only one file points to the inode. Use the Readlink command to view the contents of the symbolic link itself, the contents of the data block corresponding to the inode number 14156667:
The content is the path name of the linked file, which exactly matches the description above.
Let's take another picture to deepen your understanding:

Let's talk about the table of contents. The Linux system does not differentiate between directories and files, and directories are files that record other filenames .. the. And: in each directory. The file is actually a hard link:
As you can see, two files point to the same inode. One file name is., the inode number is 14155777, and the other file is named/work,inode, which is also 14155777.
Each leaf directory (a directory that does not contain other directories) always has a link count of 2, because the inode for that directory is always identified by a directory entry in the previous level directory and by the. Item in this directory, for example, the Dir directory below is a leaf directory, and its number of links is 2:

When you create a test directory in the dir directory:
its number of links has changed to 3 because of the subdirectory test: The item now also points to the inode of the Dir directory, which adds 1 to the number of links. If you add a directory to dir again, the number of links increases in turn.
Reference: "Bird's Linux Private cuisine", "advanced Programming of UNIX environment" p86-p89.https://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/#fig2
Related Article

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.