1

Recently I tried to extend the virtual disk size for my Centos7 virtual machine. I did it in a wrong way and now I have the following:

    # fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000a74fb

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83877887    40889344   8e  Linux LVM
/dev/sda3        83877888   104857599    10489856   8e  Linux LVM

Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

Logical volume centos-root now resides on two adjacent partitions sda2 and sda3. I want to merge them into one partition, but don't know how to do it. I tried to remove /dev/sda3 from centos-root, but it fails:

# vgreduce centos /dev/sda3
  Physical volume "/dev/sda3" still in use

1 Answer 1

1

Why are you trying to "merge" the partitions? This is a completely fine setup. Yes, the second partition is not needed, but this doesn't matter with LVM, you just have two PVs, you can use space on both of these.

If you really want to change this, you'll need to make sure there are no data saved on the sda3 PV (pvs -o+pv_used will tell you how much space is allocated on each PV). This means you need to shrink the root logical volume using lvreduce (don't forget to use -r to resize the filesystem too) to make sure it fits on the sda2 PV. After this use pvmove to move all allocated extents from it: pvmove /dev/sda3, after this the vgreduce command should work. After that you'll need to remove the partition and resize sda2 (don't forget to use pvresize to actually resize the physical volume format on it).

1
  • Thank you Vojtech! I also had to use lvextend and xfs_growfs to have it complete.
    – elky
    Mar 2, 2021 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .