Overlay File System parsing __overlay

Source: Internet
Author: User
Tags file copy

A overlay file system contains two file systems, a upper file system, and a lower file system, and is a new type of federated file system. Overlay is "overlay ... Above "means that the overlay file system means that one file system is covered by another file system.
to better demonstrate the principles of the overlay file system, a new overlay file system is being built. The file tree structure is as follows:

1, create four file directories in a previous sibling directory (such as/root) in a Linux operating system that supports the overlay file system (3.18 or more) lower, upper, merged, work where lower and the contents of the upper folder as shown above, merged and work are empty, same filename is the same, content is different.
2, under the/root directory to execute the following Mount command, you can see that the empty merged folder already contains the lower and upper folder all the files and directories.
$mount-T overlay overlay-olowerdir=./lower,upperdir=./upper,workdir=./work./merged
3, use the DF–H command to see the newly built over The lay file system is already mounted.
filesystem Size Used avail use% mounted on
overlay 20G 13G 7.8G 62%/root/merged

So the lower and upper directories have the same folders and the same files, which are displayed when merged into the merged directory. The rules are as follows:
1. File name and directory are not the same, then lower and upper directory of files and directories in accordance with the original structure into the merged directory;
2. The file name is the same, showing only the upper layer files. As shown above in the lower and upper directory and the lower directory dir_a have same.txt files, but when merged into the merged directory, only the upper, and lower hidden;
3. The directory name is the same, the directory is merged into a directory. As shown above in the lower and upper directories have a dir_a directory, the directory and all the files in the directory merged into the merged dir_a directory, if the directory has the same file name, it will also show only upper, such as the dir_a in the image above the Same.txt file.

Overlay supports only two tiers, upper file systems are usually writable, and lower file systems are read-only, which means that when we make any changes to the overlay file system, only the files in the upper file system are modified. Let's take a look at the read, write, and delete operations of the overlay file system.

Read
Lower read Upper do not have some documents, you need to read from the lower;
Read only when upper some files, directly from the upper
When you read lower and upper files, you read them directly from upper.

Write
Upper only in the case of files, directly in upper write
In Lower and upper all the files, it is written directly in upper.
In the case of lower files only write, you will do a copy_up operation, first from the lower file copy to upper, and create a hard link for the file. At this point you can see that two new files are generated in the upper directory, and the write operation only takes effect on files copied from lower to upper, and lower or original files.

By deleting
When you delete lower and upper files, upper will be deleted, create a ' without ' file in the upper directory, and lower will not be deleted.
When you delete lower files that are not upper, you create a ' without ' file in the upper directory for the deleted file, and the lower will not be deleted.
When you delete lower and upper directories, upper will be deleted, creating a ' without ' directory similar to the ' opaque ' file in the upper directory, and lower will not be deleted.

As you can see, because lower is read-only, no changes will be made to lower, regardless of the files and directories on lower. All the operations are done on the upper,.

Copy_up only in the first write on the file to do copy_up operation, the following operations are no longer need to do copy_up, all only operate this file, especially for large files of the scene. The overlay copy_up operation is faster than the AUFS, because there are many layers in the aufs, and there may be delays across many layers, while overlay is only two layers. And overlay was merged into Linux kernel Mailline in 2014, but Aufs was not merged into Linux kernel mailline, so overlay could be faster than AUFS.

The lower file system can be used for any Linux-supported file system, or even for another overlayfs. Because although the bottom of the overlay file system is made up of two file systems, it is only a file system, as previously seen with the DF command, and can also form a new overlay file system with other file systems. The upper is writable and does not support NFS. Multilayer lower can perform the following commands:
$mount-T overlay overlay-olowerdir=/lower1:/lower2:/lower3, upperdir=./upper,workdir=./work./merged
In the example above, lower is merged into a file system by three file systems, where Lower1 is on top and lower3 at the bottom.
Docker has been using AUFS (Advanced multi-level Unified file system) as a container file system. Aufs is a layered file system that transparently covers one or more existing file systems. When a process needs to modify a file, Aufs creates a copy of the file. Aufs can combine multiple layers into a single layer representation of a file system. Docker's image is Aufs, and each new version is a simple variance change from the previous version, effectively keeping the mirrored file minimized. What's the difference after Docker use overlay?
First mirroring at the time of download each layer of the mirror has its own mirror ID, each mirror will have its own directory, saved in the/var/lib/docker/overlay directory, but the names of these layers directory is not the name of the download image when the ID. We all know that Aufs is a multilayer, how it is reflected in the two layer. After starting a container, also in this directory to create a layer directory, into the directory can see three folders, respectively, Merged,upper,work, and a file Lower-id, and in the Lower-id is the image of the highest level of the ID, so for the container, It's also a two-tier file system.

This explains that Docker pull image displays a mirror ID name that is not the same as the Mirror directory name under the/var/lib/docker/overlay directory. The mirrored directory holds files that are unique to this layer and that are shared by hard links below. This allows for more efficient use of disk resources.
From the above diagram, we can see that the two layers of overlay correspond to the Docker mirror layer (read-only) and the container layer (writable), only the multi-layer mirrors in the original Aufs are merged into the lower layer, and the upper layer represents the container layer.

We see that although both overlay and AUFS are federated file systems, the structure is simpler than AUFS and incorporates Linux kernel mainline, which can be faster than aufs, but still too young to be cautious in production use. And Aufs as the first storage driver for Docker, has a long history, relatively stable, and in a large number of production practices, there is strong community support.

Reproduced from: http://dockone.io/article/1511

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.