在Linux环境下增加磁盘(包括物理机器上增加磁盘,或者在云环境增加磁盘),都需要将磁盘格式化,并挂载到指定目录下。
以阿里云环境下,增加一块高效云盘为例。
使用fdisk增加分区
增加一块1T的高效云盘以后,使用fdisk查看,会发现新增了一块磁盘/dev/vdb
root@iZt4n2xe04owrybltp05j6Z:~# 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: 0xb2ac676a
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 83886046 83883999 40G 83 Linux
Disk /dev/vdb: 1 TiB, 1099511627776 bytes, 2147483648 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@iZt4n2xe04owrybltp05j6Z:~# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xaf33802a.
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
Partition number (1-4, default 1): 1
First sector (2048-2147483647, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-2147483647, default 2147483647):
Created a new partition 1 of type 'Linux' and of size 1024 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
查看新分区的情况,可以看到已经有了一个分区信息/dev/vdb1
root@iZt4n2xe04owrybltp05j6Z:~# 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: 0xb2ac676a
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 83886046 83883999 40G 83 Linux
Disk /dev/vdb: 1 TiB, 1099511627776 bytes, 2147483648 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: 0xaf33802a
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 2147483647 2147481600 1024G 83 Linux
格式化磁盘
有了新的分区,需要在对分区格式化
mkfs.ext4 /dev/vdb1
挂载到指定目录
mkdir /data
mount /dev/vdb1 /data
这样,就可以使用新的磁盘空间了。
对于磁盘空间大于2TB的情况,阿里云环境下,需要额外处理,可以参考:
https://help.aliyun.com/document_detail/34377.html?spm=a2c4g.11186623.2.26.29d37d56A660p1#concept-i15-qpc-ydb
重启后自动挂载
按照上述的方式挂载磁盘,重启机器以后,会发现原本挂载的目录已经没法用了,需要重新挂载,每次都这样玩,太麻烦。
编辑/etc/fstab
,添加下面的这行。这里,/dev/vdb1
是新增磁盘,/data
是挂载位置。
/dev/vdb1 /data ext4 defaults 0 0