Article directory
1. Linux partition
●Principle introduction
- As far as Linux is concerned, no matter how many partitions it has and which directory it is assigned to, it ultimately has only one root directory, an independent and unique file structure. Each partition in Linux is used to form part of the entire file system.
- Linux uses a processing method called "loading". Its entire file system contains a complete set of files and directories, and associates a partition with a directory. A partition to be loaded at this time will have its storage space obtained in a directory.
- Schematic diagram
●Hard disk description
- Linux hard disks are divided into IDE hard disks and SCSI hard disks. Currently, they are basically SCSI hard disks.
- For IDE hard disks, the drive identifier is "hdx~", where "hd" indicates the type of device where the partition is located, here it refers to the IDE hard disk. "X" is the disk number (a is the basic disk, b is the basic slave disk, c is the auxiliary master disk, d is the auxiliary slave disk), "~" represents the partition, and the first four partitions are represented by numbers 1 to 4. They are The primary partition or extended partition is a logical partition starting from 5. For example, hda3 is represented as the third primary partition or extended partition on the first IDE hard disk, and hdb2 is represented as the second primary partition or extended partition on the second IDE hard disk.
- For SCSI hard disks, they are marked as "sdx~". SCSI hard disks use "sd" to indicate the type of device where the partition is located, and the rest are the same as IDE hard disks.
Check the mounting status of all devices
Command: Isblk or Isblk -f
Classic case of mounting
· Explanation:
Let's take adding a hard disk as an example to familiarize ourselves with the relevant instructions of the disk and deeply understand the concepts of disk partitioning, mounting, and unmounting.
How to add a hard disk
1. Add a hard disk to the virtual machine
2. Partition
3. Format
4. Mount
5. Set up automatic mounting
Step 1 to add a hard disk to a virtual machine:
In the [Virtual Machine] menu, select [Settings], then add the hard disk to the device list, and then go to [Next]. Only the selected disk size needs to be modified in the middle, until it is completed. Then restart the system (to recognize it)!
Step 2
partition command to add a hard disk to the virtual machine fdisk /dev/sdb
starts partitioning /sdb
m displays the command list
p displays the disk partition the same as fdisk -l
n adds a partition
d deletes the partition
w writes and exits
Note: After starting the partition, enter n, add a new partition, and then select p, the partition type is the main partition. Pressing Enter twice defaults to all remaining space. Finally, enter w to write to the partition and exit. If you do not want to save, enter q to exit.
Step 3 of adding a hard disk to a virtual machine
Format the disk
Partition command: mkfs -t ext4 /dev/sdb1
where ext4 is the partition type.
Add a hard disk to the virtual machine. Step 4
Mount: Associate a partition with a directory.
Mount device name to mount directory .
For example: mount /dev/sdb1 /newdisk
umount device name or mount directory
. For example: umount /dev/sdb1
Or umount /newdisk
note: use Command line mount will become invalid after restarting
Step 5 of adding a hard disk to a virtual machine
: Permanent mounting: /etc/fstab
Mounting is achieved through modification
. After the addition is completed, the execution will take mount -a
effect immediately.
2. Disk status query
Query the overall disk usage of the system
basic grammar
df -h
Applications
Query the overall disk usage of the system.
Query the disk usage of the specified directory.
Basic syntax
du -h /directory.
Query the disk usage of the specified directory. The default is the current directory -s.
Specify directory usage summary
-h with measurement unit
-a with file
–max. -depth=1 Subdirectory depth
-c adds summary value while listing details
Application example
Query /opt self-recorded disk usage, depth is 1
Disk situation - practical instructions for work
1. Count the number of files in the /opt folder
ls -l /opt | grep "^-" | wc -l
2. Count the number of directories under the /opt folder
ls -l /opt | grep "^d" | wc -l
3. Count the number of files in the /opt folder, including those in subfolders
ls -lR /opt | grep "^-" | wc -l
4. Count the number of directories under the /opt folder, including those in subfolders
ls -lR /opt | grep "^d" | wc -l
5. Display the directory structure in tree form. Note that if there is no tree, use yum install tree
installation