一、查看磁盘挂载状态:
fdisk -l
df -h
二、为其中一个磁盘创建新的分区,参考:
linux用fdisk创建分区,在Linux下用fdisk创建分区_weixin_39968410的博客-CSDN博客
sudo fdisk /dev/nvme0n1
1. 创建主分区:
---------------------------------------------------------------------------
command (m for help): p ## p :显示硬盘分割情况
Disk /dev/nvme0n1: 3.5 TiB, 3840755982336 bytes, 7501476528 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 131072 bytes / 131072 bytes
Disklabel type: dos
Disk identifier: 0x473a4ff6
---------------------------------------------------------------------------
Command (m for help): n ##设定新的硬盘分割区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
- - - - - - - - - - - - - - - - - --
Select (default p): p ## 创建主分区(p)
- - - - - - - - - - - - - - - - - --
Partition number (1-4, default 1): 1 #分区号为1
- - - - - - - - - - - - - - - - - --
First sector (2048-4294967295, default 2048): ##直接回车默认从第一个柱面开始划分
- - - - - - - - - - - - - - - - - --
Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294): +3.5T. #分区大小设置,超过该磁盘剩余的空间,无效,默认是最大空间
Value out of range.
Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294): +1T #分区大小设置为1TB
- - - - - - - - - - - - - - - - - --
Created a new partition 1 of type 'Linux' and of size 1 TiB.
---------------------------------------------------------------------------
2. 创建扩展分区
---------------------------------------------------------------------
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e #建立扩展分区
Partition number (2-4, default 2): 2 #分区号为1
First sector (2147485696-4294967295, default 2147485696):
Last sector, +sectors or +size{K,M,G,T,P} (2147485696-4294967294, default 4294967294): +1T
Value out of range.
Last sector, +sectors or +size{K,M,G,T,P} (2147485696-4294967294, default 4294967294): +800G # 分区容量为800G
Created a new partition 2 of type 'Extended' and of size 800 GiB.
---------------------------------------------------------------------
Command (m for help): p #查看分区状态
Disk /dev/nvme0n1: 3.5 TiB, 3840755982336 bytes, 7501476528 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 131072 bytes / 131072 bytes
Disklabel type: dos
Disk identifier: 0x473a4ff6
- - - - - - - - - - - -
# 以下是刚刚创建的分区:
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 2048 2147485695 2147483648 1T 83 Linux
/dev/nvme0n1p2 2147485696 3825207295 1677721600 800G 5 Extended
3. 在扩展分区创建逻辑分区
Command (m for help): n
Partition type
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l # 选择创建逻辑分区
Adding logical partition 5
First sector (2147487744-3825207295, default 2147487744):
Last sector, +sectors or +size{K,M,G,T,P} (2147487744-3825207295, default 3825207295): # 直接回车表示所有扩展分区只划分一个逻辑分区
Created a new partition 5 of type 'Linux' and of size 800 GiB.
4. 保存设置
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
5. 查看磁盘状况:
三、格式化磁盘
刚创建的分区必须要进行格式化,否则会出现如下错误:
mount: /data: wrong fs type, bad option, bad superblock on /dev/nvme0n1p1, missing codepage or helper program, or other error.
1. 格式化磁盘:
mkfs.xfs -f /dev/nvme0n1p1
mkfs.xfs -f /dev/nvme0n1p2
2. 挂载磁盘
mount /dev/nvme0n1p1 /data