Linux disk and file system
Formatting
Because each file system settings set the file attributes/permissions are not the same, in order to store the data, you need to format the partition, such as in the Linux file system, there is,, inode
block
These are superBlock
for the file system exists, so in the format of the time, You need to add tags to the disk, marking God Horse!
File system
In the absence of LVM and disk array Technology, a divider represents a filesystem, and now instead of the data that can be hung into a filesystem instead of a splitter slot
Basic data in three file systems
- superblock: Record a filesystem inode/block total, usage, remaining amount, first-level file system format and related information
- inode: The permission information used to store the file, while recording the block number where the real data resides
- block: Where the contents of the document are actually recorded
Because this particular form of storage is EXT3/4 on Linux, it is not easy to fragment, so there is no need for defragmentation on Linux
Block groups
Block block is the actual content of the record file, so after planning, it can no longer change, if a block block is too large, it will result in the data reading is not efficient
Therefore, the Linux file system uses a block group approach, each block group has its own independentinode,block,superBlock
Data Block
-Block size and number of blocks per chunk are determined the first time they are formatted, unless reformatted
-Only one file per block can be placed!
Inode table
The inode, like the data block, cannot change the quantity once it is formatted.
There are several features:
- Each inode is fixed to a size of
128B
- Every file is just an
一个
inode.
- So each file system can be created with the
文件数量
number of Inode
- When reading the data of a file, the Inode permission checks the user right before deciding to read the block information
Sometimes because of file data too much, need to record more than one block of information, Inode only 128B
, then there are 12 in the Inode directly, an indirect, a double indirect, a three indirect , This allows you to use block data to record block numbers!
Chunk Group
The number of blocks per file system is determined at the time of formatting, but sometimes the block of a filesystem is divided into a single group because the file system is too large. , that is block group rent , such as Group1, Group2
Inode,superblock, Inode Bitmap, block bitmap These are special block, Block specialization will be used to store some special data, so the data content of the general file is placed in the block!
Use DUMPE2FS to see:
Group 0: (Blocks 0-32767) [itable_zeroed]
Checksum 0xec2c, unused inodes 0
Primary superblock at 0, Group descriptors at 1-1
reserved GDT blocks are located in 2-406
Block bitmap at 407 (+407) and Inode bitmap at 423 (+423)
Inode table at 4 39-948 (+439)
22643 free blocks, 0 free inodes, 1138 directories
Number of available blocks: 9881, 10126-32767
available inode:
/blockquote>
The inode, Spuerblock, and so on are all placed in block blocks.
the relationship between the directory and the Inode, block
A directory associated with an inode and at least one block
- The inode holds the permission information and the allocated block number
- The allocated block contains the file name and the inode of the file name (because you can find the file via the Inode).
inode | Number
filename |
123 |
File1 |
456 |
File2 |
789 |
File3 |
Inside the block is to save the information of the file under the directory in this form.
Why is the size of a directory a fixed multiple?
Because the inode occupies the directory 128B
, and block occupies 4k
, so the basic is a multiple of 4096!
Mount
Mount point must be a directory, the directory is entered into the file system, because not all the file system can be used, must be hung in the future to use!
/File System Inode label
-i-d/ /. /..
We get the result:
2 drwxr-xr-x root root 4096 April 12 21:43//
2 drwxr-xr-x root root 4096 April 12 21:43/./
2 drwxr-xr-x root root 4096 April 12 21:43/.. /
Linux VFS (Linux virtual file system)
Because Linux can be hung on multiple types of file system, there is a large difference between the various filesystem, I am through the virtual file systems to the underlying various types of file systems to abstract the non-discriminatory, the specific identification of the work is given to the VFS to complete
DF (List disk overall usage)
Df-akmthhi
-a lists all file systems
---K in KB format
---M in MB form
---H human readable form shows
----H human is shown in readable form, just 1000 as the scale between
--T is a list of file system types
-I list Inode usage
DF command is obtained by reading the inside of a file system Superblock, the speed is very fast, so the DF command after the must be a file system, a file system is not hung in the directory is not possible!
Du evaluates the disk usage of the file system
DU-ASSHKM DirName
-A all file entries
--S list sum
--S list except for the current directory, excluding subdirectories
---H human can be read
--K KB Show
--M-MB Show
Note: direct du is only listed under the current directory size of the directory, the file is not listed, so the listed capacity and current./capacity is not the same, plus the -a
option is OK
Hard Links (Entity connections)
A hard link can be said to add an entry under the block of the directory, which holds the file name and the inode number corresponding to the file:
filename |
Inodenumber |
Filename1 |
Indoenumbera |
Filename2 |
Inodenumbera |
Where filename1 good filename2 are corresponding to the same inodenumber, so file1 and File2 are only occupy a file of space size, actually save things just file name and Inode, So when you create a new hard link, you generally do not increase the memory size unless the block of the corresponding directory is full and you need to request a new piece of memory.
There is a primary name that points to the inode, so the resource that the inode points to is not released, meaning that the file is always there as long as there is a hard link.
Restrictions on hard links
- Cannot span file systems: Because the base of a hard link is an inode, and each file system's Inode is independent of each other, it cannot span the file system
- Cannot hard link directory: Because the hard link need to link all the files under the directory at the same time, in order to reduce the complexity of this operation, the directory is not allowed to join the entity
Symbolic Links (soft links)
A soft link is like a shortcut. Create a soft link is like a new file, the full path of the link is written to the file, once the soft link operation, then will read the corresponding name of the linked file, and then start the operation! Once the soft link link file is deleted, the soft link still exists, but it is invalid.
Soft links need to occupy the inode and block, because it is a new file, rather than simply adding entries in the directory
Formatting
After we have used Fdisk to wear a new splitter slot, if we want to use this divider, we need to format this slot
Format Command :
-Mkfs-t Filesystemtype Device
-MKE2FS [-B size][-i size][-l][-CJ]
File system Check and Repair
In the case of system power outage and so on, it is possible to damage the file system, then we need to repair the file system, the current instructions are generally fsck
andbadblocks
fsck Considerations
FSCK will only be used when there is a major accident in the system, and it will not be possible to perform a fsck check when the file system is mounted, otherwise it would damage the file system!!!! The file system to be checked must be umount after the fsck
Commands such as: fsck -C -f -t ext4 /dev/sdb1
the-c option here is used to show the progress of the current check
Lost+found folder
In a file system is usually a lost+found
folder called, this folder is usually stored in the fsck
future where the problem data, when you fsck
later, this file will automatically disappear
Single Maintenance Mode
Generally under the single maintenance mode, the root file system permissions are read-only, this time we need to hang the root file system for the read-writemount -o remount,ew,auto /
Mount command
-A option: /etc/fatab
hang all the things that are not hanging up
-L Option: shows what is now hanging on the file system and -l
will explicitly pair the label
-T option: Specify the type of file system you want to mount
-N option: Do not write to the file at mount time /etc/mtab
, such as in the single-player mode is particularly useful
-O option: Here the options are very powerful:
arg1 |
arg2 |
Descibe |
ro |
RW |
control file system read and write |
async |
sync |
|
auto |
noauto |
allow this file system to mount-a Mount |
dev |
nodev |
is it permissible on this file system Setup profile |
suid |
nosuid |
Is it allowed in this file The system contains suid/sgid files |
exec |
noexe |
|
default |
|
|
remount |
|
Re-mount the file system |
Mount–bind
To hang a directory under a directory, you can use the
mkdir /tmp/tempHome
mount --bind /home /tmp/tempHome
The two directories have the same inode, which is somewhat similar to a hard link
the file system can also be mounted with the corresponding label
We can specify a label when we format the file system, such as the command:mke2fs -b -i -j -L “qeesung_label”
Disk and file systems for Linux check gaps