第一种方式(不分区)
磁盘不分区,直接挂载到某个目录。
 查看磁盘列表
 fdisk -l
[root]# fdisk -lDisk /dev/vdb: 214.7 GB, 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
创建目录
 mkdir /data
格式化磁盘
 有好几种文件格式,需要自己选择下,一般选xfs
 mkfs.xfs /dev/vdb
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# mkfs.
mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.fat     mkfs.minix   mkfs.msdos   mkfs.vfat    mkfs.xfs     
挂载到目录(临时)
 mount /dev/vdb /data
挂载到目录(永久)
 写到/etc/fstab文件中
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# cat /etc/fstab#
# /etc/fstab
# Created by anaconda on Fri Nov  8 10:19:15 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_host--172--25--9--73-root /                       xfs     defaults        0 0
UUID=8477d0c9-a162-4653-825e-7d10436bbfb3 /boot                   xfs     defaults        0 0
/dev/mapper/centos_host--172--25--9--73-swap swap                    swap    defaults        0 0
/dev/mapper/centos_host--172--25--9--73-swap	none	swap	sw,comment=cloudconfig	0	0
执行 mount -a 立即挂载
第二种方式(分区)
查看磁盘信息
 fdisk -l
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# fdisk -lDisk /dev/vda: 214.7 GB, 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
Disk label type: dos
Disk identifier: 0x000d041cDevice Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM
可以看到/dev/vda又被分成两个分区,占用了20g空间,磁盘中其他的空间还没被挂载。
交互式方式创建分区
 fdisk /dev/vda
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): m
Command actiona   toggle a bootable flagb   edit bsd disklabelc   toggle the dos compatibility flagd   delete a partitiong   create a new empty GPT partition tableG   create an IRIX (SGI) partition tablel   list known partition typesm   print this menun   add a new partitiono   create a new empty DOS partition tablep   print the partition tableq   quit without saving changess   create a new empty Sun disklabelt   change a partition's system idu   change display/entry unitsv   verify the partition tablew   write table to disk and exitx   extra functionality (experts only)Command (m for help): 
输入p打印分区信息
Command (m for help): pDisk /dev/vda: 214.7 GB, 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
Disk label type: dos
Disk identifier: 0x000d041cDevice Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM
/dev/vda3        41943040   419430399   188743680   83  LinuxCommand (m for help): 
输入n创建分区
Command (m for help): n
Partition type:p   primary (3 primary, 0 extended, 1 free)e   extended
Select (default e): 可以看到还能创建1个分区。
 每个磁盘最多能创建4个分区。
创建分区并分配空间
 一路空格把剩余空间都分给最后一个分区。
 最后输入w保存
完整命令执行过程
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# fdisk -lDisk /dev/vda: 214.7 GB, 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
Disk label type: dos
Disk identifier: 0x000d041cDevice Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVMDisk /dev/vdb: 214.7 GB, 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 bytesDisk /dev/mapper/centos_host--172--25--9--73-root: 18.5 GB, 18513657856 bytes, 36159488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos_host--172--25--9--73-swap: 1879 MB, 1879048192 bytes, 3670016 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-jindie-distributedmessage-0002 admq-V2.2.1]# lsblk
NAME                                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                                   11:0    1 1024M  0 rom  
vda                                  252:0    0  200G  0 disk 
├─vda1                               252:1    0    1G  0 part /boot
└─vda2                               252:2    0   19G  0 part ├─centos_host--172--25--9--73-root 253:0    0 17.2G  0 lvm  /└─centos_host--172--25--9--73-swap 253:1    0  1.8G  0 lvm  [SWAP]
vdb                                  252:16   0  200G  0 disk /data
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): m
Command actiona   toggle a bootable flagb   edit bsd disklabelc   toggle the dos compatibility flagd   delete a partitiong   create a new empty GPT partition tableG   create an IRIX (SGI) partition tablel   list known partition typesm   print this menun   add a new partitiono   create a new empty DOS partition tablep   print the partition tableq   quit without saving changess   create a new empty Sun disklabelt   change a partition's system idu   change display/entry unitsv   verify the partition tablew   write table to disk and exitx   extra functionality (experts only)Command (m for help): pDisk /dev/vda: 214.7 GB, 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
Disk label type: dos
Disk identifier: 0x000d041cDevice Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVMCommand (m for help): n
Partition type:p   primary (2 primary, 0 extended, 2 free)e   extended
Select (default p): 
Using default response p
Partition number (3,4, default 3): 
First sector (41943040-419430399, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-419430399, default 419430399): 
Using default value 419430399
Partition 3 of type Linux and of size 180 GiB is setCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# lsblk /dev/vda
NAME                                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                                  252:0    0  200G  0 disk 
├─vda1                               252:1    0    1G  0 part /boot
└─vda2                               252:2    0   19G  0 part ├─centos_host--172--25--9--73-root 253:0    0 17.2G  0 lvm  /└─centos_host--172--25--9--73-swap 253:1    0  1.8G  0 lvm  [SWAP]
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# partprobe /dev/vda
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# lsblk 
NAME                                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                                   11:0    1 1024M  0 rom  
vda                                  252:0    0  200G  0 disk 
├─vda1                               252:1    0    1G  0 part /boot
├─vda2                               252:2    0   19G  0 part 
│ ├─centos_host--172--25--9--73-root 253:0    0 17.2G  0 lvm  /
│ └─centos_host--172--25--9--73-swap 253:1    0  1.8G  0 lvm  [SWAP]
└─vda3                               252:3    0  180G  0 part 
vdb                                  252:16   0  200G  0 disk /data
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# mkfs.xfs /dev/vda3
meta-data=/dev/vda3              isize=512    agcount=4, agsize=11796480 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=47185920, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=23040, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# 
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# mkdir /data02
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# mount /dev/vda3 /data02
[root@ecs-jindie-distributedmessage-0002 admq-V2.2.1]# df -h
Filesystem                                    Size  Used Avail Use% Mounted on
/dev/mapper/centos_host--172--25--9--73-root   18G  4.5G   13G  27% /
devtmpfs                                      7.8G     0  7.8G   0% /dev
tmpfs                                         7.8G     0  7.8G   0% /dev/shm
tmpfs                                         7.8G   12M  7.8G   1% /run
tmpfs                                         7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1                                    1014M  209M  806M  21% /boot
tmpfs                                         1.6G   12K  1.6G   1% /run/user/42
/dev/vdb                                      197G  1.4G  186G   1% /data
tmpfs                                         1.6G     0  1.6G   0% /run/user/0
/dev/vda3                                     180G   33M  180G   1% /data02