挂载硬盘
先分区,再格式化,然后挂载
查看硬盘状态
通过fdisk -l 可以看到/dev/vdb 200G 未进行分区格式化
[root@ecs-9c6d-a493 /]# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x18957b03
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 83886046 83883999 40G 83 Linux
Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
创建分区表
[root@ecs-9c6d-a493 /]# sudo parted /dev/vdb
GNU Parted 3.4
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
(parted) mklabel gpt # 推荐使用 GPT(支持大磁盘和现代系统)
(parted)
创建单个分区(占用全部空间)
(parted) mkpart primary 0% 100% # 创建占用全部空间的分区
(parted)
(parted) print # 确认分区信息
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 215GB 215GB primary
(parted) quit # 退出
Information: You may need to update /etc/fstab.
[root@ecs-9c6d-a493 /]#
验证分区创建
[root@ecs-9c6d-a493 /]# sudo fdisk -l /dev/vdb
Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 7F5EB598-E33D-45D0-B7FD-B71E2D953AFB
Device Start End Sectors Size Type
/dev/vdb1 2048 419428351 419426304 200G Linux filesystem # 新分区信息
[root@ecs-9c6d-a493 /]#
格式化分区
[root@ecs-9c6d-a493 /]# sudo mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=13107072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=0 bigtime=1 inobtcount=0
data = bsize=4096 blocks=52428288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=25599, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ecs-9c6d-a493 /]#
挂载分区
- 创建挂载目录: mkdir /project/data
- 挂载
[root@ecs-9c6d-a493 /]# sudo blkid /dev/vdb1 # # 获取分区 UUID
/dev/vdb1: UUID="f2c3332f-e517-48f7-9780-b2ec9ee73a6b" BLOCK_SIZE="512" TYPE="xfs" PARTLABEL="primary" PARTUUID="9b2cbf19-96d3-46ee-910a-530fe6a64620"
- 添加或修改配置
sudo vi /etc/fstab # 修改UUID的值
UUID=f2c3332f-e517-48f7-9780-b2ec9ee73a6b /project/data xfs defaults 0 0 # xfs
验证挂载结果
sudo mount -a
df -hT /project/data
df -h
结果如下
[root@ecs-9c6d-a493 data]# sudo mount -a
[root@ecs-9c6d-a493 data]#
[root@ecs-9c6d-a493 data]#
[root@ecs-9c6d-a493 data]# df -hT /project/data
Filesystem Type Size Used Avail Use% Mounted on
/dev/vdb1 xfs 200G 237M 200G 1% /project/data
[root@ecs-9c6d-a493 data]#
[root@ecs-9c6d-a493 data]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 25M 7.8G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/vda1 40G 3.2G 35G 9% /
tmpfs 7.8G 908K 7.8G 1% /tmp
/dev/vdb1 200G 237M 200G 1% /project/data
[root@ecs-9c6d-a493 data]#