Linux 4-disk and file system management and linux Disk System Management
1. Some basic definitions
1. superblock: record the overall information of this filesystem, including the total inode/block volume, usage, remaining amount, and file system format and related information;
2. inode: records the attributes of an archive. An archive occupies one inode and records the block number of the archive data;
3. block: Actually records the file content. If the file is too large, multiple blocks will be occupied.
Ii. file systems supported by Linux
1. Check what file systems are supported by Linux:
Ls-l/lib/modules/$ (uname-r)/kernel/fs
2. view the file systems that are currently loaded into the memory:
Cat/proc/filesystems
Linux VFS (Virtual Filesystem Switch) helps us manage how to access different file systems
Iii. Ext2 FILE SYSTEM INTRODUCTION
1. block features
1) The block size and quantity cannot be changed after being formatted (unless re-formatted), generally 1 K, 2 K, or 4 K, the size determines the maximum size of a single file and the total size of the file system;
Block Size: 1KB, 2KB, 4KB
Maximum size of a single file: 16 GB 256 GB 2 TB
Max total file system capacity 2 TB 8 TB 16 TB
2) each block can only store the data of one file;
3) if the file size is greater than the block size, one file will occupy multiple blocks;
4) if the file size is smaller than the block size, the remaining capacity of the block will no longer be used (disk space will be wasted ).
2. inode features
1) The size of each inode is fixed to 128 bytes;
2) each file occupies only one inode;
3) the number of files that can be created by the file system is related to the number of inode;
4) when the system reads the file, it must first find the inode and analyze whether the permissions recorded by the inode match the user. If yes, the system can start to read the block content.
5) The inode record block number is defined as 12 Direct, one indirect, one double indirect, and three indirect record areas.
Iv. File System Operations
1. df: list the total disk usage of the file system
Df [-ahikHTm] [directory or file name]
Options and parameters:
-A: List all file systems, including system-specific/proc and other file systems;
-K: displays each file system based on the capacity of KBytes;
-M: displays file systems with the capacity of MBytes;
-H: display data in easy-to-read formats such as GBytes, MBytes, and KBytes;
-H: Replace the carry mode of M = 1000 K with M = 1024 K;
-T: the filesystem name (for example, ext3) of the partition is also listed;
-I: displays the inode quantity instead of hard disk capacity.
2. du: Evaluate the disk usage of the file system
Du [-ahskm] file or directory name
Options and parameters:
-A: lists all files and directory capacities, because only the files under the directory are counted by default.
-H: displayed in a readable capacity format (G/M;
-S: only list the total amount, rather than the capacity occupied by each directory;
-S: Does not include the total number of subdirectories. By default, du lists the sizes of all files. Therefore, if you use du under/etc, the sub-directory capacity under/etc will also be calculated once. Then, the final Capacity (/etc) will be added once. Therefore, if you want to list all the data in a directory, you can add the-S option to the partition, reduce the number of times the directory is added!
-K: displays the capacity in KBytes;
-M: displays the capacity in MBytes;
3. ln create a file link
Ln [-sf]
Options and parameters:
-S: If no parameter is added, the link is hard link, and-s is symbolic link.
-F: if the target file exists, you can manually remove it and create it again!
When creating a directory, the number of links is generally 2, while the number of links in the upper directory increases by 1. For example,/tmp/test has/tmp/test and/tmp/test /. link/tmp/test /..
4. fdisk disk partition (parted is used for partitioning 2 TB or more)
Fdisk-l view the current disk partition information
Fdisk: Enter the disk partition management system
5. Format The mkfs Disk
Mkfs [-t File System Format] Device File Name
Options and parameters:
-T: It can be connected to the file system format, such as ext3, ext2, and vfat. (It takes effect only when supported by the system)
6. More detailed disk formatting for mke2fs
Options and parameters:
-B: You can set the size of each block. Currently, 1024,204 8 and 4096 bytes are supported;
-I: inode size
-C: Check for disk errors. If-c is issued only once, a quick read/write test is performed. If-c is issued twice, the read/write test is performed ), will be slow ~
-L: the header name (Label) can be followed)
-J: mke2fs is EXT2. After-j is added, it is added to journal and becomes EXT3.
7. fsck to check whether the file system has an error
8. badblocks check whether there is any bad track in the hard disk or floppy disk sector
9. mount, unmount disk mounting and dismounting
Note:
1) A single file system should not be repeatedly mounted to different mount points (directories;
2) multiple file systems should not be mounted in a single directory;
3) the directory to be used as the mount point should theoretically be empty directories. If it is not empty, the original file will be hidden after mounting.
10. mknod: Modify information about the file system, such as the main device code and secondary device code.
11. e2label Modify file system Header
12. Change the file system to ext2, ext3, and ext4 in tune2fs.
13. Some parameters are set when hdparm is used as the IDE interface.
14. mkswap can be used to create a large file as a swap file, and swapon and swapoff can be used to enable or disable swap file to implement virtual memory.
TIPS: You can use dd if =/dev/zero of =/tmp/swap bs = 1 M count = 128 to create a large file.