Disk parameter revision for linux missing and missing detection
Linux disk parameter Revision
Archive representative Device
In linux, we all know that we can use corresponding files to represent a device. For example,/dev/sdb1 represents the first separator slot of the sdb hard disk. The device uses major and minor to indicate the device to be replaced.
Brw-rw -- 1 root disk 8, 0 May 12 20:16/dev/sda
Brw-rw -- 1 root disk 8, May 12 19:48/dev/sda1
Brw-rw -- 1 root disk 8, 10 October 19:48/dev/sda10
Brw-rw -- 1 root disk 8, 11 Aug 17 19:48/dev/sda11
Brw-rw -- 1 root disk 8, 12 May 12 19:48/dev/sda12
Brw-rw -- 1 root disk 8, 13 Aug 17 19:48/dev/sda13
Brw-rw -- 1 root disk 8, 2 May 12 19:48/dev/sda2
Brw-rw -- 1 root disk 8, 3 Aug 17 19:48/dev/sda3
Brw-rw -- 1 root disk 8, 4 May 12 19:48/dev/sda4
Brw-rw -- 1 root disk 8, May 12 19:48/dev/sda5
Brw-rw -- 1 root disk 8, 6 May 12 19:48/dev/sda6
Brw-rw -- 1 root disk 8, May 12 19:48/dev/sda7
Brw-rw -- 1 root disk 8, 8 Aug 17 19:48/dev/sda8
Brw-rw -- 1 root disk 8, 9 May 12 19:48/dev/sda9
Root @ qeesung-laptop:/media # ll/dev/sdb *
Brw-rw -- 1 root disk 8, 16 May 12 20:16/dev/sdb
Brw-rw -- 1 root disk 8, 17 Aug 17 20:25/dev/sdb1
Brw-rw -- 1 root disk 8, May 12 20:18/dev/sdb2
The Linux kernel identifies the corresponding device through the corresponding major and minor.
Device name |
Major |
Minor |
/Dev/sdb |
8 |
0-15 |
/Dev/sdba |
8 |
16-31 |
Mknod command
This command is mainly used to create a device file (make block or character special files)
Mknod [OPTION]... name type [major minor]
The main types are:
-B block Device
-C char character device
-P pipe Equipment
Example:
Create an MPS queue File
# Mknod pipeFile p
# Echo this is a test line> pipeFile
# Cat pipeFile
Create a block File
# Mknod blockFile B 8 100
Create a character file
# Mknod charFile c 4 100
There will eventually be three files
Brw-r-1 root 8,100 May 12 21:15 blockFile
Crw-r-1 root 4,100 May 12 21:16 charFile
Prw-r-1 root 0 May 12 21:12 pipeFile |
E2label command
In linux, a corresponding label can be specified for each separator slot to indicate the separator slot, which is like a C drive D Drive in windows. If a label is specified for the disk's separator slot, it will be mounted under the/media Directory according to the label name. If no label is specified, the UUID of the split slot will be mounted under the/media directory.
In linux, you can run the e2label command to specify the label of the corresponding separator. The advantage of specifying a label is that the label will not change with the change of the disk file name, we know that the disk mounting order in linux determines the disk file name. For example, if you first Mount SATA disk 1, the device name of Disk 1 is/dev/sda, if you try to mount Disk 1 after attaching SATA disk 2, the disk file of Disk 1 is/dev/sdb... However, even if the disk file name is changed, the corresponding separator label will not change.
Run the e2label command:
E2label/dev/sdb1 "newLabelName"
Tune2fs command
The tune2fs command is very useful. The following are some basic usage instructions:
--L is equivalent to displaying the superBlock content of the troughs of dumpe2fs-h.
--L is equivalent to e2label changing the label of a separator
--J: Convert the ext2 file format to the ext3 file format with logs
For more details, just use man.
Automatic mounting of the file system
We can change the data in/etc/fstab to change the file system that is automatically mounted to the system every time the system is started. The following are the items in the/etc/fstab/file:
In this example, the file system is mounted under the/home directory, and no line of information indicates the file system automatically mounted upon startup. each item is distinguished by space. The specific meaning of each item is:
-File system: Corresponding separator slot, which is UUID or label name
-Mount point: Mount point. It must be a directory, and the root directory/must take precedence over all file systems.
-Type: File System Type
-Options <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3Ryb25nPqO6zsS8/s + 5E + DQo8dGFibGU + DQo8dGhlYWQ + DQoJPHRyPg0KCTx0aCBhbGlnbj0 = "center"> arg1Arg2DescriptionUserNouserCan a common user mount a file system?AsyncSyncWhether the disk is read and written AsynchronouslyAutoNoautoWhether it can be automatically mounted is mount-.RwRoWhether the file system is read-only or read/writeSuidNosuidWhether suid/sgid files and directories are supportedUlts Default Configuration Mode
-Dump: Indicates whether to perform dump backup on the file system: 0 indicates no backup, 1 indicates daily backup, 2 indicates irregular backup
-Pass: Use fsck to check whether the file system is faulty. 0 indicates no detection. 1 indicates the first check (usually the root directory). 2 indicates that the check is required. It is only detected after 1!
Now suppose we need to mount the file system/dev/sdb1 to the/media/sdb1 directory in read-only mode when it is started, then we need to write data under/etc/fstab;
/Dev/sdb1/media/sdb1 ext4 ro 1 2
Next, let's try mount-a and find that the file system is automatically mounted to the/media/sdb1 directory in read-only mode, indicating that we have not written an error.
Note: If you do not check whether the entries in the newly added fstab are correctly written and restarted in a rush, you may fail to start the device and enter the single-user mode, in this case, you need to mount-n = o remount. rw/Remount the root directory, and then modify the/etc/fstab file.
Mount-o loop
The mount-o loop option is used to mount a file to the system directory as a hard disk partition, especially when our partition is unreasonable. For example, the partition in your root directory is very large, the partition size is almost full. Now you can resume a large file and use it as a new device on the system. Now you have an additional partition, however, this partition is only virtual. There is no corresponding partition slot on the disk to divide this partition.
Let's take a look at the actual application:
# Create a new directory cd/tmp & mkdir hello & cd hello # copy 512 1 m data blocks to dd in file1 from the beginning of the/dev/zero File System if =/dev/zero of =. /file1 bs = 1 M count = 512ll-h file1 # We Get-rw-r -- 1 root 512 M May 13 23:49 file1 new mount point mkdir file1MountPoint # Now let's try mount file1 to file1MountPointmount-o loop file1. /file1MountPoint # mount error detected: You must specify the file system type. Therefore, the format of this file is mkfs-t ext4. /file1 # Try mounting again and find that the mounting is successful, because all the content in the file is 0 at the beginning, and the sub-user cannot mount a file that is all 0, we need to format this file for mounting, that is, to create a superBlock inodetable blockTable in the disk area where the file is located. When mounting the file, it will be read and mounted.
We copied MB of content from a device called/dev/zero to the file, now let's try to copy all the file systems/dev/sdb1 with a capacity of MB into a new file file2 and see how to mount it again.
# View the Mounted Directories df-l | greo/dev/sdb1 # We get the corresponding Mount directory/dev/sdb1 99150 5647 88383/media/sdb1 # We enter/media /sdb1 check cd/media/sdb1 & ls; cd/tmp/hello # The following three files are found: lost + found newfile newFiledd if =/dev/sdb1 of =. /file2 bs = 1 M count = 512 & mkdir file2MountPoint # Get the file file2. Our file2 size is only 100 M, here we copied all the items in/dev/sdb1, and mounted the file without formatting. /file2. /file2MountPoint # No error reported, but it succeeded. Go to the file system and check the cd file2MountPoint & ls #. Three files are found in the file lost + found newfile newFile.
The above file file2 is the content of the entire disk in/dev/sdb1, so the content in file2 is the complete file system content, that is to say, the file data in file2 is all the data in the/dev/sdb1 file system, including superBlock, inodeTable, blockTable, and so on, so we can directly mount this file, in fact, full backup of the file system can also be achieved here
Create a swap Partition
The main function of swap partitioning is to move the programs in memory to swap when the physical memory is insufficient, so that the physical memory can be used by the required program.
We can create a swap file system.
Fdisk/deb/sdbn + 2Gt682 # change the File System id mkswap/dev/sdb6swapon/dev/sdb6
The above is to re-create a swap partition with a hard disk partition.
The following uses a file to create a swap partition.
dd if=/dev/zero of=./newSwapFile bs=1M count=500Mmkswap ./newSwapFileswapon ./newSwapFile
We can use swapon-s to check which swap is currently mounted and used.
Swapoff can also be used to remove a swap partition in the system.
You can use the free command to view the swap usage in the system (total amount, usage, and remaining conditions)
system ID
In linux, each file system has a corresponding id.
-Linux ext4 --> system id = 83
-Linux swap --> system id = 82
-Windows ntfs --> system id = 7
Total directory usage
When we execute the ll-l command under a directory, the top of the output will show such words with a total usage of 512032,
The total usage here is similar to the total usage of the du-s command. In fact, the total usage here is the number of blocks occupied by files in the directory * block size
To split a large hard disk, use the command parted.