Check for missing disks and file systems in linux.

Source: Internet
Author: User
Tags inode usage

Check for missing disks and file systems in linux.
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, in the file system of linuxinode,block,superBlockThese exist for the file system. Therefore, when formatting, you need to add tags to the disk to mark the Trojan!

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 the block group method. Each block group has its owninode,block,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:

In some cases, because the file contains too much data, you need to record multiple block information, but inode only128BIn inode12 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.
  • In the allocated block, the inode corresponding to the file name and file name is saved (because inode allows you to find the file)
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?

Because inode occupies the Directory128BAnd block usage4k, So it is basically a multiple of 4096!

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 is different from the current./capacity.-aOption.

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, inode of each file system is independent of each other, so it cannot cross file systems
  • Cannot hard link Directory: 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. Therefore, we need to repair the file system.fsckAndbadblocks

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
The command is as follows:fsck -C -f -t ext4 /dev/sdb1Here, the-C option is used to display the progress of the current check.

Lost + found folder

In a file systemlost+foundFolder, which is usually infsckWhen you store problematic data in the futurefsckIn the future, this file will automatically disappear after you see it.

Single maintenance mode

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

Mount command

-A option: Set/etc/fatabAll things that are not hanging are hanging
-L option: displays which file systems are currently attached,-lThe Label
-T option: specifies the type of the file system to be mounted.
-N option: Do not write data to a file during mounting./etc/mtabFor 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 systemmount -aIn the form
Dev Nodev Whether device files can be created on this file system
Suid Nosuid Whether the file system containssuid/sgidFile
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.
When formatting the file system, we can specify a label, such as 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.