Help - Recover data after partition table overwritten

Mijzelf
Posts: 6199
Joined: Mon Jun 16, 2008 10:45 am

Re: Help - Recover data after partition table overwritten

Post by Mijzelf » Tue Mar 18, 2014 6:26 pm

Hm. I obviously don't use parted enough. The right command for that is

Code: Select all

parted /dev/sda unit s print
That will print the partition information in sector units. The information in GB is a bit, well, uninformative.

shadowcliffs
Posts: 21
Joined: Thu Aug 01, 2013 4:42 am

Re: Help - Recover data after partition table overwritten

Post by shadowcliffs » Wed Mar 19, 2014 4:03 pm

Donor drive:

Code: Select all

/# parted /dev/sda unit s print
Model: Seagate ST2000DM001-1CH1 (scsi)
Disk /dev/sda: 3907029168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start      End          Size         File system  Name     Flags
 1      65536s     42008576s    41943041s                 primary
 2      42010624s  3907028991s  3865018368s               primary

Drive waiting for recovery:

Code: Select all

# parted /dev/sda unit s print
Model: Seagate ST2000DM001-9YN1 (scsi)
Disk /dev/sda: 3907029168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start      End          Size         File system  Name     Flags
 1      65536s     42008576s    41943041s                 primary
 2      42010624s  3907028991s  3865018368s               primary

It looks everything is the same except for the Model number.
Mijzelf wrote:Hm. I obviously don't use parted enough. The right command for that is

Code: Select all

parted /dev/sda unit s print
That will print the partition information in sector units. The information in GB is a bit, well, uninformative.

Mijzelf
Posts: 6199
Joined: Mon Jun 16, 2008 10:45 am

Re: Help - Recover data after partition table overwritten

Post by Mijzelf » Thu Mar 20, 2014 10:44 pm

So the partition tables are identical, that cannot be the problem. Your donor disk has a version 1.1 raid array, which means the superblock is at the beginning of the partition. Somehow this superblock got damaged on your target disk. Any idea how? Your wrong direction partition table transplantation cannot have done that, I think. The partition table is only a few sectors at the beginning of the disk, and this superblock is at the beginning of the 2nd partition. Meantime the first partition, which is in between, is healthy, as far as I can see. Your box booted from it.

Anyhow, you can create a new superblock:

Code: Select all

mdadm --create /dev/md1 --level=1 --raid-devices=1 --force --assume-clean --metadata=1.1 /dev/sda2
The force is needed to let it create a single disk array. It is possible that the sequence of the parameters should be different, in that case you will get an error stating the right sequence.

If your data is valueable, it is a good idea to first create a low-level copy of the disk. If there is something else wrong than a damaged superblock, this action might worsen the situation.

shadowcliffs
Posts: 21
Joined: Thu Aug 01, 2013 4:42 am

Re: Help - Recover data after partition table overwritten

Post by shadowcliffs » Thu Mar 20, 2014 11:17 pm

The command runs without error. Here's the result after a reboot.

Code: Select all

# parted -l /dev/sda
Model: Seagate ST2000DM001-9YN1 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      33.6MB  21.5GB  21.5GB               primary
 2      21.5GB  2000GB  1979GB               primary


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/md0_vg-vol1: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system  Flags
 1      0.00B  17.2GB  17.2GB  xfs

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/md0_vg-BFDlv: 4295MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system  Flags
 1      0.00B  4295MB  4295MB  ext2


Error: /dev/mtdblock0: unrecognised disk label

Error: /dev/mtdblock1: unrecognised disk label

Error: /dev/mtdblock2: unrecognised disk label

Error: /dev/md0: unrecognised disk label

# mdadm --examine /dev/sda1
/dev/sda1:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 014ab0d0:a553a50e:35cf8e80:a58c75ef
  Creation Time : Wed Dec  5 15:01:20 2012
     Raid Level : linear
   Raid Devices : 1
  Total Devices : 1
Preferred Minor : 0

    Update Time : Wed Dec  5 15:01:20 2012
          State : active
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0
       Checksum : cca64e48 - correct
         Events : 1

       Rounding : 64K

      Number   Major   Minor   RaidDevice State
this     0       8        1        0      active sync   /dev/sda1

   0     0       8        1        0      active sync   /dev/sda1
# mdadm --examine /dev/sda2
/dev/sda2:
          Magic : a92b4efc
        Version : 1.1
    Feature Map : 0x0
     Array UUID : 2c933b23:9f50b993:59c9a92b:d45627c0
           Name : LUNAS01:1  (local to host LUNAS01)
  Creation Time : Thu Mar 20 16:00:46 2014
     Raid Level : raid1
   Raid Devices : 1

 Avail Dev Size : 3864756224 (1842.86 GiB 1978.76 GB)
     Array Size : 1932377920 (1842.86 GiB 1978.75 GB)
  Used Dev Size : 3864755840 (1842.86 GiB 1978.75 GB)
    Data Offset : 262144 sectors
   Super Offset : 0 sectors
          State : clean
    Device UUID : 1789fdb6:a254d258:7cfc5e8d:a85f4f9a

    Update Time : Thu Mar 20 16:00:46 2014
       Checksum : 71fff7e8 - correct
         Events : 0


   Device Role : Active device 0
   Array State : A ('A' == active, '.' == missing)

Compared to the working drive, what missing is following:

Code: Select all

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/6690d340_vg-lv31dd0603: 1979GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system  Flags
 1      0.00B  1979GB  1979GB  ext3
I don't really remember what exact are on that disk, so I guess it's not so important. It would be great if it can be recovered, if not, life will still go on.
Mijzelf wrote:So the partition tables are identical, that cannot be the problem. Your donor disk has a version 1.1 raid array, which means the superblock is at the beginning of the partition. Somehow this superblock got damaged on your target disk. Any idea how? Your wrong direction partition table transplantation cannot have done that, I think. The partition table is only a few sectors at the beginning of the disk, and this superblock is at the beginning of the 2nd partition. Meantime the first partition, which is in between, is healthy, as far as I can see. Your box booted from it.

Anyhow, you can create a new superblock:

Code: Select all

mdadm --create /dev/md1 --level=1 --raid-devices=1 --force --assume-clean --metadata=1.1 /dev/sda2
The force is needed to let it create a single disk array. It is possible that the sequence of the parameters should be different, in that case you will get an error stating the right sequence.

If your data is valueable, it is a good idea to first create a low-level copy of the disk. If there is something else wrong than a damaged superblock, this action might worsen the situation.

Mijzelf
Posts: 6199
Joined: Mon Jun 16, 2008 10:45 am

Re: Help - Recover data after partition table overwritten

Post by Mijzelf » Fri Mar 21, 2014 4:09 pm

Have you already tried the vgscan blurb? The filesystem you are missing is in a Logical Volume inside the new raid array. If that fails to be detected/managed/whatever I'm afraid there was more wrong than the raid superblock alone.

shadowcliffs
Posts: 21
Joined: Thu Aug 01, 2013 4:42 am

Re: Help - Recover data after partition table overwritten

Post by shadowcliffs » Fri Mar 21, 2014 6:21 pm

Code: Select all

/# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "md0_vg" using metadata type lvm2
I might have messed up something during trying to recover data with various methods.
Mijzelf wrote:Have you already tried the vgscan blurb? The filesystem you are missing is in a Logical Volume inside the new raid array. If that fails to be detected/managed/whatever I'm afraid there was more wrong than the raid superblock alone.

Mijzelf
Posts: 6199
Joined: Mon Jun 16, 2008 10:45 am

Re: Help - Recover data after partition table overwritten

Post by Mijzelf » Sun Mar 23, 2014 9:31 pm

Then I don't know how to proceed. I just have no experience with logical volumes, so I don't know how to repair it.

Post Reply