8

I have originally created 2 Logical Volumes in a Volume Group. The 2 Logical Volumes occupy the whole Volume Group and are sat on contiguous Physical Extents.

However, after I have shrunk the first Logical Volume (LV_root), it becomes smaller and empty Physical Extents appear between the 2 Logical Volumes. Here is the output from the "pvdisplay" command :

$ sudo pvdisplay --maps

  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               VG_i5_2500
  PV Size               99.65 GiB / not usable 2.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25510
  Free PE               3025
  Allocated PE          22485
  PV UUID               3nRvBS-qq10-8XZZ-n3x9-gfHx-hrxN-AouB3q

  --- Physical Segments ---
  Physical extent 0 to 18431:
    Logical volume  /dev/VG_i5_2500/LV_root
    Logical extents 0 to 18431
  Physical extent 18432 to 21456:
    FREE
  Physical extent 21457 to 25509:
    Logical volume  /dev/VG_i5_2500/LV_swap
    Logical extents 0 to 4052

I want to know that is there a way to move LV_swap towards LV_root so that there is no empty Physical Extents between them (i.e. in general, how to move Logical Volumes within the same Volume Group in order to make more rooms for contiguous free Physical Extents.) ?

Moreover, is Contiguous free Physical Extents necessary when creating new Logical Volumes in a Volume Group ?

2 Answers 2

1

There isn't an lvmove command in standard LVM (though HP may have one in a custom version).

The way to do this would be to move the contents of the volume off somewhere else, then delete it and recreate it, then copy back.

As your volume is swap, then moving the contents isn't necessary. You can swapoff, delete the volume, then create a new swap volume and swapon.

However, a goal of LVM could be said to not have to bother with any of this. Contiguous physical extents are not necessary to create a volume, it will just get inserted into the gaps. The main time you'd get a performance penalty is if you had a file that crossed non-contiguous extents and so would require an extra seek when being read.

3
  • 1
    There seems do not have the "lvmove" command, just have a "pvmove" command. "pvmove" seems could move a particular Logical Volume, but it needs another Physical Volume for the move and the solution becomes relatively complicated. I am wondering whether there is a "gparted" like LVM tool that could move Logical Volume in an easy way. Jun 11, 2012 at 0:55
  • @user1129812 Yes, this is what I am saying, lvmove does not exist in standard LVM. pvmove would help if you had another pv, then you could move it back afterwards, and it would be moved such that it closes the gap. There isn't a tool like gparted to do this, so you are left with the option in the answer (or variants of it)
    – Paul
    Jun 11, 2012 at 1:55
  • Yes. I have mis-interpreted your wordings in some ways. If there is not a gparted like LVM tool, then using "pvmove" may be the current best solution. Thanks for your suggestion. Jun 11, 2012 at 3:51
18

According to the pvmove man-page there is the possibility to move extents around on the same device:

If the source and destination are on the same disk, the anywhere allocation policy would be needed, like this:

pvmove --alloc anywhere /dev/sdb1:1000-1999 /dev/sdb1:0-999

Maybe overlapping regions are forbidden but then you could move your volume in 2 steps:

pvmove --alloc anywhere /dev/sda5:21457-24481 /dev/sda:18432-21456
pvmove --alloc anywhere /dev/sda5:24482-25509 /dev/sda:21457-22484
2
  • This should be the accepted answer. Cf. also here: wiki.archlinux.org/title/LVM#Move_physical_extents
    – Robert
    Aug 4, 2022 at 18:41
  • It actually works. I used it to make lv continous on one disk, but... I am not sure if this should be done since it just copies data from one place on another on the same disk. It does not matter that much from file system point of view and uses writes on SSD. On HDD maybe it makes more sense. Jun 16, 2023 at 7:30

You must log in to answer this question.

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