Detailed explanation of Liunx-disk partition fdisk command

Detailed explanation of disk partition fdisk command

What is a partition

Liunx is the same as Win10, we can partition the mounted hard disk, such as win into C, D, E, F and other disks, while Liunx uses file path partitions, such as the future /dev/xxx folder is divided into a certain area

Hard disk partition operation steps

Check the partition situation

The hard disk partition that Liunx needs to build access needs to use the fdisk command

#查看所有硬盘信息
fdisk -l

Insert picture description here

Operate an unpartitioned hard drive to partition

#操作未分区硬盘
fdisk /dev/sdb

fdisk command parameter introduction
m, view help
p, print partition table
n, create a new partition
d, delete a partition
q, exit without saving
w, write the partition into the partition table, save and exit

Hard Drive Partitioning in 5 Steps

1. The command n means to create a new partition
2. There are two options here, p means primary partition (primary), e means extended partition (extended), the default is the primary partition
3. Set the partition number
4. Set the sector Start position
5. Set partition size
6. Save partition result
About 4-5 steps:
1. Why the partition start position is 2048, because the sectors that can be used start from 2048 (the previous sector includes MBR used as Other uses)
2. The designation of the end sector of the partition can be either the sector number or the format of +size. Here we specify the partition size as 299G

Insert picture description here
Finally check the hard disk partition situation
Insert picture description here

Format partition

The partitioned hard disk needs to be formatted in the corresponding format

#将/dev/sdb1分区的硬盘格式化为ext4格式
mkfs -t ext4 /dev/sdb1

Insert picture description here

Partition mount

#将分区挂载到/data目录下(可以使用mkdir命令创建自己喜欢的目录挂载)
#最后通过df-h 查看一下data目录是否挂载成功,挂载后data目录有295G 
mount /dev/sdb1 /data
# 上面命令挂载后重启后需要重新挂载,如想不丢失,需要配置自动挂载
# 要修改/etc/fstab文件。 
# 加一行字: 
# /dev/sdb1 /data ext4 defaults 0 0

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44642403/article/details/112659156