Operations related to Linux disks

Table of contents

1. View disk usage

2. View disk partitions and detailed information

3. Create partitions

4. Format the partition

5. Mount


1. View disk usage

df -h

2. View disk partitions and detailed information

fdisk -l

3. Create partitions

For example, to create a new primary partition

fdisk /dev/sdX   # 其中 X 是你的磁盘号,比如 'a', 'b', 'c' 等
# 接着按照提示使用 'n' 命令创建新分区
# 使用 'w' 保存并退出
# 使用p命令查看当前分区表,找到你要扩展的主分区。
# 使用d命令删除该分区。
# 出现{k,M,G}后输入:+10G 表示第主分区的大小为10G

4. Format the partition

Replace sdXY with the partition number you want to format, such as 'sda1', 'sdb2', etc.

mkfs.ext4 /dev/sdXY  

5. Mount

When inserting an external storage device (such as a USB flash drive or hard disk) in a Linux system or wishing to mount other file systems, we can use the mount command to connect these devices or file systems to directories in the file system so that they are in the specified directory Accessible below.

(1) Use the following command to view the list of mounted devices and confirm the device file name of the U disk. Usually, the device file name of the U disk starts with /dev/sd , followed by a letter, such as sda , sdb, etc., and a number, such as sda1 , sdb1 , etc.

mount

(2) After confirming the device file name of the U disk, you can create a directory as the mount point. Suppose we create a mount point under the /mnt/usb directory.

sudo mkdir /mnt/usb

(3) Use the following command to mount the U disk to the mount point just created. Assuming that the device file name of the U disk is /dev/sdb1 , the mount command is .

sudo mount /dev/sdb1 /mnt/usb

(4) Now, you can access the files in the U disk through the /mnt/usb directory. For example, to list the files and directories in the USB stick, you can run .

ls /mnt/usb

(5) When you finish using the U disk, you can use the following command to unmount (unmount) the U disk.

sudo umount /mnt/usb

When executing the mount and umount commands, you may need to add sudo before the command to obtain administrator privileges, depending on your system configuration and user privilege settings.

Guess you like

Origin blog.csdn.net/m0_67906358/article/details/131952328