File system operations, partitioning, mounting, etc.

disk capacity df


List the overall disk usage of the file system, including usage, etc. Personal understanding is that all filesystems are mounted on the directory tree. When you dynamically mount a partition on a window, a new file system will be mounted.

 

Directory capacity du


Lists the information of directory files, -a means all files in the directory (including ordinary files and directory files), -s means the sum of the sizes of all directory files in the current directory, -S means all files in the current directory The respective directory file size of the directory

 

link file ln


 

Speaking of this concept, we must first distinguish between hard connections and soft connections. Let's see how the directory file manages its subordinate files. First of all, the directory file itself is a file. It is composed of inode and block. The inode stores the permissions of the directory and other information. The block stores its subordinate information, including the file name and corresponding information. file indoe. After understanding this concept, it is easy to understand hard links. To create a new hard link for a file is to add a file name and inode to the block in the new directory file you point to, so in theory, as long as the new directory file block size Enough, all the disk capacities have not changed, just one more pointer information has been written.

See this example, there is only target.txt in the file, so the block of the hardDir directory file has information pointing to target.txt, which is a hard link, only this link exists for target.txt, so see the link behind the permission information The number is 1. Next, I did an operation, -i just means to quickly generate a connection. We created a new hard link file pointing to target.txt. The change at this time is that there is one more piece of information in the block of the hardDir directory file. The file name is hardToTarget but The inode index value is the same as target.txt. So we see that the number of connections for this inode file has become 2. Seeing this, we realize that the name does not represent a file, only an inode can be said to be a file.

Next, let's talk about what a soft connection is. A soft connection creates a new file. We know that files have different types of formats, and the link file link is a separate file. So the connection file itself must be directed by the hardDir directory file. It stores the ten characters of "target.txt" itself, so its size is 10, it points to the file in this directory, and then finds the file through the file name it records.

Let's do an experiment to change the file name, the soft link is useless. The hard connection is still normal, because there is no data in it, so the effect is not seen.

 

Another important point is that the directory file inode cannot support hard links, because if a hard link is used to connect to a directory, the connected data needs to be connected to all data in the connected directory to establish a connection. Updating the data environment is quite complex. So the directory only supports soft links.

 

Disk partitioning, formatting, checking and mounting


The concept of disk partitioning should come from MBR and partition table. We said that the partition table is only 64B, with at most four primary partitions and at most one extended partition. An extended partition can have multiple logical partitions. This is because the partition table can only have four partitions, so there is an extended partition, so that the extended partition can contain multiple logical partitions for expansion management.

  • The fdisk -l command can see all the partitions of the device that can be found in the entire system. Remember that for example, if it is a sda disk device, the partition name will be sda1, sda2, etc., and so on. As shown in the figure below, we can see that there is only one hard disk Disk /dev/sda in the entire system, and then all the partitions under the hard disk. If you insert a USB disk or other data disk, other Disks will appear. The list includes the device name, start and end sector numbers, size, type, etc.

  • When we find the corresponding hard disk, use fdisk /dev/sda Note that numbers cannot be added after this time. At this point, we have entered the working interface of the fdisk program. We don't need to remember the instructions, because we can get the relevant management instructions by pressing m. For example, delete is d, create a new partition is n, etc., and then follow the prompts to operate. It is worth noting that pressing q means not to save and exit, and when you want to save, you can press w.

  • mkfs for formatting instructions, fsck for disk detection
  • Mounting needs to be mounted to a new directory file. It is best to unmount the corresponding mounted device first, because the directory tree is the backbone of the entire file system, in order to avoid errors.
  • The boot mount needs to be set in /etc/fstabl, as shown in the figure below, we can see that it is roughly composed of six, including the name of the disk, the mount point, the file system type, the file system parameters, and whether it can be used by the dump backup command. (0 or non-existence means no need), whether to use fsck to check the sector (1 means mandatory check at boot, 2 means other files are checked irregularly, 0 means no need to check), if this file is written incorrectly, it will not be able to boot, it must be to operate in single-user mode. Actually filesystem mounts are recorded in /etc/mtab and /proc/mounts.

  • Special device loop mount, what we call loop device file can be said to be a file system on the file system. For example, an image file iso is a file system. Mount it as a file on our directory, and read the file according to the file system. The system reads this file, which is the loop device file. Below we demonstrate mounting a loop file

  • Build swap space and mount it. Since there may be no free space partition on the disk, we can adopt the way of loop device construction. The process consists of constructing a file and then formatting it into a swap file format, starting it with swapon, and turning off the corresponding swap file with swaponff.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325247919&siteId=291194637