How to associate /dev/dm- device with the LVM logical volume

root's picture

Each LVM logical volume is represented by a dm-* file under /dev.
Sometimes it is difficult to see which dm is associated to which lv.
Fortunately the magic of shell can help out. Below you have a couple of examples.

core:~# lvdisplay|awk  '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'
dm-1 /dev/datavg/mylv
dm-2 /dev/datavg/weblv
dm-4 /dev/datavg/ftplv
dm-5 /dev/datavg/blahlv
dm-7 /dev/datavg/backups
dm-8 /dev/rootvg/homelv
dm-0 /dev/rootvg/slashlv
dm-9 /dev/rootvg/tmplv
dm-10 /dev/rootvg/usrlv
dm-11 /dev/rootvg/varlv
dm-12 /dev/rootvg/srclv
dm-14 /dev/rootvg/swap0
dm-15 /dev/rootvg/fileslv
16:16:16 root@eeny:~# ls -la /dev/disk/by-id/ | grep -i dm-name
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-dataBvg-dataB -> ../../dm-5
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-dataCvg-dataC -> ../../dm-3
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-mediaBvg-mediaB -> ../../dm-4
lrwxrwxrwx 1 root root   10 Jan 28 14:40 dm-name-mediaCvg-mediaC -> ../../dm-2
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-rootvg-home -> ../../dm-8
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-rootvg-root -> ../../dm-0
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-rootvg-swap_1 -> ../../dm-1
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-rootvg-tmp -> ../../dm-7
lrwxrwxrwx 1 root root   10 Nov 18 21:59 dm-name-rootvg-var -> ../../dm-6

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.