1. Viewing disk-related information#
df -l command to view disk#
-
The system disk is like the C drive in Windows. In Linux, it usually has a partition called "a". You can use 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 under the C drive, such as c:\windows, c:\usr. -
If there is a separate data disk and the data disk is not partitioned or mounted, you cannot see it using the df -l command.
fdisk -l command to view disk#
Using fdisk -l, you can see which disks are available.
Disk /dev/vda and Disk /dev/vdb represent two disks.
/dev/vda - System disk (built-in disk), with a partition vda1 (usually the first disk is the system disk)
/dev/vdb - Data disk (usually a virtual disk), with two partitions vdb1, vdb2
lsblk command to view disk#
In the image, sda is the system disk, and sdb is the mounted data disk.
du -h command to check disk usage of a specific directory#
Command: du [options] /directory (check the disk usage of a specific directory, default is the current directory)
Options Meaning
-s Summarize the sizes of directories
-h Human-readable format
-a Include files
--max-depth=1 Depth of subdirectories
-c List the details and add a total value
Options can be used in combination
Example: Check the disk usage of the /opt directory, with a depth of 1
2. Disk mounting related#
- Use the lsblk command to check if there is sdb
- Virtual machine disk partition
fdisk /dev/sdb partition command#
Start partitioning sdb
m Display command list
p Display disk partition same as fdisk -l
n Create a new partition
d Delete a partition
w Write and exit
Note: 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 command for mounting#
For example, mount the disk to the newdisk directory under the root directory
Mounting via command line (mount /dev...), it will be ineffective 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