Moving an LV within a VG

I have one spindle, sdj, partitioned with /boot occupying the first gibibyte and the rest (1.82 TiB) holding the almalinux volume group. The only logical volume in the group is the root filesystem (70GiB) which is located right at the end of the VG. Is there way to safely move the LV to the beginning of the VG? I need to resize the VG to release some space for other purposes.

My first thought was to use pvresize --setphysicalvolumesize 100G but this will only remove extents at the end of the physical volume. There doesn’t appear to be an lvmove command to achieve this.

NB, this is the root partition!

1 Like

man pvmove:

If the source and destination are on the same disk, the anywhere allocation policy is needed.
pvmove --alloc anywhere /dev/sdb1:1000-1999 /dev/sdb1:0-999

1 Like

That looks to be the ticket. If you have a moment could you glance at the following and check it makes sense:

pv0: pe_start=2048, pe_count=476675
root: segment 1: start_extent=0 extent_count=17920 stripe=["pv0",458755]

pvmove --alloc anywhere /dev/sdj2:458755-476674 /dev/sdj2:0-17919

Thanks.

I’m no expert on LVM. To layman’s eye those numbers look reasonable.
(I have pvmove’d from one disk to another. If I ever did in-disk move, then I have forgotten.)

Phew! stripes=["pv0",0] and the system has been rebooted. :sweat_smile: Thanks.

2 Likes

@jlehtone , this is an interesting command.

My set-up used to be:
3 * 1TiB disks in a RAID array supporting a VG. 1 * 1TiB holding some user space. 1 * 2TiB with /bootand another VG (“alma”) holding the root partition. What I did was:

  1. tar up the user space, thus freeing the 1TiB disk.
  2. Move the root partition to the start of the alma VG (as above).
  3. Shrink the alma VG to 100 GiB (root is 70 GiB).
  4. Create a 1 TiB partition on the 2 TiB disk.
  5. Expand the RAID.
  6. Create an LV for the user files and restore them.
  7. Create a new swap partition on the large disk and remove the old one on the RAID.

So now I have most of my system on RAID5 (4 raw spindles and a partition) with the large disk holding /boot, swap and the alma VG which just holds root.