« Back to all recent discussions

Recover DD-d partition info

hunandozhunandoz Posts: 16  Junior Member
edited February 17 in Discussions
Dear all,

I have unfortunately deleted my sda partition info with (dd if=/dev/zero of=/dev/sda) when I wanted to repair my SD Card partion table in sdb. :-( 
Right now system is up and running, but if I lose power, perform restart -->everything will be gone. I do not have backup possibilty of the total NAS content.
If possible I would like to recover the partitions without removing the HDD from the system. Also if possible I do not want to install debian/ubuntu onto a PC.

Thank you for your help in advance!

lsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 140M 1 loop /ram_bin
sda 8:0 0 1.8T 0 disk:
|-sda1 8:1 0 502M 0 part /zyxel/mnt/sysdisk
`-sda2 8:2 0 1.8T 0 part
`-md0 9:0 0 1.8T 0 linear /i-data/1877af91

fdisk -l:
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda doesn't contain a valid partition table


#NAS_Feb_2020
«1

Comments

  • hunandozhunandoz Posts: 16  Junior Member
    Dear All,
    if mdstat states md0 has active device  sda2 - am I ok?
    cat /proc/mdstat
    Personalities : [linear] [raid0] [raid1]
    md0 : active linear sda2[0]
          1952996928 blocks super 1.2 0k rounding

    mdadm --examine /dev/sda1
    mdadm: No md superblock detected on /dev/sda1.

    mdadm --examine /dev/sda2
    /dev/sda2:
    Magic : a92b4efc
    Version : 1.2
    Feature Map : 0x0
    Array UUID : 1877af91:c4d12aaf:62318110:85a049b4
    Name : NAS:0 (local to host NAS)
    Creation Time : Sun Mar 24 23:38:55 2019
    Raid Level : linear
    Raid Devices : 1
    Avail Dev Size : 1952996928 (1862.52 GiB 1999.87 GB)
    Used Dev Size : 0
    Data Offset : 2048 sectors
    Super Offset : 8 sectors
    State : clean
    Device UUID : 2a4ec1ab:c15d1211:dbf7ffc6:10f1e4d3
    Update Time : Sun Mar 24 23:38:55 2019
    Checksum : e2dc1423 - correct
    Events : 0
    Rounding : 0K
    Device Role : Active device 0
    Array State : A ('A' == active, '.' == missing)
  • MijzelfMijzelf Posts: 1,259  Paragon Member
    You'll have to recreate the partition table manually. You can find the start sector and size of the partitions with

    cat /sys/block/sda/sda1/start
    cat /sys/block/sda/sda1/size
    cat /sys/block/sda/sda2/start
    cat /sys/block/sda/sda2/size

  • hunandozhunandoz Posts: 16  Junior Member
    Mijzelf,
    Thank you for the starting step; Now I know the start/size for both partition. 
    cat /sys/block/sda/sda1/start
    63
    cat /sys/block/sda/sda1/size
    1028097

    cat /sys/block/sda/sda2/start
    1028160
    cat /sys/block/sda/sda2/size
    3905995905

    Can ou help me with fdisk as well?
    I am afraid as the NAS sees the volume (sda2) as JBOD [as far as I understand it], so I do not want crush it.


  • hunandozhunandoz Posts: 16  Junior Member
    I have just checked one more thing; /dev/md0 is as well existing in fdisk. 

    fdisk -l
    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

    Disk /dev/sda doesn't contain a valid partition table

    Disk /dev/md0: 1999.9 GB, 1999868854784 bytes
    2 heads, 4 sectors/track, 488249232 cylinders, total 3905993857 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

    Disk /dev/md0 doesn't contain a valid partition table

  • hunandozhunandoz Posts: 16  Junior Member
    Mijzelf,

    As far as I have checked;
    fdisk /dev/sda (am I need sudo?)
    select "n" as new partition
    select "p" as primary (? - it will "name" it as sda1?)
    enter "63"
    enter "1028097"
    repeat with sda2 data
    n, p, 1028160, 3905995905.

    How to connect it to md0? (Sorry for my poor linux knowledge)
    Thank you for your patience, and understanding,
  • MijzelfMijzelf Posts: 1,259  Paragon Member
    I have just checked one more thing; /dev/md0 is as well existing in fdisk.
    fdisk runs on any block device, and even on files. But as you can see, md0 doesn't contain a valid partition table, so it's pretty meaningless here.
    As far as I have checked;
    fdisk /dev/sda (am I need sudo?)
    By default there is no sudo on the box. If you logged in using the same credentials as you used to dd the partition table away, you don't need it.
    (? - it will "name" it as sda1?)
    Yes.
    How to connect it to md0?
    You don't need to. The partition table is not more then a database which contains the location and size of the partitions. You didn't change anything in the partition itself, so if you recover the table, the partitions will be as they always were. sda2 contains a header which tells it's a part of md0.



  • hunandozhunandoz Posts: 16  Junior Member
    Mijzelf,
    Thank you for the given instruction. 
    But I was unable to create 1st partition, as the possible value range is 2048  - 3907029167.
    I have stopped / quit from fdisk.
  • hunandozhunandoz Posts: 16  Junior Member
    Mijzelf,
    One more question. I am able to create the sda2, the id is 83 - "linux" is it OK?
  • hunandozhunandoz Posts: 16  Junior Member
    Mijzelf, 
    Sorry to asking many questions. 
    The end sector shall be 1028160 + 3905995905 = 3907029167
    Am I right?
  • hunandozhunandoz Posts: 16  Junior Member
    I have googled, and switched on "dos compatibility flag" with issue "c". Many thanks!!!
    Shall I do anything else?
  • hunandozhunandoz Posts: 16  Junior Member
    After executing "w"; I have received the following;
    I still do not know if the id 83 / linux partition is OK or not... Is there a way to check it?
    What will happen if I do partprobe  kpartx as mentioned below?

    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    WARNING: Re-reading the partition table failed with error 16: Device or resource                         busy.

    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    [email protected]:~# fdisk -l

    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x6d403b49

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1              63     1028159      514048+  83  Linux
    /dev/sda2         1028160  3907029167  1953000504   83  Linux

    Disk /dev/md0: 1999.9 GB, 1999868854784 bytes
    2 heads, 4 sectors/track, 488249232 cylinders, total 3905993857 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

    Disk /dev/md0 doesn't contain a valid partition table

  • hunandozhunandoz Posts: 16  Junior Member
    Dear Mijzelf,
    Just reading through fdisk; shall I set sda1 to bootable? 
    I am a beginner, so sorry for asking so many times...
  • MijzelfMijzelf Posts: 1,259  Paragon Member
    edited February 18
    Many questions, but you're doing fine. The generated partition table looks OK to me. for comparison, this is the partition table of my old, trusty 325:

    Disk /dev/sda: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Disk identifier: 0x604f18f3

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1              63     1028159      514048+   8  AIX
    /dev/sda2         1028160   156296384    77634112+  20  Unknown

    As you can see the first partition is identical, and the second starts on the same sector. Further the last sector of the 2nd partition is the last sector of the disk on your system, while mine has 3 sectors left. Probably because it wanted a multiple of 4096 bytes, or something like that. I suppose you did the math, about the endsector.

    The partition type is ignored, so you don't need to bother about that. The bootable flag is only used by BIOS driven PC's, and so is also ignored here.

    How many blocks did you overwrite by dd? Has sector 63 been spared?
  • hunandozhunandoz Posts: 16  Junior Member
    Ok, thank you for the help.
    Actually I do not know; as far as I remember on the screen was "512 bytes written" or something.  
    Opinion about executing "partprobe" or "kpartx"?
    Or keep system live till I will be able to backup to an ext. drive, and only after do a trial?

  • MijzelfMijzelf Posts: 1,259  Paragon Member
    When you only have written 512 bytes the disk should be recovered now.
    Opinion about executing "partprobe" or "kpartx"?
    I don't think either of them are available on the box. Nor does it help. They inform the kernel about partition on the disk, while you now want to 'inform' the disk about partitions in memory, by writing a partition table.
    A tool which could do so is TestDisk, which can scan a disk for apparent partitions, and write a partition table. In your case that can help to save the data, but the generated partition table will not be compatible with the firmware, because TestDisk will find the inner part of the raid array.
    Or keep system live till I will be able to backup to an ext. drive, and only after do a trial?
    That's your decision. I think your partition table is fine now. If it isn't, the data is still not lost (as long as you don't re-initialize the disk) but it will be a bit harder to copy it than it is now, of course.

Sign In or Register to comment.