1

I have imaged a smaller drive to a larger drive. I now need to increase the size of the parition/volume group (correct term?). The drive has ~1.6 TiB of unallocated space which I want /dev/sdb3 to use then allocate that increase to /dev/cl/root. Below is some information cobbled together from google searching. The first four pieces are from gparted.

/dev/sdb1    fat16        /boot/efi  200 MiB
/dev/sdb2    ext4         /boot      1.0 GiB
/dev/sdb3    lvm2 pv      cl      221.68 GiG
unallocated  unallocated            1.60 TiB

$ sudo lvmdiskscan

  /dev/sdb1       [     200.00 MiB] 
  /dev/sdb2       [       1.00 GiB] 
  /dev/sdb3       [     221.68 GiB] LVM physical volume
  /dev/cl/var     [     100.00 GiB] 
  /dev/cl/swap    [       2.00 GiB] 
  /dev/cl/root    [     110.00 GiB] 


$ sudo lsblk
    NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sdb               8:16   0   1.8T  0 disk 
    ├─sdb2            8:18   0     1G  0 part 
    ├─sdb3            8:19   0 221.7G  0 part 
    │ ├─cl-swap     253:1    0     2G  0 lvm  
    │ ├─cl-root     253:2    0   110G  0 lvm  
    │ └─cl-var      253:0    0   100G  0 lvm  
    └─sdb1            8:17   0   200M  0 part 


$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb3
  VG Name               cl
  PV Size               221.68 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              56749
  Free PE               2478
  Allocated PE          54271
  PV UUID               Uohq5b-Ubkr-f51E-y1tf-vfAi-JA06-dKWx7A

I tried to increase physical size by using sudo pvresize /dev/sdb3 with the output of

  Physical volume "/dev/sdb3" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Though this didn't seem to do anything. I can't resize /dev/sdb3 within gparted. I tried to increase the volume group using

$ sudo vgextend cl /dev/sdb3
  Can't open /dev/sdb3 exclusively.  Mounted filesystem?

I am not sure why it failed as I don't think /dev/sdb3 is mounted as the physical drive is attached to within another Linux CentOS 7 system which was used to image the hard drive.

How can I resize/extend /dev/sdb3 to use the reset of the unallocated space then increase /sdb3/cl-root to use all of the new space?

Some response I have seen show creating a new partition within the unallocated space and then adding it to the group/volume, but I was hoping to increase /dev/sdb3 to use the remaining unallocated space then increase the size of /sdb3/cl-root.

2

First, you'll have to edit the partition table to actually extend the sdb3 partition. You might use gparted, parted, gdisk or fdisk for this.

If you use gdisk or fdisk, the changes are only written to the partition table when you tell the program to do it, so with a single gdisk/fdisk session, you can view the exact disk location (block/sector number) where sdb3 begins, delete the sdb3 partition, recreate it with the exact same starting point and a new end point, and then write the updated partition table to the disk.

If the kernel does not accept the new partition size immediately, you might have to run sudo partprobe /dev/sdb at this point.

Once the new partition size is visible in /proc/partitions, you can proceed with sudo pvresize /dev/sdb3 exactly as you did. After that, sudo pvdisplay should indicate increased PV size, Total PE and Free PE values.

At that point, you can use sudo lvextend -r -L <desired new size> /dev/cl/root to extend your LV.

Since sdb3 PV is already a member of the cl volume group, you don't need vgextend in this case: it is only used when you're adding a new, unused PV into an existing volume group. Since the VG is currently active and all its LVs are mounted/in use, the PV is locked for exclusive access by the LVM, so even the vgextend tool cannot access it directly. If you tried to do the vgextend by booting from an external media, so that the LVs would be unmounted, you would see an error message

Physical volume '/dev/sdb3' is already in volume group 'cl'

instead.

  • "block/sector number) where sdb3 begins, delete the sdb3 partition, recreate it with the exact same starting point and a new end point, and then write the updated partition table to the disk." -- If I delete the sdb3 partition and recreate it, will the data be gone? I would like to keep the data if possible. If this process does not keep the data I should be able to copy the partition from the original disk to the new disk I would image. – lordhog Jul 2 at 9:33
  • 1
    Linux ` fdisk/ gdisk` will only update the partition table and nothing else. So if you overwrite the partition table with one that specifies the same beginning position and a new ending position for an existing partition, that is how a partition gets extended without any change to its actual contents. But ` gparted` and parted have a "resize partition" function that does exactly the same thing, but they have the advantage that with that function you cannot even accidentally change the starting point of the partition. – telcoM Jul 2 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.