Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze Linux file system

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly analyzes how to analyze the relevant knowledge points of the Linux file system, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn more about "how to analyze the Linux file system".

To use a computer, you need to store all kinds of data on a hard drive (HDD) or other similar device (such as USB memory). There are two reasons. First, memory (RAM) loses what is stored in it when the computer is turned off. Although there are non-volatile RAM types (such as USB flash and SSD) that store data after the computer is powered off, flash memory is much more expensive than standard, volatile RAM (such as DDR3), and other similar types of RAM.

Another reason data needs to be stored on a hard drive is that even a standard RAM is much more expensive than a regular hard drive. Although the prices of RAM and hard drives are falling rapidly, the price of RAM is still calculated in bytes. Let's do a quick calculation in bytes: based on the price of a 16 GB RAM and a 2 TB hard drive. Calculations show that RAM is about 71 times more expensive than hard drive. Today, the price of a typical RAM is about $0.000000004373750 per byte.

Intuitively show the price of RAM a long time ago, in the very early days of computer development, one of the types of RAM was based on points on the CRT screen. This RAM is very expensive, about $1 per byte.

Define

You may have heard other people talk about file systems in a variety of different and confusing ways. The word file system itself has multiple meanings, and you need to understand its correct meaning in the context of a discussion or document.

I will define different meanings of "file system" based on what I have observed using the word "file system" in different situations. Note that although I try to follow the standard "official" meaning, I intend to define this term based on its different uses (as follows). This means that I will discuss it in more detail in the following chapters of this article.

The entire Linux directory structure that starts with the top-level root (/) directory.

Specific types of data storage formats, such as EXT3, EXT4, BTRFS, XFS, and so on. Linux supports nearly a hundred types of file systems, including some very old and some up to date. Each file system type uses its own unique metadata structure to define how data is stored and accessed.

Partitions or logical volumes formatted with a specific type of file system can be mounted to the specified mount point of the Linux file system.

Basic functions of the file system

Disk storage is a necessary function of the file system, and it comes with some interesting and indispensable details. Obviously, the file system is used to provide space for the storage of non-volatile data, which is its basic function. However, it also has many important functions based on requirements.

All file systems need to provide a namespace, which is a way of naming and organizing. It defines how the file should be named, the maximum length of the file name, and that all available character sets can be used for a subset of the character sets in the file name. It also defines the logical structure of data on disk, such as using directories to organize files rather than aggregating all files into a single, huge file mix.

After defining a namespace, the metadata structure is necessary to provide a logical basis for that namespace. This includes the required data structure to be able to support a hierarchical directory structure, the ability to determine whether blocks in hard disk space are used or available, and the ability to modify the name of a file or directory. Provide information about the file size, creation time, last access or modification time, as well as the location or location of the file to which the data belongs in disk space. Other metadata is used to store advanced information about disk segmentation, such as logical volumes and partitions. This higher-level metadata and the structure it represents contains information that describes that the file system is stored in a drive or partition, but is independent of and independent of the file system metadata.

The file system also requires an application program interface (API) to provide access to system function calls to file system objects, such as files and directories. API also provides functions such as creating, moving, and deleting files. It also provides algorithms to determine certain information, such as where files are stored in the file system. Such algorithms can be used to explain terms such as disk speed and minimizing disk fragmentation.

Modern file systems also provide a security model, which is a scheme that defines access to files and directories. The Linux file system security model ensures that users can only access their own files, not other users' files or the operating system itself.

The last component is the software needed to implement all these functions. Linux uses a two-tier software implementation to improve the efficiency of the system and programmers.

Picture 1:Linux two-tier file system software implementation.

The first of these two layers is the Linux virtual file system. The virtual file system provides a single set of commands for the kernel and developers to access all types of file systems. Virtual file system software interacts with different types of file systems by calling special device drivers. The device driver for a particular file system is a layer 2 implementation. The device driver interprets the standard set of file system commands as specific types of file system commands on partitions or logical volumes.

Directory structure

As a Virgo who is usually very organized, I like to store things in smaller, organized containers rather than in the same large container. The use of directories enables me to store files and find them when I want to view them. Directories, also known as folders, are called folders because the files in them are stored on the physical desktop by analogy.

In Linux and many other operating systems, directories can be organized into a tree-like hierarchical structure. The Linux directory structure is defined in the Linux file system hierarchy standard (LCTT translation note: see this article). When a directory is accessed through a directory reference, deeper directory names are concatenated by a forward slash (/) to form a sequence, such as / var/log and / var/spool/mail. These are called paths.

The following table provides a brief list of standard, well-known, predefined top-level Linux directories and their uses.

Directory description / (root file system) root file system is the top-level directory of the file system. It must contain all the files needed to boot the Linux system before mounting other file systems. It must contain all executables and libraries that need to be used to boot the remaining file system. After the file system starts, all other file systems are mounted as subdirectories of the root file system to a standard, predefined mount point. The / bin/bin directory contains the user's executable file. / boot contains the static bootstrap and kernel executable files and configuration files needed to start the Linux system. / dev this directory contains the device files for each hardware device connected to the system. These files are not device drivers, but represent devices that every computer on the computer can access. / etc contains the local system configuration file for the host computer. The / home home directory stores user files, and each user has a subdirectory located in the / home directory (as its home directory). / lib contains the shared library files needed to boot the system. / media A place where external removable devices are mounted, such as a host that may be connected to a USB drive. / mnt A temporary mount point of a normal file system, such as immovable media, that can be used when an administrator repairs or works on a file system. / opt optional files, such as vendor-supplied applications, should be installed here. / root this is not a root (/) file system. It is the home directory of the root user. / sbin system binaries. These are executable files for system administration. / tmp temporary directory. It is used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without notice. / usr this directory contains shareable, read-only files, including executable binaries and libraries, man files, and other types of documents. / var variable data files are stored here. These files include log files, files for MySQL and other databases, data files for Web servers, mail, and more.

Table the top level of the 1:Linux file system hierarchy

These directories and their subdirectories are shown in Table 1, and in all subdirectories, bold directories make up a necessary part of the root file system. That is, they cannot be created as a separate file system and mounted at boot time. This is because they (especially what they contain) must appear when the system boots for the system to boot correctly.

The / media directory and / mnt directory are part of the root file system, but they never contain any data because they are just temporary mount points.

The remaining non-bold directories in Table 1 do not need to appear during system startup, but will then be mounted to the root file system, where they prepare the host for useful work during the boot phase.

Please refer to the official Linux File system hierarchy Standard (FHS) web page for more details about each of these directories and their subdirectories. There is also a good introduction to FHS on Wikipedia. These standards should be followed as much as possible to ensure operational and functional consistency. This hierarchical directory structure is the same no matter what type of file system is used on the host.

Linux unified directory structure

On some personal computers that are not Linux operating systems, if you have multiple physical hard drives or partitions, each hard disk or partition is assigned a drive letter. It is necessary to know which hard drive the file or program is on, such as C: or D:. Then, you can use the drive letter in the command. Take D: as an example, in order to enter the D: drive, you can use the cd command to change the working directory to the correct directory to locate the required files. Each hard drive has its own separate, complete directory tree.

The Linux file system unifies all physical hard drives and partitions into a single directory structure. They all start with the top-level root directory (/). All other directories and their subdirectories are located in a single Linux root. This means that there is only one directory tree to search for files and programs.

Because there is only one file system, / home, / tmp, / var, / opt, or / usr can be created on a different physical hard drive, partition, or logical partition than the root (/) file system, and then mounted to a mount point (directory) as part of the root file system tree. Even removable drives, such as USB drives or an external USB or ESATA hard drive, can be mounted to the root file system and become an integral part of the directory tree.

When you upgrade from one version of a Linux distribution to another or change from one distribution to another, you can clearly see the benefits of creating to different partitions. In general, except for any upgrade tool such as dnf-upgrade in Fedora, it is wise to occasionally reformat the hard drive containing the operating system during the upgrade process to remove long-accumulated garbage. If the / home directory is part of the root file system (on the same hard drive), it will also be formatted and need to be restored from a previous backup. If the / home directory is a separate file system, the installer will recognize it and skip its formatting. The same is true for / var directories that store databases, mailboxes, web pages, and other variable users, as well as system data.

There are other reasons for treating parts of the Linux system directory tree as a separate file system. For example, a long time ago, I didn't know the possible problem of having all the required Linux directories as part of the root (/) file system, so some very large files filled the / home directory. Because the / home directory and the / tmp directory are not separate file systems, but simple subdirectories of the root file system, the entire root file system is filled. There is no room left for the operating system to store temporary files or extend existing data files. First, the application starts to complain that there is no space to save the file, and then the operating system begins to behave abnormally. After booting to single-user mode and clearing the extra files in the / home directory, you can finally get back to work. I then reinstalled the Linux system using a very standard multi-file system setting to avoid a system crash again.

I once encountered a situation where the Linux host was still running, but users were not allowed to log in through the GUI desktop. I can log in locally through the command line interface (CLI) by using one of the virtual consoles, and then use SSH remotely. The cause of the problem is that some temporary files needed to log in to the GUI desktop cannot be created because the / tmp file system is full. Because the command-line interface login does not require the creation of files in the / tmp directory, no free space does not prevent me from using the command-line interface to log in. In this case, the / tmp directory is a separate file system, and there is a lot of free space on the logical volume where / tmp resides. I simply expanded the capacity of the / tmp logical volume to accommodate the temporary files needed by the host, and the problem was solved. Note that this solution does not require a reboot, and when the / tmp file system expands, users can log in to the desktop.

When I was a lab administrator in a big technology company, I encountered another glitch. The developer installed an application in the wrong location (/ var). As a result, the application crashed because the / var file system was full and the log files stored in / var/log could not attach new log messages due to lack of space. However, the system is still running because the root file system and / tmp file system are not yet full. After removing the application and reinstalling it on the / opt file system, the problem was resolved.

File system Typ

The Linux system supports about 100 partition types of reads, but only a few can be created and written. However, it is common that different types of file systems can be mounted on the same root file system. In this context, the term file system refers to the structure and metadata needed to store and manage user data in a partition on a hard drive or logical volume. Here is a complete list of file system types that can be recognized by the Linux system's fdisk command, you can feel the high compatibility of Linux systems with many types of systems.

The main purpose of Linux's support for reading so many types of partition systems is to improve compatibility so that at least some of the file systems of other computer systems can interact. All the optional types when creating a new file system in Fedora are listed below:

Btrfs

Cramfs

Ext2

Ext3

Ext4

Fat

Gfs2

Hfsplus

Minix

Msdos

Ntfs

Reiserfs

Vfat

Xfs

Other distributions support creating different types of file systems. For example, CentOS 6 only supports the creation of file system types marked in boldface in the above table.

Mounting

The term "mount mount" filesystem on Linux systems means that in the early days of computer development, tapes or removable disk groups needed to be physically mounted to a suitable drive device. When physically placed on a drive, the operating system logically mounts the file system on disk so that the operating system, applications, and users can access the contents of the file system.

A mount point is simply a directory, like any other directory, created as part of the root file system. So, for example, the home file system is mounted in the directory / home. File systems can be mounted to mount points of other non-root file systems, but this is not common.

In the early stages of the Linux system startup phase, the root file system is mounted to the root directory (/). Other file systems are later mounted through Linux launchers such as rc under SystemV or systemd in newer Linux distributions. The mount of the file system during the startup process is managed by the / etc/fstab configuration file. A simple way to remember is that fstab stands for the "file system table file system table", which contains a list of file systems that need to be mounted, all of which specify mount points and options that may be required for a particular file system.

Use the mount command to mount the file system to an existing directory / mount point. In general, any directory that acts as a mount point should be empty and do not contain any other files. The Linux system does not prevent users from mounting a directory that has been mounted to a file system or from mounting a file system to a directory that contains files. If you mount a file system to an existing directory or file system, its original contents will be hidden and only the contents of the newly mounted file system will be visible.

This is the end of the introduction on "how to analyze the Linux file system". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report