Linux disk and file system missing and missing

Source: Internet
Author: User

Linux disk and file system missing and missing
Linux disks and file systems

Format

Because the file attributes/permissions set by each file system are not the same, to store the data, you need to format the separation slot. For example, inode exists in the file system on linux, block, superBlock, these exist for the file system, so during formatting, you need to add tags in the disk to mark the magic horse!

File System

InLVMAndDisk ArrayBefore the technology, a separation slot represents a file system. Now, instead of a separation slot, it turns the data that can be attached into a file system.

Basic data in the three file systems

SuperBlock: Records the total inode/block quantity, usage, remaining amount of a fileSystem, the format and related information of the first-level file system. Inode: Used to store file-related permission information and record the block number of the real data. Block: Where the document content is actually recorded
In linux, ext3/4 is a special storage format and is not prone to fragments. Fragment

Block group

The block records the actual content of the file, so after the plan is completed, it cannot be changed. If a block is too large, it will cause inefficient Data Reading.
Therefore, the linux File System uses block groups. Each block group has its own independent inode, block, and superBlock.

Data block
-The block size and quantity of each block group are determined during the first formatting, unless the block is reformatted.
-Only one file can be placed in each block!

Inode table

Inode is like a data block. Once formatted, the number cannot be changed.
There are also the following features:

The size of each inode is fixed to B. Each file only occupies one inode. Therefore, the number of files that can be created by each file system is related to the number of inode. When reading data from a file, first, inode checks user permissions and determines whether to read or not to read block information.

In some cases, because the file contains too much data, multiple block information needs to be recorded, but inode only has B, so there will be12 Direct, one indirect, one double indirect, and three indirectIn this way, you can use the block data to record the block number!

Block group
The number of blocks in each file system has been determined during formatting, but sometimes the block in a file system is divided into one group because the file system is too large.Block group rent, Such as Group1 and Group2.
Inode, superBlock, inode bitmap, and block bitmap are all special blocks. Special blocks are used to store special data. Therefore, the data content of general files is stored in the block!
With dumpe2fs, you can see:

Group 0: (Blocks 0-32767) [ITABLE_ZEROED]
Checksum 0xec2c, unused inodes 0
Primary superblock at 0, Group descriptors at 1-1
The reserved GDT block is located in 2-406
Block bitmap at 407 (+ 407), Inode bitmap at 423 (+ 423)
Inode table 439-948 (+ 439)
22643 free blocks, 0 free inodes, 1138 directories
Number of available blocks: 9881,101 26-32767
Available inode count:

Inode and spuerBlock are all stored in the block.

Relationship between directories, inode, and block
A directory is associated with an inode and at least one block is associated.

The inode stores the permission information and the allocated block number. The inode stores the file name and the inode corresponding to the file name (you can find the file through inode)
Inode number Filename
123 File1
456 File2
789 File3

The block stores the file information in the directory in this way.

Why is the directory size a Fixed Multiple?

Inode in the directory occupies 4096 B, while block occupies 4 k, so it is basically a multiple!

Mount
The mount point must be a directory. This directory is the entry to the file system, because not all file systems can be used and can be used only after being mounted!

/Inode Number of the file system

ls -i -d /  /.  /..

The result is as follows:

2 drwxr-xr-x 23 root 4096 April 12 21:43 //
2 drwxr-xr-x 23 root 4096 April 12 21:43 /./
2 drwxr-xr-x 23 root 4096 April 12 21:43 /../

linux VFS(linux virtual file system)

Because linux can be mounted to multiple types of file systems, there is a big difference between various file systems, I use virtual file system to abstract the underlying types of file systems into non-differentiated, the specific identification and differentiation work is handed over to VFS.

Df (list the total disk usage)

Df-akmThHi
--A: List all file systems.
--K is expressed in kb format
--M in mb format
--H human readable Representation
-The-H human is displayed in the readable form, but the 1000 is used as the zoom ratio
--T lists the types of file systems.
--I: List inode usage

The df command is obtained by reading the superBlock in a file system, which is very fast. Therefore, the df command must be followed by a file system, A directory that is not mounted by the file system is not allowed!

Du evaluates the disk usage of the file system

Du-asShkm dirName
--All file entries of
--S: list the sum.
--S: list all subdirectories except the current directory
--H human readable
--K kb show
--M-mb show

Note:If du is used directly, only the directory sizes under the current directory are listed. The files under this directory are not listed, so the listed capacity and current. /The capacity is different. You can add the-a option.

Hard Link(Object connection)

The hard link is to add an entry under the block corresponding to the directory, which stores the file name and inode number corresponding to the file:

filename inodeNumber
filename1 indoeNumberA
filename2 inodeNumberA

Filename1 and filename2 all correspond to the same inodeNumber. Therefore, both file1 and file2 only occupy the space of one file. In fact, only the file name and inode are saved, therefore, when creating a hard link, the memory size is generally not increased, unless the block of the corresponding directory is full, you need to apply for a new memory.
There is a main Name Pointing to inode, so the inode points to the resource will not be released, that is, as long as there is a hard link, the file will always exist

Hard link restrictions

Not across file systems: Because hard links are based on inode, and inode of each file system is independent of each other, it is impossible to cross file systems and cannot hard link directories: because hard links need to link all files under the directory at the same time, in order to reduce the complexity of this operation, the directory object connection is not allowed.

Symbolic Link(Soft link)

Soft links are like shortcuts. Creating a soft link is like creating a new file and writing the full path of the link into the file. Once the soft link is operated, the corresponding name of the linked file will be read, start Operation again! Once the file of the soft link is deleted, the soft link still exists, but it is no longer valid.
Soft links need to occupy inode and block, because it is a new file, rather than simply adding entries in the directory

Format

After we use fdisk to wear a new split slot, if we want to use this split slot, We Need To Format this split slot.

Formatting command:
-Mkfs-t fileSystemType device
-Mke2fs [-B size] [-I size] [-L] [-cj]

File System check and repair

In the case of system power failure and so on, it may cause damage to the file system, so we need to repair the file system. The current commands generally include fsck and badblocks.

Fsck considerations

Fsck is used only when a major system accident occurs. Do not check the fsck when mounting the file system. Otherwise, the file system will be damaged !!!! The file system to be checked must be fsck after umount
Command example: fsck-C-f-t ext4/dev/sdb1 here the-C option is used to display the progress of the current check

Lost + found folder

In a file system, there is usually a folder named lost + found. This folder is generally used to store problematic data after fsck. After fsck, this file will disappear automatically.

Single maintenance mode

In the single-person maintenance mode, the root file system has read-only permissions. In this case, we need to mount-o remount, ew, auto/to read and write the root file system/

Mount command

-A option: Mount all the things that are not attached to/etc/fatab.
-L option: displays which file systems are currently attached to, and-l will explicitly Label
-T option: specifies the type of the file system to be mounted.
-N option: Do not write data to the file/etc/mtab during mounting. For example, it is particularly useful in single-user mode.
-O option: the options here are very powerful:

arg1 arg2 descibe
ro rw Control File System read/write
async sync Synchronous write or asynchronous write Mechanism
auto noauto Allow this file system to be mounted as mount-
dev nodev Whether device files can be created on this file system
suid nosuid Whether the file system contains suid/sgid files
exec noexe Whether executable files are allowed in the file system
default   Standard by default
remount   Remount the File System

Mount-bind
You can use
Mkdir/tmp/tempHome
Mount -- bind/home/tmp/tempHome
These two directories have the same inode, which is somewhat similar to hard links.

The file system can also be mounted using the corresponding label.
We can specify a label when formatting the file system, for example, the command: mke2fs-B-I-j-L "qeesung_label"

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.