In a botched attempt to move my root partition from one disk to another I have done the following:
- added new disk
- partitioned it with parted (part #3 is now almost totally filling the disk)
-
initialized a physical volume
$ pvcreate /dev/sdb3 Physical volume "/dev/sdb3" successfully created
-
extended the volume group to include this new physical disk
$ vgextend myvg /dev/sdb3 Volume group "myvg" successfully extended
-
extended the logical volume (I think this is where I ballsed it up: I think I should have pvmove'ed stuff to the new pv in that group – can someone confirm?)
$ lvextend /dev/mapper/myvg-root /dev/sdb3
I would now like to undo the lvextend and then proceed with the original plan of moving the content of the old physical volume over to the new physical volume. Can I reduce the logical volume (I have not yet touched the ext4 partition that sits in /dev/mapper/myvg-root with something like resizefs) without fear of damaging the ext4 filesystem? If so, how do I tell it to reduce by exactly the right amount?
$ lvreduce --by-exactly-the-amount-occupied-by-PV /ev/sdb3 /dev/mapper/myvg-root
Best Answer
To summarize, currently there is an ext4 filesystem (root) inside a logical volume (myvg-root) that sits in a volume group (myvg) that is made up of two physical volumes (one of which is the newly added sdb3).
You can inspect the mapping of logical extents to physical extents with lvdisplay
You can simply reduce the size of this logical volume with lvreduce
Note how the number of logical extents on sdb3 to be reduced is 476869+1 (counting starts at 0!). That's it. Now a quick check seems to confirm the original world order:
Now a slow and tedious pvmove command should allow the moving of data over: