lvm 添加分区

# 查看分区情况
# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1 1024M  0 rom
xvda            202:0    0  100G  0 disk
├─xvda1         202:1    0  500M  0 part /boot
└─xvda2         202:2    0 14.5G  0 part
  ├─centos-root 253:0    0   13G  0 lvm  /
  └─centos-swap 253:1    0  1.5G  0 lvm  [SWAP]

# 新建分区
# fdisk /dev/xvda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (31457280-209715199,默认为 31457280):
将使用默认值 31457280
Last 扇区, +扇区 or +size{K,M,G} (31457280-209715199,默认为 209715199):
将使用默认值 209715199
分区 3 已设置为 Linux 类型,大小设为 85 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。

# 让内核重新识别分区
# partprobe



####   lvm部分
# 然后创建物理卷pv
# pvcreate /dev/xvda3
  Physical volume "/dev/xvda3" successfully created

# 查看pv信息
pvdisplay

# 查看vg情况
# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               14.51 GiB
  PE Size               4.00 MiB
  Total PE              3714
  Alloc PE / Size       3704 / 14.47 GiB
  Free  PE / Size       10 / 40.00 MiB
  VG UUID               qT52GT-QK7N-N2xq-j3Kt-0TLQ-mRCf-nU2U1g


# 将pv加入vg
# vgextend centos /dev/xvda3

# 查看vg空间,应该看到明显增大
# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               99.50 GiB
  PE Size               4.00 MiB
  Total PE              25473
  Alloc PE / Size       3704 / 14.47 GiB
  Free  PE / Size       21769 / 85.04 GiB
  VG UUID               qT52GT-QK7N-N2xq-j3Kt-0TLQ-mRCf-nU2U1g

# 将新的vg空间扩展给lv
lvextend -L +85G /dev/mapper/centos-root

# 检查逻辑卷
e2fsck -f /dev/mapper/centos-root

# 重新定义分区大小
resize2fs -f  /dev/mapper/centos-root  # 针对的是ext2、ext3、ext4文件系统

# centos 7 重新定义分区大小
xfs_growfs /dev/mapper/centos-root  # 针对的是xfs文件系统

作者:Star-Hitian,转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/p/15117821.html

原文地址:https://www.cnblogs.com/Star-Haitian/p/15117821.html