Linux File System mounting and high-level Architecture

Source: Internet
Author: User
Article Title: Linux File System mounting and high-level architecture. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Linux is an excellent platform for using standard and fancy file systems and developing file systems. This article discusses the Virtual File System (VFS, sometimes called the Virtual File System switch) in the Linux kernel, and then introduces the main structure of connecting the file system.

  Basic File System Architecture

The Linux File System architecture is an interesting example of abstracting complex systems. By using a set of common API functions, Linux supports many file systems on many storage devices. For example, a read function call can read a certain number of bytes from a specified file descriptor. The read function does not know the type of the file system, such as ext3 or NFS. It does not know the storage media of the file system, such as AT Attachment Packet Interface (ATAPI) disk, Serial-Attached SCSI (SAS) disk, or Serial Advanced Technology Attachment (SATA) disk. However, when you call the read function to read a file, the data will return normally. This article describes how to implement this mechanism and introduces the main structure of the Linux File System layer.

  What is a file system?

First, answer the most common question "What is a file system ". A file system organizes data and metadata on a storage device. Since the definition is so broad, the code that supports it is very interesting. As mentioned above, there are many file systems and media. Due to the existence of so many types, we can expect that the Linux File System Interface is implemented as a hierarchical architecture, thus separating the user interface layer, file system implementation from the driver of the operating storage device.

  Mounting

In Linux, the process of associating a file system with a storage device is called mounting ). Use the mount command to attach a file system to the current file system hierarchy (Root ). During mounting, you must provide the file system type, file system, and a mount point.

To illustrate the functions of the Linux File System layer (and the mounting method), we create a file system in a file in the current file system. The implementation method is to first use the dd command to create a file of the specified size (use/dev/zero as the source to copy the file)-in other words, a file initialized with zero, see list 1.

Listing 1. Creating an initialized File

1. $ dd if =/dev/zero of = file. img bs = 1 k count = 10000

2.10000 + 0 records in

3.10000 + 0 records out

4. $

Now there is a 10 MB file. img file. Use the losetup command to associate a cyclic device with this file to make it look like a block device, rather than a regular file in the file system:

1. $ losetup/dev/loop0 file. img

2. $

This file is now available as a block device (represented by/dev/loop0 ). Then, use mke2fs to create a file system on this device. This command creates a new ext2 File System of the specified size, as shown in Listing 2.

Listing 2. Create an ext2 file system with a circulating Device

1. $ mke2fs-c/dev/loop0 10000

2. mke2fs 1.35 (28-Feb-2004)

3. max_blocks 1024000, rsv_groups = 1250, rsv_gdb = 39

4. Filesystem label =

5. OS type: Linux

6. Block size = 1024 (log = 0)

7. Fragment size = 1024 (log = 0)

8.2512 inodes, 10000 blocks

9.500 blocks (5.00%) reserved for the super user

10 ....

11. $

Run the mount command to mount the file. img file represented by the cyclic device (/dev/loop0) to the mount point/mnt/point1. Note that the file system type is ext2. After mounting, you can use this mount point as a new file system, such as using the ls command, as shown in listing 3.

Listing 3. Create a mount point and mount the file system through a circulating Device

1. $ mkdir/mnt/point1

2. $ mount-t ext2/dev/loop0/mnt/point1

3. $ ls/mnt/point1

4. lost + found

5. $

As shown in Listing 4, you can continue this process: Create a new file in the mounted file system, associate it with a cyclic device, and then create another file system on it.

Listing 4. Create a new cyclic File System in the cyclic File System

1. $ dd if =/dev/zero of =/mnt/point1/file. img bs = 1 k count = 1000

2.1000 + 0 records in

3.1000 + 0 records out

4. $ losetup/dev/loop1/mnt/point1/file. img

5. $ mke2fs-c/dev/loop1 1000

6. mke2fs 1.35 (28-Feb-2004)

7. max_blocks 1024000, rsv_groups = 125, rsv_gdb = 3

8. Filesystem label =

9 ....

10. $ mkdir/mnt/point2

11. $ mount-t ext2/dev/loop1/mnt/point2

12. $ ls/mnt/point2

13. lost + found

14. $ ls/mnt/point1

15. file. img lost + found

16. $

Through this simple demonstration, you can easily see how powerful the Linux File System (and cyclic devices) is. You can create an encrypted file system on a cyclic device in the same way. You can use cyclic devices to temporarily Mount files as needed, which helps protect data.

  File System Architecture

Now that we have seen the file system construction method, let's look at the Linux File System layer architecture. This article examines the Linux File System from two perspectives. First, use the high-level architecture. Then we will discuss the main structure of implementing the file system layer in depth.

  High-level Architecture

Although most file system code is in the kernel (except for the user space file system discussed later ), however, the architecture shown in Figure 1 shows the relationship between the user space and the main components related to the file system in the kernel.

  
Figure 1. Architecture of Linux File System Components

[1] [2] Next page

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.