I like the Linux File System very much. Next I will discuss in detail how to delete the Linux File System. Linux is a complete software package consisting of development tool software, editor software, CPU graphical user interface, and network tool software. Linux has all the features of a modern, fully functional UNIX system.
As a multi-user, multi-task operating system, once a Linux File System is deleted, it is hard to restore. Although the DELETE command only marks the deletion in the file node and does not actually clear the file content, other users and some processes with disk write operations will soon overwrite the data. However, you can recover a Linux File System that is used by a single machine in your home, or rectify the file by mistake.
A Brief Introduction to the Ext2 File System Structure
In the Ext2 file system used by the Linux File System, files are stored in blocks. By default, the size of each block is 1 K. Different blocks are distinguished by block numbers. Each file has a node that contains information such as the file owner, read/write permission, and file type. For a file smaller than 12 blocks, the block number of the file data block is directly stored in the node. If the file contains more than 12 blocks, the node stores the block number of an indirect block after the 12 blocks. In the block corresponding to this indirect block number, each block number in the block number Ext2fs that stores 256 file data blocks occupies 4 bytes, so that the block number that can be stored in a block is 1024/4 = 256 ). If a larger file exists, the second-level indirect block and third-level indirect block appear in the node.
Restore deleted objects by mistake
Most Linux File System distributions provide a debugfs tool for editing Ext2 file systems. However, there is still some work to do before using this tool. First, Remount the partition where the accidentally deleted file is located in read-only mode. Run the following command: Suppose the file is in the/usr partition.) mount-r-n-o remount/usr-r indicates read-only mounting;-n indicates no write to/etc/mtab, add this parameter to restore files on/etc. If the system says xxx partion busy, you can run the fuser command to check which processes use the files in this partition:
If there are no important processes, run the following command to stop them:
Then you can re-mount these Linux file systems.
If all the files are installed in a large partition, you can use linux single to enter the single-user mode at the boot prompt to minimize the chance of system processes writing data to the hard disk, or simply mount the hard disk on another machine. In addition, do not write the recovered data to/to avoid damaging the useful data. If the host has dos/windows, you can write it to these partitions:
Then you can execute debugfs: Suppose Linux is in/dev/hda5)
The prompt debugfs appears:
The lsdel command can be used to list the information of many deleted files:
Debugfs: 2692 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
164821 0 100600 8192 1/1 Sun May 13 19:22:46 2001
36137 0 100644 4 1/1 Tue Apr 24 10:11:15 2001
196829 0 100644 149500 38/38 Mon May 27 13:52:04 2001
The first field is the file node number, the second field is the file owner, the third field is the read and write permissions, and the next is the file size, number of blocks, and deletion time. Then we can determine what we need based on the file size and deletion date. For example, we want to restore a file with a node of 196829:
You can first check the file data status:
Inode: 196829 Type: regular Mode: 0644 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 149500
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 38
Fragment: Address: 0 Number: 0 Size: 0
Ctime: 0x31a9a574 -- Mon May 27 13:52:04 2001
Atime: 0x31a21dd1 -- Tue May 21 20:47:29 2001
Mtime: 0x313bf4d7 -- Tue Mar 5 08:01:27 2001
Dtime: 0x31a9a574 -- Mon May 27 13:52:04 2001
594810 594811 594814 594815 594816 594817
Then you can use the dump command to restore the file:
In this way, the file is restored. Exit debugfs:
Another method is to manually edit inode:
User ID 
Group ID 
Creation time [0x31a9a574]
Modification time [0x31a9a574]
Access time [0x31a21dd1]
Deletion time [0x31a9a574] 0
Link count  1
Block count 
File flags [0x0]
File acl 
Directory acl 
Fragment address 
Fragment number 
Fragment size 
Direct Block #0 
Triple Indirect Block 
After the mi command is used, a line of information is displayed each time for editing. For other lines, press enter to confirm and change the deletion time to 0. The Link count value is changed to 1. After modification, exit debugfs:
Then use fsck to check/dev/hda5
The program will find the lost data block and put it in lost + found. The files in this directory are what we need.
Now all O. K. Good Luck.
Linux File System partition Solution
Hard Disk Partitions are composed of primary partitions, extended partitions, and logical partitions. Therefore, we must follow this standard for Hard Disk Partitions. the maximum number of primary partitions, including extended partitions, is four, determined by the number of Hard Disk Master Boot records (MBRMaster Boot Recorder), MBR stores startup management programs (GRUB, LILO, NTLOARDER, etc.) and Partition Table records. The extended partition is also a primary partition. The extended partition can contain more logical partitions. Therefore, the range of the primary partition including the extended partition is from 1 to 4, logical partitions start from 5;
For a partition of a disk, a disk should have four primary partitions, And the expansion is also regarded as one primary partition. The following allocation scheme exists:
1) partition structure: four primary partitions without extended partitions; [primary | partition 1] [primary | partition 2] [primary | partition 3] [primary | partition 4, if you want to divide more than five partitions on one disk, this will not work; three primary partitions and one extended partition; [Master | partition 1] [Master | partition 2] [Master | partition 3] [extended partition] [logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8] This situation works, in addition, the degree of freedom of the partition is relatively large, and the partition is not restricted and can be divided into more than five partitions. This is just an example;
2) The most reasonable partitioning method;
The most reasonable partition structure: the primary partition is in the front, the extended partition is in the back, and then the logical partition is divided in the extended partition; the number of Primary partitions + the number of extended partitions should be controlled within four; for example, the following partition is better; [Master | partition 1] [Master | partition 2] [Master | partition 3] [extended partition] [logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]...
[Primary | partition 1] [primary | partition 2] [extended partition] [logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8] ......
[Master | partition 1] [extended partition] [logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8] ......
The most unreasonable partition structure: the primary partition is surrounded by extended partitions; for example, the following;
[Primary | partition 1] [primary | partition 2] [extended partition] [primary | partition 4] [Blank unpartitioned space] [logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8] ......
In this way, [extended partitions] between [primary | partition 2] and [primary | partition 4] have degrees of freedom, but what should I do if [blank and unpartitioned space] After [primary | partition 4? Unless primary partition 4 fully utilizes the space after the extended partition, it is impossible for you to create another partition after primary partition 4, making it impossible to divide logical partitions; although this method complies with the criteria of four primary partitions of a disk, the partitioning method of the primary partition surrounding the extended partition is not available;
Recommended partition Solution
Although Red Hat Linux can be installed in a single large partition, a better idea is to separate it. Considering the simplicity of a single partition and the flexibility of multiple partitions, we recommend the following Configuration:
Note: To install all the software packages of Red Hat Linux, you must use a large partition size. One swap partition-swap partitions are used to support virtual memory. Swap partitions are generally two times the memory size. A root partition-where the root partition is/(root directory. it only needs the files and system configuration files required to start the system. most system root partitions of 50 MB to MB can work well. one/usr partition --/usr is the place where many software in the Red Hat Linux File System is located. based on the number of packages you switch and install, the partition should be between MB and MB. if possible, use the maximum space for/usr partition. any RPM-based package you will install in the future will use more/usr space than other partitions.
A/home partition -- this is the location of the user's home directory; its size depends on the number of users in your Red Hat Linux File System and the amount of data these users will store.
[The following partition is only applicable to installation of Red Hat Linux/Alpha.
One MILO partition-Alpha users who use MILO to start the system need to create a mb dos partition. At the end of the installation, MILO can copy to this partition ..
In addition, the user environment may require the creation of one or more of the following partitions: One/usr/local partition-general, /usr/local is used to store software different from other Red Hat Linux file systems, such as software that is not an RPM package. the size of the software depends on the number of software to be stored. a/usr/src partition -- in Red Hat Linux File System,/usr/src usually stores two things:
Linux file system kernel source program-all the Linux kernel source programs are stored here, and the new kernel is also created here. Currently, the kernel source program is about 30 MB. Note: You may need more space to create the kernel or save several different versions of the kernel.
RPM package source program-if the package source program is installed, the file will be stored here. Note: Unless otherwise specified, the package will also be created using a 'create directory' here. here.
Similarly, the size of the partition depends on the number of software that will be installed here.
One/tmp partition -- just like its name,/tmp partition is used to store temporary files. It is a good idea to create a/tmp partition for a large, multi-user system or network server. For a single-user workstation, you do not have to create a/tmp partition.
A/var partition-the Red Hat Linux File System writes logs in/var/log. The print queue files are usually written in/var/spool. This is just two examples written in/var. Unless otherwise configured,/var will be part of the root Linux file system, usually not occupying a lot of space. If the system has many prints, emails, or logs, you can create a/var partition. Generally, only multiple users or servers need dedicated/var partitions.
One/boot partition -- most of the partitions mentioned here are for large systems. This partition is useful for systems with very little space. All the files required for starting LILO are in the/boot directory. These files (including Linux kernel) in/boot occupy 1 MB of space. If it is difficult to arrange MB space for the root partition used by LILO, only 5-10 MB can be used (usually not so much) to store/boot. Although you still need to create a root partition, It can be anywhere in the system-BIOS restrictions only apply to partitions with/boot.
Mounting in a Linux File System
In the process of using a Linux File System, a virtual File System (VFS) is often used to directly access other Linux file systems supported by the kernel through VFS, it is used like in a common Linux ext file system. Only the kernel needs to be re-compiled to support NTFS.
In a Linux File System, the mount command is used. You can use the man mount command to obtain detailed explanations of command parameters. The following describes how to mount a file system using the command line in several cases:
1. Add the FAT32 File System
Simplest usage: mount/dev/hda6/mnt/d
Among them,/dev/hda6 is the author's Windows d disk,/mnt/d is the directory mount point. The Linux file system recognizes the file system type of the/dev/hda6 partition, and then adds it to the Mount. Of course, you can also specify the file system type of the partition. The command is as follows:
In practice, a windows partition is directly attached, and the Chinese file name and directory name are garbled. To avoid this problem, you can specify a character set by running the following command:
Mount/dev/hda6/mnt/d-o codepage = 936, iocharset = cp936
Mount-t vfat/dev/hda6/mnt/d-o codepage = 936, iocharset = cp936
2. Mount the NTFS file system
In most Linux File System versions, you need to recompile the Linux core to mount the NTFS partition (see
). After the core supports NTFS, run the following command:
You can also specify the character set for garbled characters in Chinese file names and directory names. However, unlike the vfat partition, the following command is practical:
Mount-t ntfs-o iocharset = cp936/dev/hda2/mnt/c-r
Mount-t ntfs-o iocharset = cp936, rw/dev/hda2/mnt/c
3. mount a USB flash drive or a file system on a mobile hard disk
More and more people are using USB flash drives. In fact, using USB flash drives in Linux file systems is also very simple. Linux has good support for USB devices. After inserting a USB flash drive, the USB flash disk is recognized as a SCSI disk. You can use the following command to mount the file system on the USB flash disk.
You can specify a character set for garbled characters in Chinese file names and directory names. The command is similar to the one described in FAT32:
Mount/dev/sda1/usb-o pagecode = 936, iocharset = cp936
4. Add a directory shared by the Linux File System through samba.
The directory shared by samba is hard to tell which file system it was originally, but this is not important as long as it is transparent to users. When mounting, we specify the smbfs type. When mounting a samba shared partition, Chinese file names and directory names may also be garbled. You can run the following command to mount the file:
Username = terry, password = terry, codepage = 936, iocharset = cp936
Username = terry, password = terry, codepage = 936, iocharset = cp936
Note: you do not need to directly enter the password = terry parameter. In this way, you are required to enter the password in the system field to prevent anyone from seeing your password directly. Depending on the actual situation, the parameters following-o can be increased or decreased accordingly.
5. Add the directory shared by the Window system
In a LAN, you often need to access directories shared by other Windows systems. In a Linux file system, after samba is installed, you can use the commands in samba to access the shared resources of Windows machines.
Use smbclient to list shared resources of Windows machines
Based on the Windows Shared resources listed above, you can select the Windows Shared resources to be attached to the local Linux File System, and then use smbmount or mount to mount the shared resources, refer to the following commands:
Smbmount // 192.168.100.111/public/
Mount // 192.168.100.111/d/mnt/cdrom-o username = terry (enter the password on the command line)
Mount // 192.168.100.111/d/mnt/cdrom-o username = terry $1234 (you do not need to enter the password in the command line)
Note: In addition to the command line method described above, the best method is to use other clients, such as LinNeighborhood, networkneighbours, and ksmbshare. Refer to other articles.
The above is a command line method. You must enter the command once each time you use it. If you often need to mount some Linux File Systems, what should you do if you want to automatically mount them at startup? The following two methods are described:
Place the mounting command in/etc/rc. d/rc. local.
Modify the partition configuration file/etc/fstab and mount the Linux File System at startup. The following is my/etc/fstab file:
LABEL = // ext3defas1 S1 1
None/dev/pts devpts gid = 5, mode = 6200 0
LABEL =/home/homeext3defaults 1 2
None/procprocdefaults 0 0
None/dev/shm tmpfs defaults 0 0
/Dev/hda4 swap swapdefaults 0 0
Noauto, owner, kudzu, ro 0 0
/Dev/hda2/ntfs ults, iocharset = cp9360 0
/Dev/hda6/win vfat defaults, codepage = 936, iocharset = cp936 0 0
// 192.168.100.228/terry/mp3smbfsusername = terry, password = terry, codepage = cp936, iocharset = cp936 0 0
Note the last three lines:
The fourth to last line adds my C drive, NTFS format
In the last row, mount my d disk, in FAT32 format.
The second to the last line adds another Linux File System server installed with samba in my LAN.
- Introduction to Linux File System partitions
- Modularization of Linux File System Installation
- Getting started with Linux File System Types
- Linux File System categories
- Two Linux File System Performance testing tools