CentOS云服务器数据盘分区和格式化

时间:2022-06-01 22:15:33

1. 查看数据盘信息

登录CentOS云服务器后,可以使用“fdisk -l”命令查看数据盘相关信息。 使用“df –h”命令,无法看到未分区和格式化的数据盘,只能看到已挂载的。

[root@VM_75_6_centos tlbb]# fdisk -l

Disk /dev/vda:  MB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xcd6e8236 Device Boot Start End Blocks Id System
/dev/vda1 * + Linux Disk /dev/vdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/vdb doesn't contain a valid partition table Disk /dev/vdc: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/vdc doesn't contain a valid partition table

可以看到 vdb vdc 这两个盘并未进行分区。
2.数据盘分区

执行以下命令,对数据盘进行分区。 然后输入 n p 1 两次enter wq。分区已然形成

fdisk /dev/vdb
[root@VM_75_6_centos tlbb]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf9140b26.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): wq
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

再fdisk -l一下。

Disk /dev/vdb: 21.5 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xf9140b26 Device Boot Start End Blocks Id System
/dev/vdb1 + Linux

然后进行格式化文件系统。

[root@VM_75_6_centos tlbb]# mkfs.ext3 /dev/vdb1
mke2fs 1.41. (-May-)
文件系统标签=
操作系统:Linux
块大小= (log=)
分块大小= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
第一个数据块=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , , 正在写入inode表: 完成
Creating journal ( blocks): 完成
Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

最后,将此分区挂在到/home目录下

mount /dev/vdb1 /home

用df -h看一下分区信息。

[root@VM_75_6_centos tlbb]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/vda1 .9G .9G .7G % /
/dev/vdb1 20G 173M 19G % /home

大功告成。