LVM Data Recovery – Is pvcreate Destructive When Recovering an LVM2 Volume Group

data-recoveryjfslinuxlvm

I don't want to lose any data, so I'm asking if the solution Novell offers is safe to try. If not, are there safe alternatives?

Step-by-tedious-step:

  1. I have two volume groups: main and Rand; Rand is what I boot from while main is an older group.
  2. main/home stopped mounting due to a possible bad superblock. (this error)
  3. I found this Novell link suggesting vgcfgrestore yesterday, so I tried it. No bueno.
  4. I then ran fsck.jfs on /dev/main/home, which allowed it to mount. Success!
  5. This morning, I see errors. df -h shows /dev/mapper/Rand-root has 0 bytes free. Deleting a debian .iso–and more– fails to change that. (20+ gigs were free yesterday.)
  6. vgscan, pvscan–a lot of utilities fail to work due to a "disk full" error.
  7. I reboot. df -h still reports 0 bytes free, but vgscan and pvscan work now.
  8. Something one of those utilities returned led me to try vgcfgrestore Rand. No change in df -h and now main/home (mounted at /mnt/10.10/) starts spewing I/O errors.
  9. Reboot. A BIOS/SMART error on a disk along with a pvscan error saying can't find device with uuid="uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82", which blkid identifies as /dev/sdb5.
  10. fdisk -l shows:

    Disk /dev/sdb: 120.0 GB, 120034123776 bytes
    255 heads, 63 sectors/track, 14593 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00039f8a
    
    Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1   *           1          32      248832   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sdb2              32       14594   116969473    5  Extended
    /dev/sdb5              32       14594   116969472   8e  Linux LVM
    Note: sector size is 4096 (not 512)
    
  11. The Novell link says my problem fits Symptom 2 and provides a solution, but says nothing about fdisk reporting a partition error. (Which may be causing the SMART error.)

The Novell solution says to first identify the device, then run pvcreate with the UUID and device as parameters, then vgcfgrestore, vgscan, vgchange -ay, and fsck.

If I try this, is there a chance pvcreate will damage anything?

Also, for the pvcreate command, should I use /dev/sdb or /dev/sdb5 as the device?

Output:

~ » sudo vgscan                                                                                                                                                                                                                                                                                                   steven@Rand
[sudo] password for steven: 
  Reading all physical volumes.  This may take a while...
  Found volume group "Rand" using metadata type lvm2
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  Found volume group "main" using metadata type lvm2
------------------------------------------------------------
~ » sudo pvscan                                                                                                                                                                                                                                                                                                   steven@Rand
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  PV /dev/sdb5        VG Rand   lvm2 [111.55 GiB / 0    free]
  PV unknown device   VG main   lvm2 [1.36 TiB / 0    free]
  PV /dev/sda1        VG main   lvm2 [465.76 GiB / 461.76 GiB free]
  Total: 3 [1.93 TiB] / in use: 3 [1.93 TiB] / in no VG: 0 [0   ]
------------------------------------------------------------
~ » blkid                                                                                                                                                                                                                                                                                                         steven@Rand
/dev/sdb1: UUID="ba9a3955-0b9c-4660-9852-0f9f405d2f8e" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb5: UUID="uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82" TYPE="LVM2_member" 
/dev/sde1: LABEL="My Book" UUID="A2CA0AEBCA0ABC13" TYPE="ntfs" 
/dev/sdf1: UUID="5F8C6ED4773C3763" TYPE="ntfs" 
------------------------------------------------------------

~ » sudo lvs

  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  LV     VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  root   Rand -wi-ao 106.98g                                      
  swap_1 Rand -wi-ao   4.56g                                      
  home   main -wi---   1.35t                                      
  root   main -wi---   2.00g                                      
  swap   main -wi---   4.00g                                      
  tmp    main -wi--- 512.00m                                      
  usr    main -wi---   6.00g                                      
  var    main -wi---   2.00g                                      
------------------------------------------------------------
~ » sudo lvscan
  ACTIVE            '/dev/Rand/root' [106.98 GiB] inherit
  ACTIVE            '/dev/Rand/swap_1' [4.56 GiB] inherit
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  inactive          '/dev/main/swap' [4.00 GiB] inherit
  inactive          '/dev/main/root' [2.00 GiB] inherit
  inactive          '/dev/main/usr' [6.00 GiB] inherit
  inactive          '/dev/main/var' [2.00 GiB] inherit
  inactive          '/dev/main/tmp' [512.00 MiB] inherit
  inactive          '/dev/main/home' [1.35 TiB] inherit
------------------------------------------------------------
~ » sudo pvs
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  PV             VG   Fmt  Attr PSize   PFree  
  /dev/sda1      main lvm2 a-   465.76g 461.76g
  /dev/sdb5      Rand lvm2 a-   111.55g      0 
  unknown device main lvm2 a-     1.36t      0 
------------------------------------------------------------
~ » blkid
/dev/sdb1: UUID="ba9a3955-0b9c-4660-9852-0f9f405d2f8e" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb5: UUID="uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82" TYPE="LVM2_member" 
/dev/sde1: LABEL="My Book" UUID="A2CA0AEBCA0ABC13" TYPE="ntfs" 
/dev/sdf1: UUID="5F8C6ED4773C3763" TYPE="ntfs" 
------------------------------------------------------------
~ » sudo vgs
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  VG   #PV #LV #SN Attr   VSize   VFree  
  Rand   1   2   0 wz--n- 111.55g      0 
  main   2   6   0 wz-pn-   1.82t 461.76g
------------------------------------------------------------
~ » sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "Rand" using metadata type lvm2
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  Found volume group "main" using metadata type lvm2
------------------------------------------------------------
~ » sudo pvscan
  Couldn't find device with uuid uZ1fiS-5Wo4-VNzC-gzs0-ekVz-Bepn-1MZe82.
  PV /dev/sdb5        VG Rand   lvm2 [111.55 GiB / 0    free]
  PV unknown device   VG main   lvm2 [1.36 TiB / 0    free]
  PV /dev/sda1        VG main   lvm2 [465.76 GiB / 461.76 GiB free]
  Total: 3 [1.93 TiB] / in use: 3 [1.93 TiB] / in no VG: 0 [0   ]
------------------------------------------------------------

Best Answer

pvcreate writes PV metadata onto the device/partition, I think most would call that "destructive" however, since it's part of the LVM planning and layout it's also "constructive". pvcreate could be destructive to data areas if any of the following parameters were changed to increase the metadata size or location.

Depending on the command line options passed to pvcreate, one can
write multiple copies of the metadata via --[pv]metadatacopies
change the metadata size via --metadatasize
change the data alignment via --dataalignment
shift the start of the data area an additional alignment_offset via --dataalignmentoffset
recreate a previous PV by specifying the UUID --uuid

Also from the pvcreate man page.
To see the location of the first Physical Extent of an existing Physical Volume use pvs -o +pe_start

Typically, the metadata is written in the first few blocks of the device, up to the first usable PE, shown by pvs -o +pe_start and can be partially viewed by the following cmd.

dd if=/dev/sdb5 bs=4096 count=4 |less

Using less instead of od because much of the metadata is clear text and less does a good job of handling both binary and text data.

Personally, I always set metadata copies to be more than one.

Related Question