Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have two disk partitions, say sda1 and sda2, each containing a VG.

  • sda1 -> VG_SYS
  • sda2 -> VG_GUESTS

VG_SYS has a number of LV, one for every partition I needed.

The problem is that VG_SYS has gone out of space (or better, partitions made on its LVs are out of space), while VG_GUESTS has a lot of free space.

Is it possible, and how, to shrink VG_GUESTS (and eventually sda2 too) and reallocate the free space to sda1/VG_SYS?

Thanks in advance

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Assuming one LV on each VG, your process would like this:

  1. Unmount the volume on VG_GUESTS.
  2. Shrink ext3 fs on the volume that uses VG_GUESTS with resize2fs.
  3. Shrink the LV on VG_GUESTS with lvreduce.
  4. Shrink the sda2 PV with pvresize - this may fail.
  5. Refresh the VG information with vgreduce.
  6. Use a partitioning tool to modify the size of sda2 and create sda3 in the free space.
  7. Mount the volume on VG_GUESTS.
  8. Add sda3 to VG_SYS.
  9. Extend LV on VG_SYS with lvextend.
  10. Resize the file system with resize2fs (should work online, but you should be ready to boot from a LiveCD).

Scared yet? If you are, I've managed to create the correct impression. Because this is playing with fire. I can bet $5 against your single that something will go wrong, and you'll lose your data.

Instead of trying to shrink the volume, which is always difficult and dangerous, the safest approach is actually something a bit more destructive:

  1. Backup guests volume.
  2. Unmount the volume.
  3. Remove the PV from sda2 with pvremove.
  4. Use a partitioning tool to modify the size of sda2 to the size you want to add to VG_SYS, then create sda3 using the remaining space that will house the new VG_GUESTS.
  5. Create new PV on sda2, then add it to VG_SYS.
  6. Extend LV on VG_SYS with lvextend.
  7. Resize the file system with resize2fs (should work online, but you should be ready to boot from a LiveCD).
  8. Create PV on sda3, then VG on that PV, then LV on that VG, then ext3 fs on that LV, then mount it on the guests volume mount point.
  9. Restore your data to that new volume.

I've intentionally omitted the exact commands, since you should be doing this kind of thing with complete understanding of what each command does, so RTFM and good luck.

share|improve this answer
    
I followed a way quite different, but the first proposal has been a guide, so I can (with some reserves :) accept the answer. Problem solved. –  AlberT Nov 6 '09 at 19:27

You probably want something like this. However, keep in mind that it assumes you're just going to fully remove a PV from your VG, not try and shrink it down. I suspect to do what you want, you'll need a third partition (possibly on a removable USB drive) to use as temporary storage. Assuming it's /dev/sdb1, you could do something like this:

  • create a new temp logical group on /dev/sdb1 (say, VG_TEMP)
  • copy all LVs from VG_GUESTS to VG_TEMP
  • remove /dev/sda2
  • expand /dev/sda1
  • recreate /dev/sda2, re-add it as a PV to VG_GUESTS
  • copy back all LVs from VG_TEMP to VG_GUESTS

That'd be about the safest. And make sure you have backups!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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