Found partition, but need help fixing partition tables

How to use TestDisk to recover lost partition
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Locked
Message
Author
Diverge
Posts: 4
Joined: 25 Jul 2013, 22:04

Found partition, but need help fixing partition tables

#1 Post by Diverge »

I have the following setup:

System: ESXI 5.1 w/ datastore on mSATA SSD
OS: Virtual Machine - Synology DSM 4.2
Arrary: 3 x 2TB Samsung Spinpoint F4EG HD204UI passed through to Synology VM by RDM (Raw Device Mapping)

To make a long story short. This system was running great for over a month. I went to add 4th drive to array, got an error, tried to reboot, nas locked up. Power cycled it, booted up, no more data volume.

Next I'll show the condition of my array after partiton table damage and follow that with how I went about finding my partition.

DiskStation> fdisk -l

Code: Select all

Disk /dev/sda: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1               1         311     2490240  fd Linux raid autodetect
Partition 1 does not end on cylinder boundary
/dev/sda2             311         572     2097152  fd Linux raid autodetect
Partition 2 does not end on cylinder boundary
/dev/sda3             588      243201  1948788912   f Win95 Ext'd (LBA)

Disk /dev/sdc: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sdc1               1         311     2490240  fd Linux raid autodetect
Partition 1 does not end on cylinder boundary
/dev/sdc2             311         572     2097152  fd Linux raid autodetect
Partition 2 does not end on cylinder boundary

Disk /dev/sdb: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sdb1               1         311     2490240  fd Linux raid autodetect
Partition 1 does not end on cylinder boundary
/dev/sdb2             311         572     2097152  fd Linux raid autodetect
Partition 2 does not end on cylinder boundary
SYNOLOGY> sfdisk -l

Code: Select all

DiskStation> sfdisk -l
/dev/sda1                   256         4980735         4980480  fd
/dev/sda2               4980736         9175039         4194304  fd
/dev/sda3               9437184      3907015007      3897577824   f

/dev/sdb1                   256         4980735         4980480  fd
/dev/sdb2               4980736         9175039         4194304  fd

/dev/sdc1                   256         4980735         4980480  fd
/dev/sdc2               4980736         9175039         4194304  fd

/dev/md01                     0         4980351         4980352   0
/dev/md11                     0         4194175         4194176   0
testdisk, partion table type none, no alignment. Found my missing partition: [DiskStation:2]

Code: Select all

Results
   P ext4                     0   4  5   310   7 17    4980352 [1.42.6-3202]
     ext4 blocksize=4096 Large file Sparse superblock, 2549 MB / 2431 MiB
   P Linux md 0.9 RAID        0   4  5   310   9 19    4980480 [md0]
     md 0.90.0 B.Endian Raid 1: devices 0(8,1)* 1(8,17) 2(8,33), 2550 MB / 2431 MiB
   P Linux SWAP 2           310   9 20   571  28 17    4194160
     SWAP2 version 1, pagesize=4096, 2147 MB / 2047 MiB
   P Linux md 0.9 RAID      310   9 20   571  30 35    4194304 [md1]
     md 0.90.0 B.Endian Raid 1: devices 0(8,2)* 1(8,18) 2(8,34), 2147 MB / 2048 MiB
   P Linux md 1.x RAID      588 112  5 243200  72 48 3897559304 [DiskStation:2]
     md 1.x L.Endian Raid 5 - Array Slot : 0 (0, 1, 2, failed, failed, failed), 1995 GB / 1858 GiB

interface_write()
   P ext4                     0   4  5   310   7 17    4980352 [1.42.6-3202]
   P Linux md 0.9 RAID        0   4  5   310   9 19    4980480 [md0]
   P Linux SWAP 2           310   9 20   571  28 17    4194160
   P Linux md 0.9 RAID      310   9 20   571  30 35    4194304 [md1]
   P Linux md 1.x RAID      588 112  5 243200  72 48 3897559304 [DiskStation:2]
I then calculated offset for Diskstation:2 partition, and used losetup:

Code: Select all

CHS to LBA = (588*255*63)+(112*63)+(5-1) = 9453280
Offset in bytes = 9453280*512 = 4840079360

Code: Select all

DiskStation> losetup -o 4840079360 /dev/loop1 /dev/sda
DiskStation> losetup -o 4840079360 /dev/loop2 /dev/sdb
DiskStation> losetup -o 4840079360 /dev/loop3 /dev/sdc
DiskStation> losetup
/dev/loop1: 545112064 /dev/sda
/dev/loop2: 545112064 /dev/sdb
/dev/loop3: 545112064 /dev/sdc
Examine new loop devices.

Code: Select all

DiskStation> mdadm --examine /dev/loop[1-3]
/dev/loop1:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : c7ac0e55:5cb2e968:b09f83b2:85b6356e
           Name : DiskStation:2  (local to host DiskStation)
  Creation Time : Sun May 19 18:10:54 2013
     Raid Level : raid5
   Raid Devices : 3

 Avail Dev Size : 3897559680 (1858.50 GiB 1995.55 GB)
     Array Size : 7795118592 (3717.00 GiB 3991.10 GB)
  Used Dev Size : 3897559296 (1858.50 GiB 1995.55 GB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
          State : clean
    Device UUID : 26c354ea:9679fee7:b4337841:8d291201

    Update Time : Tue Jun 11 12:00:06 2013
       Checksum : 2a2f9fe9 - correct
         Events : 18

         Layout : left-symmetric
     Chunk Size : 64K

   Device Role : Active device 0
   Array State : AAA ('A' == active, '.' == missing)
/dev/loop2:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : c7ac0e55:5cb2e968:b09f83b2:85b6356e
           Name : DiskStation:2  (local to host DiskStation)
  Creation Time : Sun May 19 18:10:54 2013
     Raid Level : raid5
   Raid Devices : 3

 Avail Dev Size : 3897559680 (1858.50 GiB 1995.55 GB)
     Array Size : 7795118592 (3717.00 GiB 3991.10 GB)
  Used Dev Size : 3897559296 (1858.50 GiB 1995.55 GB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
          State : clean
    Device UUID : e48bfdb6:7f6d61e8:3ba638d8:2f633966

    Update Time : Tue Jun 11 12:00:06 2013
       Checksum : f32308ba - correct
         Events : 18

         Layout : left-symmetric
     Chunk Size : 64K

   Device Role : Active device 1
   Array State : AAA ('A' == active, '.' == missing)
/dev/loop3:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : c7ac0e55:5cb2e968:b09f83b2:85b6356e
           Name : DiskStation:2  (local to host DiskStation)
  Creation Time : Sun May 19 18:10:54 2013
     Raid Level : raid5
   Raid Devices : 3

 Avail Dev Size : 3897559680 (1858.50 GiB 1995.55 GB)
     Array Size : 7795118592 (3717.00 GiB 3991.10 GB)
  Used Dev Size : 3897559296 (1858.50 GiB 1995.55 GB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
          State : clean
    Device UUID : dd8e1640:c64f0593:bbf07fd2:e4bca4ff

    Update Time : Tue Jun 11 12:00:06 2013
       Checksum : ba929230 - correct
         Events : 18

         Layout : left-symmetric
     Chunk Size : 64K

   Device Role : Active device 2
   Array State : AAA ('A' == active, '.' == missing)
Assembled new array:

Code: Select all

DiskStation> mdadm -A /dev/md2 /dev/loop1 /dev/loop2 /dev/loop3
mdadm: /dev/md2 has been started with 3 drives.

Code: Select all

DiskStation> cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md2 : active raid5 loop1[0] loop3[2] loop2[1]
      3897559296 blocks super 1.2 level 5, 64k chunk, algorithm 2 [3/3] [UUU]

md1 : active raid1 sda2[0] sdb2[1] sdc2[2]
      2097088 blocks [12/3] [UUU_________]

md0 : active raid1 sda1[0] sdb1[1] sdc1[2]
      2490176 blocks [12/3] [UUU_________]

unused devices: <none>
DiskStation>

Code: Select all

DiskStation> vgdisplay
  --- Volume group ---
  VG Name               vg1000
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               3.63 TB
  PE Size               4.00 MB
  Total PE              951552
  Alloc PE / Size       951552 / 3.63 TB
  Free  PE / Size       0 / 0
  VG UUID               6Lf9E0-Uruw-vS94-vaQn-TyxN-35a4-awlTUI

DiskStation> pvdisplay
  --- Physical volume ---
  PV Name               /dev/md2
  VG Name               vg1000
  PV Size               3.63 TB / not usable 2.25 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              951552
  Free PE               0
  Allocated PE          951552
  PV UUID               n5I8mM-3o67-f411-xnzi-lmr5-uh09-bnhpVr

DiskStation> lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg1000/lv
  VG Name                vg1000
  LV UUID                YGWx0P-vbWP-wHmD-4Cqs-h8R5-sKQy-Ol2GBp
  LV Write Access        read/write
  LV Status              NOT available
  LV Size                3.63 TB
  Current LE             951552
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
Activated the volume group:

Code: Select all

DiskStation> vgchange -ay
  1 logical volume(s) in volume group "vg1000" now active
Mounted the volume group:

Code: Select all

DiskStation> mount /dev/vg1000/lv /mnt -o ro
Find all my data (it's all backed up now :) :

Code: Select all

DiskStation> cd /mnt


DiskStation> ls
@appstore     @database     @download     @iSCSITrg     @spool        @tmp          Plex          aquota.group  aquota.user   downloads     lost+found    music         photo         software      video
DiskStation> cd downloads/
DiskStation> ls
KerbalSpaceProgram  nzb
DiskStation> cd nzb
DiskStation> ls
complete    incomplete
DiskStation> 

Diverge
Posts: 4
Joined: 25 Jul 2013, 22:04

Re: Found partition, but need help fixing partition tables

#2 Post by Diverge »

DiskStation> mdadm -D /dev/md2

Code: Select all

/dev/md2:
        Version : 1.2
  Creation Time : Sun May 19 18:10:54 2013
     Raid Level : raid5
     Array Size : 3897559296 (3717.00 GiB 3991.10 GB)
  Used Dev Size : 1948779648 (1858.50 GiB 1995.55 GB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Fri Jul 26 00:36:45 2013
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           Name : DiskStation:2  (local to host DiskStation)
           UUID : c7ac0e55:5cb2e968:b09f83b2:85b6356e
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       7        1        0      active sync   /dev/loop1
       1       7        2        1      active sync   /dev/loop2
       2       7        3        2      active sync   /dev/loop3
I tried to fix my partition table using sfdisk from linux live OS.

Broken partition tables (same for each drive):

Code: Select all

# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=      256, size=  4980480, Id=fd
/dev/sda2 : start=  4980736, size=  4194304, Id=fd
/dev/sda3 : start=  9437184, size=3897577824, Id= f
/dev/sda4 : start=        0, size=        0, Id= 0
My attempt at fixing partition tables:

Code: Select all

# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=      256, size=  4980480, Id=fd
/dev/sda2 : start=  4980736, size=  4194304, Id=fd
/dev/sda3 : start=  9437184, size=3897577824, Id= f
/dev/sda4 : start=        0, size=        0, Id= 0
/dev/sda5 : start=  9453280, size=3897559304, Id= fd
I tried to assemble array with partitions instead of loop devices:

Code: Select all

DiskStation> mdadm -A /dev/md2 /dev/sda5 /dev/sdb5 /dev/sdc5
mdadm: failed to add /dev/sdb5 to /dev/md2: Invalid argument
mdadm: failed to add /dev/sdc5 to /dev/md2: Invalid argument
mdadm: failed to add /dev/sda5 to /dev/md2: Invalid argument
mdadm: /dev/md2 assembled from 0 drives - not enough to start the array.
I'm stuck. Dunno why it doesn't work, or what I am doing wrong. I got someone to show me their partition tables, and everything pretty much correlates with mine (which exception of drive sizes, and even though he had only one data volume in DSM, he had 2 md partions for it, which I found odd).

Below is his partitions:

Code: Select all

ESXi> sfdisk -l
/dev/sda1               256           4980735           4980480    fd  
/dev/sda2           4980736           9175039           4194304    fd  
/dev/sda3           9437184        1953511007        1944073824     f  
/dev/sda5           9453280         488383007         478929728    fd  
/dev/sda6         488399104         976759007         488359904    fd  

/dev/sdb1               256           4980735           4980480    fd  
/dev/sdb2           4980736           9175039           4194304    fd  
/dev/sdb3           9437184         976759007         967321824     f  
/dev/sdb5           9453280         488383007         478929728    fd  
/dev/sdb6         488399104         976759007         488359904    fd  

/dev/sdc1               256           4980735           4980480    fd  
/dev/sdc2           4980736           9175039           4194304    fd  
/dev/sdc3           9437184         488383007         478945824     f  
/dev/sdc5           9453280         488383007         478929728    fd  

/dev/md01                 0           4980351           4980352     0  
/dev/md11                 0           4194175           4194176     0  

Error: /dev/md2: unrecognised disk label
get disk fail

Error: /dev/md3: unrecognised disk label
get disk fail

Here is mine (with my attempt to fix partition table - my md2 is assembled loop devices, not partitions).

Code: Select all

DiskStation> sfdisk -l
/dev/sda1                   256         4980735         4980480  fd
/dev/sda2               4980736         9175039         4194304  fd
/dev/sda3               9437184      3907015007      3897577824   f
/dev/sda5               9453280      3907012583      3897559304  fd


/dev/sdb1                   256         4980735         4980480  fd
/dev/sdb2               4980736         9175039         4194304  fd
/dev/sdb3               9437184      3907015007      3897577824   f
/dev/sdb5               9453280      3907012583      3897559304  fd


/dev/sdc1                   256         4980735         4980480  fd
/dev/sdc2               4980736         9175039         4194304  fd
/dev/sdc3               9437184      3907015007      3897577824   f
/dev/sdc5               9453280      3907012583      3897559304  fd


/dev/md01                     0         4980351         4980352   0


/dev/md11                     0         4194175         4194176   0


Error: /dev/md2: unrecognised disk label
get disk fail
sd[abc]1 = DSM (OS partition)
sd[abc]2 = swap partitions
sd[1bc]3 = extended partition for data volume ?
sd[abc]5 = logical partition for data volume ?
md0 = LVM Raid 1 for DSM ?
md1 = LVM Raid 1 for swap ?
md2 = LVM Raid 5 for data volume ?

I'm not sure I know what I am talking about. I'm trying to learn how this all works :)

I just want to thank Remy for helping me via emails and giving me things to try. If it wasn't for him my data would be lost still. But if anyone has any ideas on how to fix my partition, I'd like to learn how :)

Maybe my LVM for data volume should be split in 2 (md2 and md3) like others guys? If so, how would I find out the offset for md3 ? And if true, why does it work fine as one partition with loop devices?

User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Found partition, but need help fixing partition tables

#3 Post by cgrenier »

Concerning /dev/sda, Partition table type: Intel, after Analyse and Quick Search, if the 3 Linux Raid partitions are listed, choose Write, confirm, Quit
and proceed with the next disk. When all partitions tables are ok, reboot and it will be time to work on the logical raid itself.

Diverge
Posts: 4
Joined: 25 Jul 2013, 22:04

Re: Found partition, but need help fixing partition tables

#4 Post by Diverge »

cgrenier wrote:Concerning /dev/sda, Partition table type: Intel, after Analyse and Quick Search, if the 3 Linux Raid partitions are listed, choose Write, confirm, Quit
and proceed with the next disk. When all partitions tables are ok, reboot and it will be time to work on the logical raid itself.
Yeah, they were never listed using Intel type. The only way I had found it was using partition table type none, and no alignment, as suggested by Remy. That found me the DiskStation:2 partition info.

I'll scan it again just to be sure. But I must have done it like 20+ times so far :)

edit:
Before scan
Image
After scan
http://i.imgur.com/RiAzwtC.png
Wrote it anyway...
Image

did that for all 3 disks.

Looks like that didn't work :oops:

Image

Can't SSH into the VM anymore. Time to pass the disks through to my parted magic live OS VM and rewrite my old partition tables to see if I can get it back to previous state.

edit again: I guess this is why it didn't boot anymore heh
Image

Good thing I have old partition tables saved :)

edit again: have my partition tables back to previous state. At least this is good practice :mrgreen:

Locked