I have a LV (Logical Volume) composed of 5 PVs (Physical Volumes). Each PV is large 100GB so the total is 500GB.

The root partition is mounted on this LV and only 250GB are used.

I must remove at least 2 PVs in order to shrink the partition to no more than 300GB (3 PVs).

How can I accomplish this safely (without data loss)?

Thank you so much!

SOLVED: kvpm does all the stuff for us (resize2fs, vgreduce, ...).

  • Whatever you do: (1) Do a full BACKUP to an external HDD/SDD/USB first. (2) Work on a non-booted system, i.e. boot from a live/install USB/CD/DVD, then work from there. In fact, the backup is best done from a live system, too.
    – Ned64
    Oct 3 '19 at 13:27
  • I known how to do a backup, but I don't know how to shrink the root partition, and be sure that the removed PVs are really empty. Oct 3 '19 at 13:40
  • 1
    Which filesystem type is used on your root filesystem? XFS can be easily extended, but shrinking is not supported at all.
    – telcoM
    Oct 3 '19 at 14:41
  • I'm using EXT4. Oct 3 '19 at 14:58

You can't shrink a mounted ext4, so you have to do this from e.g., a live CD.

First, you shrink the logical volume, including resizing the filesystem. Note that this will take a while! It may have to move a lot of data.

lvreduce -r -L 290G «vg-name»/«lv-name»

Note both -r (which tells it to resize the filesystem first, this is critical to not suffer data loss) and I also asked for a bit smaller, just to be sure no annoying rounding errors (which would mostly be rounding by the admin — e.g., did you mean 300 GiB or 300GB?). The LVM tools are precise, you could do this exactly if you want... but it's probably easier just to re-grow the filesystem at the end.

Now, you can try vgreduce to see if it can get rid of any unused volume groups. vgreduce -a «vg-name» will attempt to remove all PVs from the volume group, but will only succeed with empty ones. If this removes two, great, you're done.

If that didn't work, you'll need to move the data, which is done with pvmove. The first argument to pvmove is the PV you want to move data from; the second (optional) argument is where to move to. If you omit the second, LVM picks somewhere (other than where you moved it from). After pvmove, you can then try vgreduce «vg-name» «path-to-pv» to remove it from the volume group; again this only succeeds if there is no data on it.

After removing them from the VG, you can use pvremove to remove the LVM "labels" from the disks. Also, you must securely wipe the disks if the data previously on there needs to remain private; LVM and resize2fs has copied the data off, it has not securely erased it.

  • I did not know the "vgreduce" command: very useful and interesting, exactly what I am searching for (after resizing and lv reducing, of course). Oct 3 '19 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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