How to resize VM partition on Vmware 

                                          by Jephe Wu - http://linuxtechres.blogspot.com

Extend a LVM partition

  1. from Vcenter, to edit configure, to add a new hard disk with required size
  2.   echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)
  3. dmesg and cat /proc/partition to confirm new disk is added.

      4. fdisk /dev/sdb to create a new partition and use t  to change it to 8e LVM

      5 . pvcreate /dev/sdb1

     6. vgextend vg_root /dev/sdb1

     7. lvextend -l +100%FREE /dev/vg_root/lv_root

or  8. lvextend -L +20G /dev/vg_root/lv_root (if only increase 20G)

     9.  resize2fs /dev/mapper/vg_root-lv_root 

or xfs_growfs mountpoint (if it's xfs partition)


Modify existing sdb LVM PV disk size and use it in vg

1. echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)

or

echo 1 > /sys/block/sdb/device/rescan

 

2.  use pvscan or  fdisk -l | grep -i sdb to confirm new disk size

3. blockdev --rereadpt /dev/sdb  to resize LVM volume size

4. pvresize /dev/sdb  to resize PV


Resize Procedure for /dev/sdb1 PV

https://access.redhat.com/solutions/57183

1. Confirm the actual storage size with fdisk -ul /dev/sdb. Observe the increased disk size. Depending on how the storage is presented, a system reboot may be necessary for this to appear.

2. Resize the partition on the disk. To achieve this, observe the starting sector in fdisk -ul /dev/sdb, then remove the partition with fdisk and re-create it with the same starting sector but the (default) last sector of the drive as the ending sector. Then write the partition table and confirm the change (and the correct starting sector) with fdisk -ul /dev/sdb.

3. Run pvresize /dev/sdb1 to grow (resize) the PV onto the rest of the expanded partition. This will create free extents within the Volume Group which then can be used to grow a Logical Volume. Running lvresize command with -r as lvresize -r will grow the filesystem within the Logical Volume as well.

Another solution would be creating a new partition under the same device starting where the first partition ended and using the rest of the cylinders to create the same, then put this new partition under LVM with the pvcreate command, extend the current VG (vgextend vg-name pv-name), then extend the current LV (lvextend) and finally resize the current filesystem (resize2fs).


Create a new LVM partition with new disk

pvcreate /dev/sdx1 

vgcreate vg01 /dev/sdx1

lvcreate -l +100%FREE -n apps vg01
mkfs -t xfs /dev/mapper/vg01_apps


For rollback

1) Unmount the mountpoint

umount -v /var/www

2) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

3) Reduce the logical volume

lvreduce --resize2fs -L -100G (-l 5119)  /dev/vg-repo/lv-repo

Note: use vgdisplay to record down existing used logic extent number, it's 5119 in this case before increase

4) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

5) Mount the filesystem back to the same mountpoint

mount /dev/vg-repo/lv-repo /var/www

6) Reduce the VG in order to release the PV /dev/sde1

vgreduce vg-repo /dev/sde1

7) Remove the PV

pvremove /dev/sde1

8) Remove the new created disk from vcenter in the backup plan?


No comments:

Post a Comment