Categories
Uncategorized

Linux file system

The role of the file system

Data stored in the hard disk, but linux will not permit you to operate directly to the disk, which is too the ground floor, said users want to store files had to study hard to learn composed of ??? linux file system as a user and launch the underlying for a buffer between the disk read and write,

File system is a structure for the organization and management documents, such as information available disk space occupied and the rest of the

Common file system

name

description

Basic Linux file system

The enhanced version of ext2

The fourth version of the ext filesystem, centos6 common

centos7 use

Swap file system

Network File System for Linux or Unix machine room shared

Fit between Linux or Unix machines to share and windows

Early windows file system

windows default file system, very powerful

CD-ROM read-only file system

google search dedicated store large amounts of data designed dedicated file system

Early logging using linux file system

ext2
ext3
ext4
xfs
swap
nfs
smbfs
vfat
ntfs
so9660
GFS
reiserfs

VFS (virtual file system)

Linux supports multiple file systems

The Linux kernel is the use of vfs virtual file system, via this intermediate layer provides the perfect support for all kinds of file systems for users, these file systems is almost transparent, users no longer need relationships underlying file system realization

The basic structure of VFS

  • super block
  • dentry
  • inode
  • data

What is a block?

A plurality of physically adjacent sectors becomes a block, the file system is read each time data are in accordance with the fast units, each read one block, this raises a problem, the smaller the block division, space higher utilization, but read and write performance is reduced, the greater the block division, wasted space severe cases may occur, but a good read and write performance

The default size of each block is generally 4k

Super block superblock

Super block is the first block in the file system store, if he is destroyed, the file system will be done, because it stores the entire file system information, including the format inode / block, and the file system

Inode inode

Inode is stored in the file’s metadata, such as file size, file owner, file properties, permissions, file read, modify timestamp, etc., at the same time, it also records the number of block and file data files are located Types of

= + Metadata data file data itself

Usually the number of the inode when formatting has been identified, the average size is 2kb, when we create a directory, this directory can store numbers = inode number of files, and generally use endless

inode number is unique, represents a different file, Linux kernel file access is achieved through the inode number, called a file name, in fact, inode alias role is to facilitate the user to see

How to find the specified file linux?
    linux system finds the inode number of the file based on the file name, the inode number holding inode table lookup pointer to a pointer, the data block to find the specified blocks

directory entry dentry

Directory entry is logical attributes of the profile, it exists only in memory, and with it you can improve query performance, regardless of directories and files, they all belong to a directory entry dentry all directory entries together make up a large tree

It is the file directory, there are also their own inode, open the directory directory file = open

Example: user query /opt/data/a.txt

Where / opt / data / a.txt are directory entries, VFS will be from / inode start the beginning of the layers to find the inode a.txt

Link file

Hard-linked files

Different file names with the same inode, inode is actually to take a number of aliases, but the corresponding kernels, They in fact a file

ln  [原文件] [目标文件]

ln  a.txt  a.hard 

101226430 -rw-r--r--. 2 root root   0 Sep  5 01:35 a.hard
101159754 lrwxrwxrwx. 1 root root   5 Sep  5 02:33 a.soft -> a.txt
101226430 -rw-r--r--. 2 root root   0 Sep  5 01:35 a.txt

Soft link file

Equivalent to the shortcut window inside, the other party is stored inode information

Soft link file has its own inode, which store the source data path

Soft connection can be cross-file system

View the current file system mount the disk

df

Format: df [options] [device name]

    -a: lists all file system

    -i: display inode information of the file system

    -h: displays units (K M)

    -T: list the type of file system

See block the system information block, the right half of FIG.

[[email protected] tmp]# df
Filesystem                      1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00  39269648 2867700  36401948   8% /
devtmpfs                           930152       0    930152   0% /dev
tmpfs                              942028       0    942028   0% /dev/shm
tmpfs                              942028   16896    925132   2% /run
tmpfs                              942028       0    942028   0% /sys/fs/cgroup
/dev/sda2                         1038336   90448    947888   9% /boot
tmpfs                              188408       0    188408   0% /run/user/0

df -i to see is the use of the left

[[email protected] tmp]# df -i
Filesystem                        Inodes IUsed    IFree IUse% Mounted on
/dev/mapper/VolGroup00-LogVol00 19644416 66185 19578231    1% /
devtmpfs                          232538   337   232201    1% /dev
tmpfs                             235507     1   235506    1% /dev/shm
tmpfs                             235507   442   235065    1% /run
tmpfs                             235507    16   235491    1% /sys/fs/cgroup
/dev/sda2                         524288   328   523960    1% /boot
tmpfs                             235507     1   235506    1% /run/user/0

mount

You can see the entire contents

[[email protected] tmp]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=930152k,nr_inodes=232538,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
.....

Repair the file system

Abnormal switch occurs, a sudden power failure, the reader device missteps supper-block in the file system is damaged, in need of repair

Command: fsck (file system check)

Format: fsck [options -t] [file system type] [partition device]

-y: automatic input yes

example:

对/dev/sdb1分区进行修复
fsck -yt ext3 /dev/sdb1

Unmount the file system

format:

umount  存储设备位置  
umount  挂载点目录

Possible causes can not be uninstalled:

  • 设置正在被使用

      Prompt “… device is busy”

Exit to an external file system to retry unloading

The fuser command to find which process by using this file system, kill it off

假设无法卸载的设备为/dev/sdb1 
1)运行下面命令看一下哪个用户哪个进程占用着此设备 
fuser -m -v /dev/sdb1

2)运行下面命令杀掉占用此设备的进程 
fuser -m -v -k /dev/sdb1 
或者fuser -m -v -k -i  /dev/sdb1(每杀掉一下进程会让你确认) 
3)再umount

Configure boot automatically mount the file system

/ Etc / fstab configuration file

[[email protected] tmp]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Apr  6 12:25:22 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup00-LogVol00 /                       xfs     defaults        0 0
UUID=7a0b4526-ffc0-4a51-9a43-d701c30d7c4f /boot                   xfs     defaults        0 0
/dev/mapper/VolGroup00-LogVol01 swap                    swap    defaults        0 0
[[email protected] tmp]# 

example:
    The / dev / sdb1 partition mounted to / mailbox directory

[[email protected] ~]# vi /etc/fstab
/dev/sdb1        /mailbox        ext3        default        0    0

Other file system commands

du command

Spatial Statistics (file system level) of directories and files occupancy

Format: du [options] [directory / filename]

    -a: When statistics include all files

    -h: displays the results (with units) using human-readable manner

    -s: only statistics for each parameter space size

Example: statistical capacity in the / tmp directory

[[email protected] tmp]# du -sh /tmp
48K /tmp

View directory inode

Command: stat
    Format: stat [options] filename

-f: Displays information file where the file system

[[email protected] tmp]# stat /tmp
  File: ‘/tmp’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: fd00h/64768d    Inode: 100663365   Links: 11
Access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:tmp_t:s0
# 访问时间,数据每次被阅读后更新
Access: 2019-09-05 07:18:54.331593449 +0000
# 数据的修改时间
Modify: 2019-09-05 07:50:41.397713275 +0000
# 文件的inode节点被改变时更新
Change: 2019-09-05 07:50:41.397713275 +0000
 Birth: -

Leave a Reply