If you had created the PV as partition, you would have to shrink the PV first with pvresize --setphysicalvolumesize 5124M /dev/sdb
and then resize the partition in the partition table with tools like fdisk
or parted
.
But in your case you cannot create new partitions there since the PV encompasses the whole drive, so you can't safely make a fresh partition table without destroying the PV. Well, actually you could by directly manipulating the partition table, but that's dangerous and will come back and bite you further along the line.
Instead, the safest way is to make another PV on a different drive, add that to the volume group, move the LV to that other PV, remove the first PV from the VG, remove the first PV from /dev/sdb, make partitions on /dev/sdb, make a PV on one of those partitions, add the PV to the VG, move the LV to this now correct PV, and finally remove the temporary PV from the VG.
Something like this: (Note that you will have to make sure you use device names that apply to your particular configuration, don't just copy&paste. /dev/sdc
is just an example, it could be different for you):
# plug in external USB drive
dmesg | tail # Check which device name the plugged in drive got.
lsblk # another way to verify, assuming `lsblk` is installed
cat /proc/partitions # one more way to verify, sizes are in KiB
fdisk /dev/sdc # Make at least one partition on the drive, minimum of 5124 MiB.
pvcreate /dev/sdc1 # create the Physical Volume (PV)
vgextend VG /dev/sdc1 # add the PV to the Volume Group (VG)
pvmove -i 5 /dev/sdb /dev/sdc1 # Try to move every Logical Volume (LV) on PV /dev/sdb over to PV /dev/sdc1.
# There's no need to unmount anything, the process is completely transparent
# to the LV and anything using it. You may want to make a tea or two ;)
# Watch out for errors regarding insufficient space on the target PV, tho.
vgreduce VG /dev/sdb # Remove the old PV from the VG.
pvremove /dev/sdb # Wipe the PV metadata from the drive. Don't continue in case of errors here!
fdisk /dev/sdb # Properly partition the drive. Partition for PV should be 5124 MiB minimum.
pvcreate /dev/sdb1 # Create a PV on the just created partition.
vgextend VG /dev/sdb1 # Add PV to the VG.
pvmove -i 5 /dev/sdc1 /dev/sdb1 # Move LVs back from the temporary PV to the freshly partitioned one.
vgreduce VG /dev/sdc1 # Remove temporary PV from the VG.
pvremove /dev/sdc1 # Wipe PV metadata from the drive.
Make a backup before trying this.
The given pv*
and vg*
commands are safe if used like shown here. They will refuse to work if the preconditions are not met or will ask if you want to do it anyway (answer n
in that case). In particular, as you shrunk the LV to exactly 5 GiB, you will need a partition that is slightly larger than 5120 MiB (I suggest adding 4 MiB, hence 5124 MiB) for the PV to be able to accommodate the metadata and it will complain if that isn't the case.
However, fdisk
is not safe and it will happily continue to do your bidding, even if it would write over your precious data, so be extra cautious.
lvcreate
to allocate a new logical volume within the available physical volume. If you want to remove the free space from the physical volume and turn it into a standard partition, that's going to be a lot more work.