How to recreate LVM device files under /dev directory using vgmknodes

After a server crash or due to a human error, volume group device files are not seen under /dev directory. The device files were removed from the filesystem after the system crash, probably due to a filesystem corruption.

# cd /dev
# ls vg01
ls: cannot access vg01: No such file or directory

If you check the output of lvdisplay command you would see the vg intact and without any error.

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                iP1MbY-LPMY-nmym-iY2B-CCRJ-ElVY-5L1mql
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-11 21:39:45 +0530
  LV Status              not available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

Creating LVM devices

1. The command vgcfgrestore would fail if you try to recover the volume group using the backup.

# vgcfgrestore -f /etc/lvm/backup/vg01 /dev/sdc

2ba3ce899000-2ba3ce89a000 rw-p 2ba3ce899000 00:00 0
2ba3ce8a5000-2ba3ce8aa000 rw-p 2ba3ce8a5000 00:00 0
2ba3ce8aa000-2ba3d1e83000 r--p 00000000 fd:00 77807        /usr/lib/locale/locale-archive
7fff26a43000-7fff26a58000 rw-p 7ffffffea000 00:00 0        [stack]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0    [vdso]
Aborted

2. In order to recreate the LVM devices under /dev/ you will have to use the vgmknodes command. Use the vgmknodes command with verbose options :

# vgmknodes -vv
Related Post