教下我&叫下我

教下我&叫下我

我不会,教下我 有福利,叫下我 致终身学习者! https://jiaoxiawo.com
tg_channel
twitter

Commonly used commands for Linux hard disk operations.

df -l Command to View Hard Disk#

  1. 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.
    image
    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.

  2. 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.
image

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.
image

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.
image

  1. Use the lsblk command to check if there is sdb.
    image
  2. 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.

image

mkfs -t ext4 /dev/sdb1 Partition Formatting Command#

image

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.
image

Modify /etc/fstab to Achieve Permanent Mounting#

[root@kongchao03 /]# vim /etc/fstab 
[root@kongchao03 /]# mount -a

image
After adding, execute mount -a or reboot to take effect.

umount Unmounting Command#

image

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.