[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

LVM: shrinking a logical volume (moving LVM logical volumes to new disks)



Hi,

so far, I managed to pvmove a LV to my USB stick and from there to a
backup disk in another machine.  Doing so, I found that I can split off
LVs from a volume group and that this inevitably creates a new VG.  That
leaves you stuck because it's impossible to move a LV from one VG to
another, and it's also impossible to merge multiple VGs into one VG :(
How stupid is that??

This means that I must move the remaining LVs from the server to the USB
stick all at once because otherwise I'd end up with a number of VGs,
each representing one LV, rather than a number of LVs within one VG.

I could move the whole VG with all the remaining LVs to the USB stick if
the VG wasn't too large for the stick by a few extends (about 1GB).
Hence I need to shrink LVs of the VG before I can move the whole VG to
the USB stick.

I'm reading that I could first shrink the file system in a LV, then
lvreduce the LV.  However, what's inside each LV is two partitions, a
1GB swap partition and another partition with ext4.

This shows up like this:


root@heimdall:~# lvdisplay
[...]
--- Logical volume ---
  LV Path                /dev/vg_guests/lv_gulltop
  LV Name                lv_gulltop
  VG Name                vg_guests
  LV UUID                rKVBWY-vycv-KEsl-CQYL-iAbV-ipqL-WtDuWy
  LV Write Access        read/write
  LV Creation host, time heimdall, 2014-06-10 11:35:45 +0200
  LV Status              available
  # open                 0
  LV Size                10.25 GiB
  Current LE             656
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:4


root@heimdall:~# fdisk -l
[...]
                           Device Boot      Start         End      Blocks   Id  System
/dev/mapper/vg_guests-lv_gulltop1            2048     1953791      975872   82  Linux swap / Solaris
/dev/mapper/vg_guests-lv_gulltop2   *     1953792    21493759     9769984   83  Linux


Each LV was partitioned from within its VM.  Inside the VM, the above
"disks" show up as /dev/xvda1 and /dev/xvda2.  The VMs can still be
started (some are running atm).

The volume group now has 6GB free I can use to work with.


Can I remove or shrink the swap partition contained in each LV (instead
of the ext4 file system) to then shrink the whole VG so that it will fit
onto the USB stick?

This should somehow be possible because the only difference to shrinking
the file system and then the partition holding the file system is that
the swap partition is at the beginning of the LV while the partition
with the file system is at the end of the LV.  In any case, with the
swap partition removed or shrunken, less space would be occupied by what
the LV contains.  So lvreduce would have to shrink the LV at its
beginning rather than at its end --- and it needs a way to figure out
where to shrink a LV anyway.  In the end, the LVs in the VG must require
a few extends less so that I can pvmove them.

Or what do I do (letting aside making disks available over the network
with iSCSI or the like)?


(Note to self: Do not partition LVs but create LVs for swap partitions
instead.)

-- 
Again we must be afraid of speaking of daemons for fear that daemons
might swallow us.  Finally, this fear has become reasonable.


Reply to: