Linux file system 笔记
整理自 TLDP: Introduction to Linux 。
“On a UNIX system, everything is a file; if something is not a file, it is a process.”
Sorts of files
- Regular files
- Directories: files that are lists of other files.
- Special files: the mechanism used for input and output. Most special files are in /dev, we will discuss them later.
- Links: a system to make a file or directory visible in multiple parts of the system’s file tree. We will talk about links in detail.
- (Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system’s access control.
- Named pipes: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics.
Table. File types in a long list (
To achieve higher data security in case of disaster.
Partition layout and types
There are two kinds of major partitions on a Linux system:
- data partition: normal Linux system data, including the root partition containing all the data to start up and run the system.
- swap partition: expansion of the computer’s physical memory, extra memory on hard disk.
Maybe there is a /boot partition for holding the kernel files.
All partitions are attached to the system via a mount point. （使用
Usually, all partitions are connected through the root partition.
During system startup, all the partitions are thus mounted, as described in the file
On a running system, information about the partitions and their mount points can be displayed using the
df command. (The
df command only displays information about active non-swap partitions.)
More file system layout
The Linux file system is usually thought of in a tree structure.
Table: Subdirectories of the root directory
The file system in reality
Every partition has its own file system. In a file system, a file is represented by an inode, a kind of serial number containing information about the actual data that makes up the file: to whom this file belongs, and where is it located on the hard disk.
Every partition has its own set of inodes; throughout a system with multiple partitions, files with the same inode number can exist.
When a hard disk is initialized to accept data storage, usually during the initial system installation process or when adding extra disks to an existing system, a fixed number of inodes per partition is created. （inode 枯竭问题）
- Owner and group owner of the file.
- File type (regular, directory, …)
- Permissions on the file.
- Date and time of creation, last read and change.
- Date and time this information has been changed in the inode.
- Number of links to this file.
- File size
- An address defining the actual location of the file data.
The only information not included in an inode, is the file name and directory. These are stored in the special directory files.