How to mount disk in Linux system

#Mount disk

lsblk View storage information

fdisk /dev/vdb m---n---p---p---w

#Mount to data after formatting

mkfs.ext4 /dev/vdb1

mkdir /data

mount /dev/vdb1 /data

echo "/dev/vdb1 /data ext4 defaults 0 0" >>/etc/fstab df -h

1. `lsblk`: This command will list all block devices (block devices), that is, disks and disk partitions. It can help you find the device ID of your data disk.

2. `fdisk /dev/vdb`: This command will open a program used to operate disk partitions. `/dev/vdb` is the device identifier of your data disk. In this program, you can use various commands to operate.

   - `m`: Show all available commands.
   
   - `n`: Create a new partition.
   
   - `p`: Print the partition table, that is, display all partitions.
   
   - `w`: Save changes and exit.

3. `mkfs.ext4 /dev/vdb1`: This command will format the first partition of your data disk (`/dev/vdb1`) using the ext4 file system.

4. `mkdir /data`: This command will create a new directory `/data`, which will be used as the mount point of the data disk.

5. `mount /dev/vdb1 /data`: This command will mount the first partition of your data disk (`/dev/vdb1`) to the `/data` directory.

6. `echo "/dev/vdb1 /data ext4 defaults 0 0" >> /etc/fstab`: This command will add a line to the end of the `/etc/fstab` file. This file is used to control which devices will be automatically mounted when the system starts. The meaning of this line is that every time the system starts, `/dev/vdb1` will be mounted to the `/data` directory. The file system type is ext4, the mount option is defaults, the dump backup is set to 0, and fsck checks The priority is 0.

7. `df -h`: This command will display the disk usage of all mounted file systems. The `-h` option will display the size in human readable form, such as KB, MB, GB, etc.

8. `lsblk`: Run the `lsblk` command again to verify that your data disk has been successfully mounted to the `/data` directory.

This is a detailed explanation of each step. If you have any other questions, please feel free to continue asking.

Guess you like

Origin blog.csdn.net/u013933709/article/details/131615287
Recommended