作者 • Cao Feilong 时间 • 2023-04-20
当系统存储空间不够时,我们新增一块磁盘,以增加容量来存储数据。
本案例中,在centos上新增一块500G磁盘,具体操作为分区->格式化->挂载到存储数据。
查看新增的磁盘#
> lsblk (TYPE为disk类型且没有下分支的,即是没有被分区的硬盘)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 478K 0 rom
vda 253:0 0 100G 0 disk
├─vda1 253:1 0 1M 0 part
├─vda2 253:2 0 512M 0 part /boot/efi
├─vda3 253:3 0 512M 0 part /boot
└─vda4 253:4 0 99G 0 part /
vdb 253:16 0 500G 0 disk
或者
> fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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: gpt
Disk identifier: 713E652D-3BCF-40B9-A5CF-871D10499E8C
# Start End Size Type Name
1 2048 4095 1M BIOS boot BIOS boot partition
2 4096 1052671 512M EFI System EFI System Partition
3 1052672 2101247 512M Microsoft basic
4 2101248 209715165 99G Microsoft basic
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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 /dev/vdb: 536.9 GB 就是需要新分区的硬盘;
格式化新增的磁盘#
> fdisk /dev/vdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf886ec28.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查看分区#
> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 478K 0 rom
vda 253:0 0 100G 0 disk
├─vda1 253:1 0 1M 0 part
├─vda2 253:2 0 512M 0 part /boot/efi
├─vda3 253:3 0 512M 0 part /boot
└─vda4 253:4 0 99G 0 part /
vdb 253:16 0 500G 0 disk
└─vdb1 253:17 0 500G 0 part
或者
> fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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: gpt
Disk identifier: 713E652D-3BCF-40B9-A5CF-871D10499E8C
# Start End Size Type Name
1 2048 4095 1M BIOS boot BIOS boot partition
2 4096 1052671 512M EFI System EFI System Partition
3 1052672 2101247 512M Microsoft basic
4 2101248 209715165 99G Microsoft basic
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0xf886ec28
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 83 Linux
查看其他分区格式#
> blkid /dev/vda4
/dev/vda4: UUID="061ff8e...a1935ae" TYPE="xfs" PARTUUID="b52bc3...6eff804"
格式化#
> mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=32767936 blks
...
realtime =none extsz=4096 blocks=0, rtextents=0
创建待挂载目录,必须是空目录,注意,如挂载已有数据的目录,则挂载完数据不显示,但还在占用空间;
创建新目录,然后复制数据到新挂载;
同一目录无法重复挂载,后挂载的会覆盖之前挂载的磁盘。
> mkdir -p /backup-gw-data
挂载分区#
以下两种挂载都要操作:
临时挂载#
> mount /dev/vdc1 /backup-gw-data
查看挂载情况
> df -Th /dev/vdc1
永久挂载#
> blkid /dev/vdc1
/dev/vdc1: UUID="bcd31b84-070d-4e77-bde0-c50cb9b68808" TYPE="xfs"
开启自动挂载
> vim /etc/fstab
UUID=bcd31b84-070d-4e77-bde0-c50cb9b68808 /backup-gw-data xfs defaults 0 0
查看挂载情况
> mount -a
或者
> df -Th /dev/vdb1