坚持以客户需求至上原则
中国老牌优质服务商

centos7中lvm分区的创建与扩展

创建LVM分区

首先,挂载虚拟硬盘到虚拟机上,这里挂了2个1T的硬盘。

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  9.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0 39.2G  0 lvm  /home
sdb               8:16   0    1T  0 disk 
sdc               8:32   0    1T  0 disk 
sr0              11:0    1 1024M  0 rom  

// 创建物理卷
$ sudo pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.

// 创建卷组
$ sudo vgcreate VG1 /dev/sdb
  Volume group "VG1" successfully created

// 查看卷组剩多少PE
$ sudo vgdisplay
  ...
  --- Volume group ---
  VG Name               VG1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <2.00 TiB
  PE Size               4.00 MiB
  Total PE              524286
  Alloc PE / Size       262143 / <1024.00 GiB
  Free  PE / Size       262143 / <1024.00 GiB     //剩余空间大小
  VG UUID               DYPyVN-9ssj-pLxN-bksi-9U0V-m2wQ-aQ3IPe
  ...

// 将所有剩余空间创建为逻辑卷
$ sudo lvcreate -l 262143 -n MyLvm0 VG1
  Logical volume "MyLvm0" created.

// 创建完成
$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  9.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0 39.2G  0 lvm  /home
sdb               8:16   0    1T  0 disk 
└─VG1-MyLvm0    253:3    0 1024G  0 lvm        // 所创建的LVM逻辑卷
sdc               8:32   0    1T  0 disk 
sr0              11:0    1 1024M  0 rom

扩展LVM分区

上面使用了一块1T虚拟硬盘,下面将另外一块虚拟硬盘添加到刚才的逻辑卷中,实现扩展。

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  9.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0 39.2G  0 lvm  /home
sdb               8:16   0    1T  0 disk 
└─VG1-MyLvm0    253:3    0 1024G  0 lvm        // 需要扩展的LVM逻辑卷
sdc               8:32   0    1T  0 disk       // 额外的空间
sr0              11:0    1 1024M  0 rom  

// 创建物理卷
$ sudo pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.

// 将它加入到卷组
$ sudo vgextend VG1 /dev/sdc
  Volume group "VG1" successfully extended

// 扩展逻辑卷MyLvm0
$ sudo lvextend -l +262142 /dev/VG1/MyLvm0
  Size of logical volume VG1/MyLvm0 changed from 1.00 TiB (262144 extents) to <2.00 TiB (524286 extents).
  Logical volume VG1/MyLvm0 successfully resized.

// 成功扩展
$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  9.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0 39.2G  0 lvm  /home
sdb               8:16   0    1T  0 disk 
└─VG1-MyLvm0    253:3    0    2T  0 lvm  
sdc               8:32   0    1T  0 disk 
└─VG1-MyLvm0    253:3    0    2T  0 lvm  
sr0              11:0    1 1024M  0 rom
赞(11)

更专业 更快速 更方便

华夏名网VIP服务