LVM Cheat Sheet¶
This isn’t meant to be comprehensive. The basic LVM stuff is covered well elsewhere on the 'net, so this page is more about some of the weirder/more esoteric corners.
Where are the LVs stored?¶
sudo pvdisplay -m /dev/the_pv | grep dev | sort -u
-m shows the extents mapping in the selected PV. The rest of the line just pulls out the actual LV names (they all start with
/dev/ on my system) and since the extents are not guaranteed to be continuous (especially if you’ve been lvextending them over time), then there will be multiple entries for each LV. The sort at the end just consolidates them so you don’t see the same LV listed multiple times.
Moving an LV to a different PV¶
Somewhat unintuitively, you use the
pvmove command to move an LV from one PV to another:
sudo time ionice pvmove -n lv_name /dev/from_pv /dev/to_pv
Do this in a screen session so you can detach and let it run. ionice is just there to make the pvmove a background I/O task. You can safely ^C out of this and it’ll resume when you re-run pvmove. It does take considerable time to move PVs. It took 5hrs to move a 500G LV from one RAID6 to another, for example.
An Aside: mdadm info¶
Not directly related to LVM, but my PVs are actually mdadm arrays. I like to periodically back up their configuration just in case something goes sideways. I’ve only had to use this information once in the 15+y I’ve used mdadm:
mdadm --misc -D /dev/md0 > md0.txt
mdadm --misc -E /dev/sd[abcdef]1 >> md0.txt
The first line spits out the detail information about the array, including the list of physical drives/partitions in it. The second line queries (“examines”) the superblock of the physical drives/partitions and adds it to the textfile. I take this and either email it or store it off the server it came from in case things go badly and the array can’t be automatically recreated.