Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux operation and maintenance of the actual file system, file links     - RedHat 6 xrdp use remote login interface (Linux)

- Ten linux version of the system (Linux)

- Transfer MySQL database to MariaDB (Database)

- Iptables use examples (Linux)

- Simple Linux file system - df, du, ln (Linux)

- RedHat Redis Linux installation (Database)

- Linux system on how to use rsync to synchronize data (Server)

- Docker knowledge base (Server)

- Linux kernel boot to retain large memory method summary (Linux)

- Open container cluster management system architecture and components introduced Kubernetes (Server)

- Ubuntu 14.10 users to install Audio Recorder 1.5.7 (Linux)

- Broadcom transplanted to OpenWrt summary (Programming)

- Use Elasticsearch + Logstash + Kibana set up centralized log Practice Analysis Platform (Server)

- OpenDJ installed on RHEL6 (Linux)

- Eclipse configuration GTK (Linux)

- CentOS 6.5 dual card configuration, one of the external network, a local area network connection (Linux)

- List Leaves (Programming)

- Ubuntu users to install Xtreme Download Manager (Linux)

- Linux System Getting Started Learning: rename multiple files in Linux (Linux)

- Replace element and non-replaced elements of learning (Programming)

 
         
  Linux operation and maintenance of the actual file system, file links
     
  Add Date : 2017-08-31      
         
       
         
  Computer operating system software as the most important, part is used directly by the user is its file management. Because computer users first problem encountered is how to save programs and data, and then how to find, copy, altered them. File management is to provide users of these issues settings.

The Bowen main elements:

1, the file system basis (concept paper, classification and storage mechanism)

2, file system management from the perspective of understanding the mechanism file copy, move and delete

3, ext filesystem extended attributes

4, Hard and Soft Links

First, the file system basis:

1. What is the file system:

Operating system responsible for managing access to documents and information organization software is called a file system. The target file system is to provide users with simple, unified interface using files, file access by name. User interface commands, according to the logical structure of the document, intuitive and transparently document the procedures of (so-called transparent means users do not understand the physical structure of the file storage, search method, I / O implementation details and other storage media-related characteristics, can be done about the operation of the document)

2, the file system of classification:

The operating system's file system according to the constituent units are divided into two categories:

(1) streaming file: constitute the basic unit of the streaming file is a character, that the streaming file is a symbolic name in the logical sense and complete finite character stream sequence. Such as Linux, UNIX, OS / 2, windows, adopted streaming file format.

(2) Record Files: Files constitute the basic unit of record is a record, the so-called record, is a collection of information for some independent significance. Such as student achievement file is recorded by the scores of all students, each of which record includes the student's name, student number, all subjects and many other fields.

3, Linux file system type:

  Linux systems, the file is divided into three categories:

(1) files: All files composed by the directory

(2) ordinary file: the system files, user files, utility files, library files

(3) Special Files: all input / output devices are seen as special file system assigns special file name, such as: / dev / lp indicates that the printer device.

4, the virtual file system: VFS (Virtual File System)

In the previous blog post mentioned, Linux system supports many file system, then it is how to do it?

[A] via the virtual file system VFS, so that Linux system can support a number of file systems, this mechanism is somewhat similar to java virtual machine mechanism Ha, it makes java virtual machine mechanism capable of cross-platform!

5, Linux system ext file system management mechanisms:


[Linux process file system to access the file description]

(1) based on the file name in the Directory by correspondence, locate the file corresponding to the Inode number
(2) to re-read the file Inode table according to Inode number
(3) to re-read the corresponding Blocks Inode table according to the Pointer

Tips:

A, there is an important element, is the Directory (directory), it is not a storage container file, but the path to the file mapping, recording a file / directory names corresponding Inode number;

B, each Inode entry occupies 128 bytes;

C, in order to accelerate the speed to find the file, first need to find, then the system will find the results to the cache buffer; in fact, most of the system will start the file cache to buffer (which is the meaning of the buffer)

[File Storage Management]

Disc, disk, tape, etc. is to save the file contents of the physical device, which is divided into physical block (block), storage space for all of the physical blocks of the file. Manage file storage space is block space management, including distribution of free blocks, recycling and organizational questions.

Common file storage management methods are: free block list and the free block chain, bitmaps, free blocks into a set of linked method. Linux and free block bitmap comprehensive set of links to law to manage file storage space:

Each block group contains the same Block number, they are self-managed, its composition as follows:

(1) Super Block (superblock) -> 0 has only the block group superblock

File system information describes the entire partition, such as block size, file system version number, and the last time, and so the mount.
Superblock on a group of blocks 1,3,5,7,9 have a backup;
[File system related commands]

With tune2fs -l and dumpe2fs [-h] to view the superblock information
du: disk usage
    -s: summary, under the display of a specified path and size of all files;
    -h: human-readale

df: disk free
    -l: Displays only information about the local file system
    -h: human-readable
    -P: Posix-compatible style display;
    -i: show inode usage information instead of 1k block
# ---- Tune2fs -l command to view the superblock information ----- #

[Root @ CentOS ~] # tune2fs -l / dev / sda1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: < none>
Last mounted on: / boot
Filesystem UUID: 0a800a5e-6e0b-48f6-b935-1296b7438b64
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 51200 Number #inode
Block count: 204800 # the number of blocks
Reserved block count: 10240
Free blocks: 149802 # idle blocks
Free inodes: 51160 # free inode
First block: 1
Block size: 1024 # block size
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192 # the number of blocks for each block group
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
Flex block group size: 16
Filesystem created: Wed Jan 29 05:20:48 2014
Last mount time: Mon Sep 22 21:01:04 2014
Last write time: Mon Sep 22 21:01:04 2014
Mount count: 19
Maximum mount count: -1
Last checked: Wed Jan 29 05:20:48 2014
Check interval: 0 (< none>)
Lifetime writes: 162 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128 #inode size
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 30a7a5f3-de5b-4d07-b512-ddb52100b427
Journal backup: inode blocks
# ---- Dumpe2fs command to view the superblock information ---- #

[Root @ Centos ~] # dumpe2fs / dev / sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: < none>
Last mounted on: / boot
Filesystem UUID: 0a800a5e-6e0b-48f6-b935-1296b7438b64
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 51200
Block count: 204800
Reserved block count: 10240
Free blocks: 149802
Free inodes: 51160
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
Flex block group size: 16
Filesystem created: Wed Jan 29 05:20:48 2014
Last mount time: Mon Sep 22 21:01:04 2014
Last write time: Mon Sep 22 21:01:04 2014
Mount count: 19
Maximum mount count: -1
Last checked: Wed Jan 29 05:20:48 2014
Check interval: 0 (< none>)
Lifetime writes: 162 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 30a7a5f3-de5b-4d07-b512-ddb52100b427
Journal backup: inode blocks
Journal features: journal_incompat_revoke
Journal size: 4096k
Journal length: 4096
Journal sequence: 0x000000a8
Journal start: 0


Group 0: (Blocks 1-8192) [ITABLE_ZEROED] # 0 block group information
  Checksum 0xf7f8, unused inodes 2006
  Primary superblock at 1, Group descriptors at 2-2 # superblock information
  Reserved GDT blocks at 3-258
  Block bitmap at 259 (+258), Inode bitmap at 275 (+274)
  Inode table at 291-546 (+290)
  3784 free blocks, 2008 free inodes, 6 directories, 2006 unused inodes
  Free blocks: 4409-8192
  Free inodes: 40, 42-2048
Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0x132c, unused inodes 2048
  Backup superblock at 8193, Group descriptors at 8194-8194 # backup superblock
  Reserved GDT blocks at 8195-8450
  Block bitmap at 260 (+4294959363), Inode bitmap at 276 (+4294959379)
  Inode table at 547-802 (+4294959650)
  844 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
  Free blocks: 11336, 11452-12288, 16379-16384
  Free inodes: 2049-4096
Group 2: (Blocks 16385-24576) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0x6de3, unused inodes 2048
  Block bitmap at 261 (+4294951172), Inode bitmap at 277 (+4294951188)
  Inode table at 803-1058 (+4294951714)
  0 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
  Free blocks:
  Free inodes: 4097-6144
Group 3: (Blocks 24577-32768) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xbade, unused inodes 2048
  Backup superblock at 24577, Group descriptors at 24578-24578 # backup superblock
  Reserved GDT blocks at 24579-24834
  Block bitmap at 262 (+4294942981), Inode bitmap at 278 (+4294942997)
  Inode table at 1059-1314 (+4294943778)
  1789 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
  Free blocks: 24835-25101, 25103-26624
  Free inodes: 6145-8192
Group 4: (Blocks 32769-40960) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0x3c6a, unused inodes 2048
  Block bitmap at 263 (+4294934790), Inode bitmap at 279 (+4294934806)
  Inode table at 1315-1570 (+4294935842)
  610 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
  Free blocks: 38303-38912
  Free inodes: 8193-10240
Group 5: (Blocks 40961-49152) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xadda, unused inodes 2048
  Backup superblock at 40961, Group descriptors at 40962-40962
  Reserved GDT blocks at 40963-41218
  Block bitmap at 264 (+4294926599), Inode bitmap at 280 (+4294926615)
  Inode table at 1571-1826 (+4294927906)
  1790 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
  Free blocks: 41219-43008
  Free inodes: 10241-12288
 

(2) GDT: Group Descriptor Table (Block Group Descriptor Table)

By a number of block group descriptors, the entire partition is divided into many blocks set is associated with the number of block group descriptors
Each block group descriptors (Group Descriptor) to store a block group description, for example, in this group of blocks from where to start is the inode table, from where to start is a data block, free inode and data blocks as well as the number and so on
And similar superblock, block group descriptor table also have a copy at the beginning of each block group, this information is very important, once accidentally damaged superblock will lose the entire partition data, once the block group descriptors accidental damage the entire block of data is lost in the group, so they have multiple copies of the
(3) bit map: Bitmap

Divided into fast bitmap (Block Bitmap) and the node bitmap (Inode Bitmap), the mechanism is as follows:

[Block Bitmap]: When applying for the free block from the bitmap to find the word bit = 0, and change it to 1, returns the corresponding block number; return of free blocks, put in place on the map corresponding to the block the word bit to 0 can be.

[Inode Bitmap]: Similar to block bitmap itself accounted for one block, where each bit represents a inode is free for use.

(4) Inode Table: Inode table:

In addition to a data file needs to be stored, some descriptive information also needs to be stored, such as file type (conventional, directories, symbolic links, etc.), permissions, file size, creation / modification / access time, which is the "ls -l" command that information can see, the presence of inode information instead of data blocks.
Each file has an inode, a block group composed of all inode inode table
inode table representing how many blocks we have to decide when you format and write block group descriptor
The default policy mke2fs formatting tool is a set of blocks the number of allocated inode number 8KB
(5) Data Blocks: block

For regular files, the data is stored in data blocks
For a directory, all file and directory names in this directory are stored in a data block, it is saved in the file name in the directory data block
In addition to the file name, the command ls -l to see other information are stored in the file's inode
Directory is a file, the file is a special type of
For symbolic links, if the target path name is stored directly in the inode is short in order to quickly find, if the target is assigned a long path name to save the data block
Device files, FIFO special file and no socket block, the major and minor numbers of the device file stored in the inode

6, ext file system directory:

Can be seen from the above Inode-table, the data in the table is stored in metadata file (which describes the data file attributes, such as file type, file time stamps, file permissions related descriptive information, etc.), but and no file name, the file name is stored in that place?

The file name is stored in the directory Ha! Here to talk about the focus of the directory.

To manage the many file system files, the primary issue is to put the file in an orderly and organized. Each file has a directory entry, the directory is mapped file path (Note: The directory is not a container file), composed of all the directory entry directory file:

As can be seen, Linux file system administration file attributes, separated from the directory entry out Ha! Benefits are separated by two points:

(1) provides a convenient file sharing:

If the file name and file attribute information is not isolated, then point to the same file multiple directory entry should contain the same file attribute information, that is, there are multiple directory entries in multiple copies of the same file attribute information . Apparently so wasted storage space Ha! If the file attributes separated, with multiple directory entry points to a file to save only the same Inode number and file attribute information only one, thus saving storage space. The more shared files to save space, the more obvious. Increase share share link link or revocation is quite convenient (we will talk later knowledge of Linux file system links Kazakhstan).

(2) reduce the file I "find by name" caused / O transfer:

Suppose peripherals as disks, each block is 512 bytes. With Linux, if the directory entry contains the file attributes, directory entry accounting for 78 bytes. If the directory entry does not contain the file attributes, directory entry accounting for 16 bytes. Set up a directory of files, total 128 directory entries, the former is a total of about 20 disk blocks, which is only 4 disk blocks. Because every time you start I / O transfers only a disk block, the latter to find a directory entry to start the disk number is greatly reduced.

7, Linux system directory tree structure:

Again consider a problem: Linux System Why should directory organized in a tree structure?

Hierarchical structure can greatly reduce the complexity of the lookup -> If the system many documents, the directory files become very long, to find a file will take too much time (for example: we want to find a file, but I do not know where to store it, then we need to "/" at the beginning to find, it certainly is very time-consuming and Kazakhstan. at this point we know that if this file is saved in "/ var / log /" down, then look up Doha must be fast!). Tree is a hierarchical data structure, which consists of the root node, sub-sub-sub-nodes and node components. Linux borrows tree structure to organize its file directory, the directory tree is formed organization. Directory tree organization is a form of multi-level directory organization.

8, the directory tree and search operations:

(1) starting from the root directory, subdirectory through levels, final data file name in order to access data files

(2) from the root directory names at all levels, linking the data file name string to become "absolute pathname"

(3) If the user is currently operating on a directory, then called "the current directory"

(4) given path name, find Inode number of files from the directory tree is called "filename search"

Tips: In order to speed up file search, Linux caching mechanism usually (need to find the first time in order to find the file, and then put the result into the buffer cache in).

Two, Linux file system management-related actions:

1, delete the file:

Inode (1) to delete the files classified as idle Inode

(2) the corresponding disk blocks classified as free blocks (will not do anything to the disk blocks)

(3) completely delete files (360 file shredder principle): the file you want to delete the corresponding disk blocks filled with zeros

Conclusion: From the above we can see: Delete files speed is very fast.

2, copy the file: file copy process is to create a file identical to the original (Inode, disk blocks are the same) file

3, move files:

Move files between different partition: Create a new file (and create new Inode disk blocks), delete old files (the files emptied Inode Inode classified as idle, the corresponding disk blocks classified as free block)

With a partition file movement: create a new disk block Inode to the source file; the source file is empty Inode classified as idle Inode.


Three, ext filesystem extended attributes:

lsattr: Lists the extended attributes of the file

chattr: (+ / - / =) assigned to the relevant extended attributes

    -i: true read-only

    -a: only allows additional content

    -c: automatic compression (similar to the NTFS compression)


Fourth, the linked file:

 

1, a hard link: Inode point to the same two paths

[grammar]

How to create a hard link file: ln SRC_FILE LINK_FILE

Second paragraph ls -l command shows the numbers refer to the number of files are hard links:

[characteristic]

Not cross partition;
You can not create hard links to directories (or will cause a circular reference);
For example Directory A -> B, B -> C, C -> A, resulting in an endless loop.

Delete the original file path, does not affect the linked file;
All files point to the same inode, therefore, as they are the same file;
[For example]

# ---- Illustrate the characteristics of hard links ---- #

[Root @ CentOS ~] # mkdir -pv LinkFileTest # Create a directory with the experiment
mkdir: created directory `LinkFileTest '
[Root @ Centos ~] # cd LinkFileTest /
[Root @ Centos LinkFileTest] # cp / etc / fstab. # Fstab file to copy the experiment directory
[Root @ Centos LinkFileTest] # ln fstab fstab_bak # fstab file to create a hard link
[Root @ Centos LinkFileTest] # ls -l
total 8
-rw-r - r-- 2 root root 924 Oct 8 20:45 fstab.
-rw-r -. r-- 2 root root 924 Oct 8 20:45 fstab_bak # can see the size of the two files, and other related properties are the same
[Root @ Centos LinkFileTest] # ls -i # command to view the number of the file Inode
396473 fstab 396473 fstab_bak # Inode number can be seen in the original document and its linked files exactly as hard

# Attempt to create hard links to directories:
[Root @ Centos LinkFileTest] # ln / tmp / / hello
ln: `/ tmp / ': hard link not allowed for directory # wrong Ha: Not allowed to create hard links to directories

2, soft links :( symbolic link, symbolic link)

ls -l: displays the file type of file l

[grammar]

How to create a soft link file: ln -s SRC_FILE LINK_FILE

[characteristic]

Without zoning restrictions;
To create the directory;
Delete the original file, the linked file will not be available;
Link file with the original file points to a different inode, therefore, is not the same file;
Number of characters in the file size of the file is a soft link it points to the file name (only Inode, no specific disk blocks)
Use symbolic links, find the file operation may be twice
Soft link file types depends on what the linked files
Tips: flexible connection system similar to shortcut windows

[For example]

# ---- Illustrate a soft link characteristic ---- #

# To create a soft link to the directory
[Root @ CentOS LinkFileTest] # ls -l
total 4
-rw-r - r-- 1 root root 924 Oct 8 21:06 fstab.
lrwxrwxrwx 1 root root 5 Oct 8 21:23 temp -.> / tmp /

# Linked file with the original file points to a different Inode
[Root @ Centos LinkFileTest] # ls -i fstab fstab_link
396473 fstab 396478 fstab_link

# Number of characters in the soft link file size of the file points to the name
[Root @ Centos LinkFileTest] # ls -l
total 4
-rw-r - r-- 1 root root 924 Oct 8 21:28 fstab.
lrwxrwxrwx 1 root root 5 Oct 8 21:25 fstab_link -> fstab # fstab:. Ha exactly five characters
lrwxrwxrwx 1 root root 5 Oct 8 21:23 temp -.> / tmp /

File Type # soft connection depends on the type of the original document
 [Root @ Centos LinkFileTest] # ls -l
total 4
-rw-r - r-- 1 root root 924 Oct 8 21:28 fstab.
lrwxrwxrwx 1 root root 5 Oct 8 21:25 fstab_link -.> fstab # fstab_link ordinary file
lrwxrwxrwx 1 root root 5 Oct 8 21:23 temp -.> / tmp / #tmp is a directory, you can cd into
[Root @ Centos LinkFileTest] # cd temp /
[Root @ Centos temp] # ls
ssh-WnVOof5715 vmware-tools-distrib
[Root @ Centos temp] # ls / tmp /
ssh-WnVOof5715 vmware-tools-distrib # can see / the same content tmp / and temp's
     
         
       
         
  More:      
 
- Generators and iterators in Python (Programming)
- Linux System Getting Started Learning: rename multiple files in Linux (Linux)
- Analysis of memory mapping process in Linux x86-32 mode (Linux)
- Linux script to copy the folder to all folders with the same name (Linux)
- The multiplexed signal driving IO (Programming)
- Linux `dirname $ 0` (Linux)
- Use OpenSSL to generate a certificate (Linux)
- Use Observium to monitor your network and servers (Server)
- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)
- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)
- Understanding the Linux load average on other UNIX-Like systems (Linux)
- The virtual memory (Linux)
- Linux crontab command format example (Linux)
- Linux System Getting Started Learning: the curl set custom HTTP header (Linux)
- CKEditor + SWFUpload achieve a more powerful editor (Linux)
- Install Ubuntu 14.04 and Windows 8 / 8.1 dual-boot in UEFI mode (Linux)
- Linux modify the network interface name (Linux)
- Eight kinds of techniques to solve hard problems Linux (Linux)
- Python format string (Programming)
- The ActiveMQ JMS installation and application examples for Linux (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.