1. View Hard Disk Related#
df -l Command to View Hard Disk#
-
The system disk is like the C drive in Windows. In Linux, it generally has the participation of "a". You can use the command df -l to view it.
You can see that the root path "/" is located on the system disk. And /root, /home, /usr are like directories such as c:\windows and c:\usr under the C drive. -
If there is a separate data disk and the data disk is not partitioned and mounted, it cannot be seen using the df -l command.
fdisk -l Command to View Hard Disk#
Using the fdisk -l command, you can see which hard disks are available.
Disk /dev/vda and Disk /dev/vdb represent two disks.
/dev/vda - System disk (built-in disk), with one partition vda1 (usually the first disk is the system disk)
/dev/vdb - Data disk (generally virtual disk), with two partitions vdb1, vdb2
lsblk Command to View Hard Disk#
In the image, sda is the system disk, and sdb is the mounted data disk.
du -h Command to Query Disk Usage of a Specific Directory#
Command: du [options] /directory (Query the disk usage of a specific directory, default is the current directory)
Options Meaning
-s Summarize the sizes of specified directories
-h Human-readable format
-a Include files
--max-depth=1 Depth of subdirectories
-c Include a grand total
Options can be used in combination.
Example: Query the disk usage of the /opt directory with a depth of 1.
2. Hard Disk Mounting Related#
- Use the lsblk command to check if there is sdb.
- Virtual machine hard disk partition
fdisk /dev/sdb Partition Command#
Start partitioning sdb
m Display command list
p Display disk partition same as fdisk -l
n New partition
d Delete partition
w Write and exit
Explanation: After starting the partition, enter n to create a new partition, then select p for the partition type as primary partition. Press Enter twice to use the remaining space by default, and finally enter w to write the partition and exit. If you don't want to save and exit, enter q.
mkfs -t ext4 /dev/sdb1 Partition Formatting Command#
mount Mounting Command#
For example, mount the disk to the newdisk directory under the root directory.
Mounting through the command line (mount /dev...), it will be invalid after restarting, meaning the mount point will disappear after restarting.
Modify /etc/fstab to Achieve Permanent Mounting#
[root@kongchao03 /]# vim /etc/fstab
[root@kongchao03 /]# mount -a
After adding, execute mount -a or reboot to take effect.