Understanding the Linux file system (a)

inode and block Overview

  • File data includes meta-information and the actual data
  • File is stored on the hard disk, the hard disk is the smallest unit of storage "sector", storing 512 bytes per sector.
  • Block (Block)
    Chinese translation of "inode", also known as i-node
    for storing the meta information file
    Understanding the Linux file system (a)

1, inode content

inode contains a lot of file meta-information, but does not include the file name, for example,
the number of bytes of the file
documents have significant UserID
GropuID file
read files, write, and execute permissions
timestamp file
structure directory file
directory is a file
directory file structure of
each inode has a number, operating system used to identify different inode number of file
inside Linux system does not use a file name, but with the inode number to identify files
for users, file inode number just another name for easy identification
inode number
(1), the system finds the inode number corresponding to the file name
(2), acquired from an inode number inode information
(3), from the inode information, find the file where the data block, reading data
inode size
inode will consume hard disk space, each inode size, typically 128 bytes or 256 bytes is
determined when the total number of inode file system is formatted
using df-i can see the total number and inode number of each hard disk partitions have been used

Practice
1, we enter the opt in create an empty directory mkdir abc, abc input touch aaa.txt then create an empty directory in the file, you can view the -i inode number of files through LS
Understanding the Linux file system (a)
2, also stat aaa.txt View details
Understanding the Linux file system (a)
3, the aaa.txt create a link to a file, enter ln aaa.txt a01.txt, then enter ls -i inode number can see the same view, but the names are the same.
Understanding the Linux file system (a)
3, we can see the input stat aaa.txt aaa.txt hard link has two.
Understanding the Linux file system (a)
4, with a file aaa.txt can view the text type.
Understanding the Linux file system (a)
5, can also be viewed with a text type ls -i (d is the beginning of a directory).
Understanding the Linux file system (a)
6, inode node can be viewed using df -i.
Understanding the Linux file system (a)

Hard links and soft links

There are links to files in Linux following two types, one similar to the Windows shortcut files can be quickly connected to the target file or directory; the other is a new file by inode link to the file system generated name, instead of generating The new document, which is called a hard link.
1, hard links
under normal circumstances, the file name and inode number is one to one relationship, each indoe number corresponds to a file name.

Due to consistent hard links and metadata source file (that is, the same piece of metadata), so it has a series of characteristics.

1, can not cross-file system;

2, and iNode the same data block;

3, only hard link to an existing file created;

4, can not be for the directory file creation, Linux file system designed to create two hard links to directories default .. if we support directory create a hard link, then will generate a directory ring may cause a deadlock (author of one of the words).;

5,删除文件时,必须删除所有的硬链接才能真正释放data block.
软链接
软链接就是再创建一个独立的文件,而这个文件会让数据的读取指向它连接的那个文件的文件名。
1、 软连接有自己的元数据,所以可以对其进行权限控制(作用于原文件)

2、 可跨越文件系统(包括网络)创建软连接

3、可对不存在的文件和目录创建(打破不能链接目录的限制)

4、 创建软连接,源文件链接数不增加

5、 删除软连接时不影响源文件

恢复误删除的文件

我们删除一个文件,实际上并不清楚inode节点和block的数据,只是在这个文件的父目录里面的block文件,删除这个文件的名字。Linux是通过Link的数量来控制文件删除,只有当一个文件不存在任何Link的时候,这个文件才会被删除。
·
1、需要使用在开始操作之前我们需要安装实验所需要的软件包,我们的光驱挂载在/mnt/里,开始安装所需要的软件,
Understanding the Linux file system (a)

在安装第二个包之前要安装libcom。
Understanding the Linux file system (a)
2、现在要把工具包进行编译安装,在编译之前输入smbclient -L //192.168.10.10/
看看共享出来的文件名是什么。
Understanding the Linux file system (a)
3、知道文件名之后就开始进行编译安装
创建mkdir /aaa,输入mount.cifs //192.168.10.10./CAA/aaa ,就可以看到/aaa里就有里extundelete这个包
Understanding the Linux file system (a)

4、对这个压缩包进行解压输入tar jxvf extundelete-0.2.4.tar.bz2 -C /opt/
Understanding the Linux file system (a)
5、进入Understanding the Linux file system (a)extundelete-0.2.4./中,可以看到configure。
Understanding the Linux file system (a)
6、配置之前要安装环境,输入yum install gcc gcc-c++ -y。
Understanding the Linux file system (a)
7、./configure 直接进行执行。
Understanding the Linux file system (a)
8、输入make install 进行安装。
Understanding the Linux file system (a)
9、接下来将添加的磁盘进行分区和格式化。
Understanding the Linux file system (a)
Understanding the Linux file system (a)
10、进行挂载,mkdir /data 输入mount /dev/sdb1 /data,然后进入data里查看。
Understanding the Linux file system (a)
11、在data里写入三个文件。
Understanding the Linux file system (a)
12、模拟删除文件,rm -rf b,b的文件就被删除了
Understanding the Linux file system (a)
13、这时候我们就可以恢复了,在这之前要先解挂载。
Understanding the Linux file system (a)
14、接下来输入extundelete /dev/sdb1 --restore all,来恢复删除的所有文件,如果误删了文件之后,要立马将设备解挂载,要不然新的文件将你的inode号占用就无法恢复了。
Understanding the Linux file system (a)
15、输入cd RECOVERD_FILES/就可以看到恢复的文件。
Understanding the Linux file system (a)

恢复LINUX中XFS类型的文件

xfsdump command
Format: -f xfsdump path to the backup storage location of the backup file device or
common options:
-f: Specifies the location of the backup file
-L: Specifies the session tag (Free interaction)
-M: Specifies the device label (Free interaction)
-s: backup file specified
xfsrestore command
format: xfsrestore -f restore files stored position to restore the file location
-f: Specifies the backup file location
-s: Specifies the file recovery restore
-t: view the contents of files and details
1, first add a disk, and then configure it formatted as xfs format, then mount to the new directory / data inside.
Understanding the Linux file system (a)
2. Copy the passwd file into the "/ data /" directory, and then in the "/ data /" directory Create a "test" directory, and create an empty file in the directory.
Understanding the Linux file system (a)
3, return to the data directory, and then back up in the partition sdb1 to / opt / Lane, named "xfs_dump".
Understanding the Linux file system (a)
4, delete the / data / content in the analog deleted.
Understanding the Linux file system (a)
5, after deleting finished and now we begin to recover.
Understanding the Linux file system (a)
6, to see if you enter ls / data / file recovery back in.
Understanding the Linux file system (a)
xfsdump use restrictions:

1, only the file system backup a mounted
2, you must use root privileges to operate
3, only backup XFS file system
4, data backup can only be resolved so that xfsrestore
5, can not back up two files with the same UUID system

Guess you like

Origin blog.51cto.com/14307755/2434544