Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

In-depth understanding of Linux file system (1)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The inode and block overview file data, including meta-information and actual data files, are stored on the hard disk. The minimum storage unit of the hard disk is the "sector". Each sector stores 512 bytes. Block (block)

Translated into Chinese as "index node", also known as I node

Used to store file meta information

1. The content of inode

Inode contains a lot of file meta-information, but does not include file names, such as

Number of bytes in the file

The UserID owned by the file

GropuID of the file

Read, write and execute permissions of files

Timestamp of the file

The structure of the directory file

A directory is also a kind of file.

The structure of the directory file

Each inode has a number, and the operating system uses inode numbers to identify different files

File names are not used internally in the Linux system, but inode numbers are used to identify files

For users, files are just nicknames for inode numbers to be easily identified.

Inode number

(1) the system finds the inode number corresponding to the file name

(2) obtain inode information through inode number

(3) according to the inode information, find the block where the file data is located, and read the data.

The size of the inode

Inode also consumes hard disk space. The size of each inode is usually 128bytes or 256bytes.

Determine the total number of inode when formatting a file system

Use df-i to view the total number of inode and the number of hard disk partitions that have been used

Actual operation

1. We type mkdir abc in opt to create an empty directory, and enter touch aaa.txt to create an empty file in the abc directory. You can check the inode node number of the file through ls-I

2. You can also check the details on stat aaa.txt.

3, create the aaa.txt into a link file, enter ln aaa.txt a01.txt, and then enter ls-I to view the inode number can see the same, but the name is the same.

3. When we enter stat aaa.txt, we can see that there are 2 aaa.txt hard links.

4. You can view the text type with file aaa.txt.

5. You can also use ls-I to view the text type (the directory that begins with d).

6. Inode nodes can be viewed with df-I.

Hard link and soft link

There are two kinds of linked files under Linux, one is similar to the Windows shortcut file, which can quickly connect to the target file or directory, and the other is the new file name generated by the inode link of the file system, rather than the new file, which is called hard link.

1. Hard links

In general, there is an one-to-one correspondence between file name and inode number, and each indoe number corresponds to a file name.

Because the hard-linked metadata is exactly the same as that of the source file (that is, the same piece of metadata), it has a series of features.

1, cannot cross file system

2, with the same iNode and data block

3. Hard links can only create files that already exist

4. Cannot be created for directory files. The Linux file system creates two hard links to directories by default at design time. .. If you support the creation of hard links in directories, it will generate a directory ring that may cause deadlocks (according to the author)

5. When deleting a file, you must delete all hard links in order to really release data block.

Soft link

A soft link is to create a separate file that allows the reading of the data to point to the file name of the file to which it is connected.

1. The soft connection has its own metadata, so you can control its permissions (acting on the original file)

2. Soft connections can be created across file systems (including networks)

3. Files and directories that do not exist can be created (breaking the restriction that directories cannot be linked)

4. Create a soft connection without increasing the number of source file links

5. The source file is not affected when the soft connection is deleted

Restore mistakenly deleted files

We delete a file, actually do not know the inode node and block data, just the block file in the parent directory of the file, delete the name of the file. Linux controls file deletion through the number of Link, and only when a file does not have any Link will it be deleted.

1. Before starting the operation, we need to install the software package needed for the experiment. Our CD-ROM drive is mounted in / mnt/, and we begin to install the required software.

Install libcom before installing the second package.

2. Now to compile and install the toolkit, type smbclient-L / / 192.168.10.10 / before compilation

See what the shared file name is.

3. After knowing the file name, begin to compile and install

Create mkdir / aaa, type mount.cifs / / 192.168.10.10./CAA/aaa, and you can see the package extundelete in / aaa.

4. Decompress the compressed package and input tar jxvf extundelete-0.2.4.tar.bz2-C / opt/

5. Enter extundelete-0.2.4./ and you can see configure.

6. To install the environment before configuration, type yum install gcc gcc-c++-y.

7. / configure is executed directly.

8. Enter make install to install.

9. The next added disk is partitioned and formatted.

10. For mounting, type mkdir / data as mount / dev/sdb1 / data, and then enter data to check.

11. Write three files in data.

12. If the file is deleted by simulation, the file of rm-rf bjorb will be deleted.

13. We can restore it at this time, and we have to unmount it before that.

14. Then type extundelete / dev/sdb1-- restore all to restore all deleted files. If you delete the file by mistake, unmount the device immediately, otherwise the new file will not be able to recover your inode number.

15. Type cd RECOVERD_FILES/ and you can see the recovered files.

Restore files of type XFS in LINUX

Xfsdump command

Format: xfsdump-f backup location path or device file to be backed up

Common options:

-f: specify the backup file location

-L: specify a session label (interaction-free)

-M: specify device label (no interaction)

-s: back up specified files

Xfsrestore command

Format: location of xfsrestore-f recovery files, location of recovered files

-f: specify the backup file location

-s: restore specified files

-t: view the contents and details of the file

1. First add a disk, then configure it, format it into xfs format, and then mount it to the new directory / data.

2. Copy the passwd file to the "/ data/" directory, then create a new "test" directory in the "/ data/" directory, and create an empty file in the directory.

3. Return to the data directory, and then back up the partition in sdb1 to / opt/ and name it "xfs_dump".

4. Delete the content in / data/ and delete it by simulation.

5. After deletion, we now begin to restore.

6. Type ls to see if the files in your / data/ have been restored.

Xfsdump usage restrictions:

1. You can only back up mounted file systems

2. You must use the permission of root to operate.

3. Only XFS file system can be backed up.

4. The backed up data can only be parsed by xfsrestore

5. Cannot back up two file systems with the same UUID

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report