linux磁盘空间不足,添加磁盘并动态扩容

磁盘初始化

使用命令查看磁盘信息

fdisk -l

Disk /dev/xvdg: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

可以看到新增的磁盘/dev/xvdg已经识别,大小为2T,现需对磁盘进行格式化操作

使用命令格式化磁盘

parted /dev/xvdg

[root@dzzz-db1 ~]# parted /dev/xvdg
GNU Parted 2.1
Using /dev/xvdg
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/xvdg: unrecognised disk label
(parted) mklabel gpt
(parted) mkpart primary 0 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdg: 2147GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  2147GB  2147GB               primary
(parted) quit
Information: You may need to update /etc/fstab. 
[root@dzzz-db1 ~]# 

1、使用print命令查看磁盘信息,提示Error: /dev/xvdg: unrecognised disk label

2、需使用mklabel gpt命令,对磁盘创建分区表;

3、使用mkpart primary 0 100%命令,出现警告输入Ignore忽略;

4、使用print即可查看新的分区信息,使用quit退出

使用命令查看该磁盘信息

fdisk -l /dev/xvdg

Disk /dev/xvdg: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdg1               1      261084  2097151999+  ee  GPT

新磁盘分区为/dev/xvdg1

使用命令创建物理卷

pvcreate /dev/xvdg1

[root@dzzz-db1 ~]# pvcreate /dev/xvdg1
Physical volume "/dev/xvdg1" successfully created

物理卷创建成功,使用pvdisplay可查看物理卷信息

动态扩容

1、将新增的xvdg1加入到卷组license(需要扩容的卷组)

使用vgdisplay可以看到我们需要扩容的卷组名为license

  VG Name               license
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               2.93 TiB
  PE Size               4.00 MiB
  Total PE              767995
  Alloc PE / Size       767995 / 2.93 TiB
  Free  PE / Size       0 / 0   
  VG UUID               ds1M8o-udP6-xtBa-xf5Z-6xYf-O0jE-Kiu0bY

使用vgextend license /dev/xvdg1将物理卷xvdg1加入license卷组

[root@dzzz-db1 ~]# vgextend license /dev/xvdg1
Volume group "license" successfully extended

2、将卷组中新加入的磁盘空间容量扩展到逻辑卷中

使用lvextend -l +100%FREE /dev/license/license-data将余空间全部扩容到l/dev/license/license-data逻辑卷中

[root@dzzz-db1 ~]# lvextend -l +100%FREE /dev/license/license-data
Extending logical volume license-data to 4.88 TiB
Logical volume license-data successfully resized

可以看到已扩容成功2T空间

3、刷新文件系统使扩容生效

使用resize2fs /dev/license/license-data刷新文件系统

[root@dzzz-db1 ~]# resize2fs /dev/license/license-data
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/license/license-data is mounted on /license; on-line resizing required
old desc_blocks = 188, new_desc_blocks = 313
Performing an on-line resize of /dev/license/license-data to 1310713856 (4k) blocks.

此时已开始扩容,容量会逐步增加,可使用df -h命令查看/dev/license/license-data大小

你可能感兴趣的:(linux)