0

I had my GRUB partition of 1 MB starting at block 2049. My BIOS did not recognize it, so I decided to move it to the beginning of the disk using the command

dd if=/dev/sda5 of=/dev/sda bs=512 count=2048

Now I cannot see the partitions at all. Before the operation the first 2048 segments( 1MB) had not format at all and where unrecognized by parted.

I made an image in other disk, dev/sdc, and running gdisk on the image got

sudo gdisk -l /dev/sdc
GPT fdisk (gdisk) version 0.8.8

Caution: invalid main GPT header, but valid backup; regenerating main header from backup!

Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table instead of main partition table!

Warning! One or more CRCs don't match. You should repair the disk!

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: damaged

Found invalid MBR and corrupt GPT. What do you want to do? (Using the GPT MAY permit recovery of GPT data.)
 1 - Use current GPT
 2 - Create blank GPT

Your answer: 1
Disk /dev/sdc: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 6FEB1F15-70D6-42F9-A4B8-6E960B8C65F5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 3437 sectors (1.7 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            4096      1887105023   899.8 GiB   8300  
   2      1887105024      1920333823   15.8 GiB    8300  
   3      1920333824      1944627199   11.6 GiB    8300  
   4      1944627200      1953523711   4.2 GiB     8200  
   5            2048            4095   1024.0 KiB  EF02

sfdisk -l /dev/sdc output still is

WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util sfdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdc: 121601 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature /dev/sdc: unrecognized partition table type

No partitions found

fsck -y /dev/sdc says

sudo fsck -y /dev/sdc
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superbloque es inválido, intentando los bloques de respaldo...
fsck.ext2: Bad magic number in super-block mientras se intentaba abrir /dev/sdc

 The superbloque could not be read or does not describe a valid ext2/ext3/ext4
 sistema de ficheros.  If the dispositivo is valid and it really contains an ext2/ext3/ext4
 sistema de ficheros (and not swap or ufs or something else), then the superbloque
 is corrupt, and you might try running e2fsck with an alternate superbloque:
     e2fsck -b 8193 <dispositivo>
 or
     e2fsck -b 32768 <dispositivo>

Is there is a way to recover my partitions or at least my data? I guess writing something else in these first segments should work.

Best,

Julian

JDaich
  • 1
  • 1
    Your sda starts at sector 0, which is the partition table. so your wrote sda5 to the entire drive. The dd nickname of data destroyer is for a reason. Your partitions are supposed to start at sector 2048. Was drive gpt? if so post this: sudo gdisk -l /dev/sda. – oldfred Feb 24 '19 at 14:46
  • It is( still) supposed to bet GPT. Here is the paste – JDaich Feb 24 '19 at 19:34
  • sudo gdisk -l /dev/sda GPT fdisk (gdisk) version 0.8.8

    Caution: invalid main GPT header, but valid backup; regenerating main header from backup!

    Caution! After loading partitions, the CRC doesn't check out! Warning! Main partition table CRC mismatch! Loaded backup partition table instead of main partition table!

    Warning! One or more CRCs don't match. You should repair the disk!

    Partition table scan: MBR: not present BSD: not present APM: not present GPT: damaged

    – JDaich Feb 24 '19 at 19:35
  • Found invalid MBR and corrupt GPT. What do you want to do? (Using the GPT MAY permit recovery of GPT data.) 1 - Use current GPT 2 - Create blank GPT – JDaich Feb 24 '19 at 19:35
  • I guess have to use the first option. Finished the command with Ctr+ c however. – JDaich Feb 24 '19 at 20:48
  • Please post above, difficult to read. If in original post you can keep the formatting. If you have a backup gpt, that will recover partition table, but data at beginning of drive is gone.Not sure then what else is recoverable. – oldfred Feb 24 '19 at 21:05
  • What exactly a backup GPT is? I do not care so much about the first MB of data, but much more about /dev/sda1 that begun at sector 4096, has 300 GB of useful data and was supposed to be untouched by dd. – JDaich Feb 24 '19 at 21:13
  • Why would you think it was untouched by dd, you forced it to overwrite the beginning of the drive with partition 5 data. So whatever was partition 5 is now in effect the full drive. Best to do an image copy of drive to another drive and work on that. I would first restore backup gpt partition table as that is the original partitioning of drive. But how large was sda5, that amount of space on entire drive was overwritten, so you may have two copies or sda5 on drive and not other data where you wrote sda5. – oldfred Feb 25 '19 at 04:03
  • /dev/sda5 was 1MB long and dd wrote 1MB, so I suppose the data after the first MB was untouched. Will try to find a backup disc before do nothing. The whole /dev/sda is 1 TB – JDaich Feb 25 '19 at 07:43
  • You can see if testdisk or parted rescue can find partition(s). https://askubuntu.com/questions/665445/upgraded-to-windows-10-on-dual-boot-and-cant-boot-to-ubuntu-partition & http://www.gnu.org/software/parted/manual/html_node/rescue.html & http://www.cgsecurity.org/wiki/TestDisk – oldfred Feb 25 '19 at 14:40
  • Parted it do not seem to help

    sudo parted /dev/sda unit s print Error: /dev/sda: unrecognised disk label

    Same result with the rescue oprtion

    – JDaich Feb 25 '19 at 15:04
  • I am trying to find a TB disk to backup my data before trying to restore the partition table wit gdisk. Have a 300 GB one. It is slightly over the size of the used space of sda1 where most of my data is. Can try TestDisk but AFAIK it will need the size of the whole partition to recover or copy it. – JDaich Feb 25 '19 at 15:26
  • TestDisk output

    `Disk /dev/sda - 1000 GB / 931 GiB - CHS 121601 255 63

    Current partition structure: Partition Start End Size in sectors

    Bad GPT partition, invalid signature. Trying alternate GPT 1 P Unknown 4096 1887105023 1887100928 2 P Unknown 1887105024 1920333823 33228800 3 P Unknown 1920333824 1944627199 24293376 4 P Linux Swap 1944627200 1953523711 8896512 5 P Unknown 2048 4095 2048`

    – JDaich Feb 25 '19 at 15:44
  • The format is unclear and have no idea how to improve it. I just can see the three partitions are there and have the correct size, but not the sdaX labels. – JDaich Feb 25 '19 at 15:48
  • Comments do not allow formatting, post in your question and then you can format it. Not sure if testdisk or just recovery by using gdisk and backup partition table is better. Best to make image copy onto another drive and work on that image. Then if not correct you have a way to try again. – oldfred Feb 25 '19 at 16:57
  • Backup ongoing for already one day sudo dd if=/dev/sda of=/dev/sdc – JDaich Mar 02 '19 at 08:35
  • I do not consider dd as the best backup solution. It takes a long time as it also copies all unallocated space. So you waste lot of time copying nothing. And dd's nickname is Data Destroyer. Many have typed wrong device and destroyed all their data. Ok for image backup if careful on device order, for any drive that otherwise cannot be read. Many use ddrescue. – oldfred Mar 02 '19 at 22:08
  • Fortunately I need to use recovery tools once every two years and I am not an expert. dd stooped suddenly twice due probably to cable disconnections, so tried gddrescuesudo apt-get install gddresuce andsudo ddrescue -f -r3 PATH$/mapfile2 – JDaich Mar 04 '19 at 22:07
  • I edited again the post with the output – JDaich Mar 04 '19 at 22:41
  • Are those partitions correct or did it add a partition at beginning and several small partitions at end? If copy you can write updated partition table and see if fsck works to repair it. If not then test disk or photorec or similar tools may be required. – oldfred Mar 04 '19 at 23:45
  • Partitions are correct and the number column matches sdax order. What is the fsck code to run? Maybe fsck /dev/sdc for the whole disk? Thanks, Julian – JDaich Mar 04 '19 at 23:51
  • You do not run fsck on drive like sdc, but on partitions like sdc1, sdc2, etc and fsck is only for ext4 or ext family ext2, ext3, ext4 partitions. http://askubuntu.com/questions/642504/ubuntu-14-04-is-not-booting-normaly-after-a-manual-hard-boot/642789#642789 – oldfred Mar 05 '19 at 03:58
  • Partitions are recognizable by gdisk or testdisk but no recognized by the system. fsck says try running e2fsck -b 8193 <dispositivo> or e2fsck -b 32768 <dispositivo>. See the updated post above. I guess must run e2fsck -b assigning blocks to unexisting devices. Never did so. – JDaich Mar 05 '19 at 07:34
  • Tried mke2fs -n to get where the superblocks are and e2fsck -b at many of them. The output was allways bad magic number. – JDaich Mar 05 '19 at 08:17
  • Your sdc is not formatted, but each partition is. So you cannot run fsck on a drive like sdc. You will always get errors on fsck on sdc. What format were partitions on sdc? The fsck is only for Linux ext4. If NTFS, you have to use Windows and run chkdsk. – oldfred Mar 05 '19 at 14:40
  • Only ext4 and swap partitions. At moment I am running a deep scan on sdc with TestDisk to see is it gives me recovery options. Will try with gparted next. I saw that the options l, o, f and v should help, but first have to use -b to have a backup even the partition table does not exist. – JDaich Mar 05 '19 at 14:50
  • I need help in how to use gdisk. I understand have to choice options and use w to execute them, but this guide says it will recover my partitions and gdisk warns that will loose them. – JDaich Mar 05 '19 at 19:58
  • This is from the author of gdisk. https://askubuntu.com/questions/460233/cant-restore-my-gpt-data-with-gdisk & https://askubuntu.com/questions/386752/fixing-corrupt-backup-gpt-table/386802#386802 – oldfred Mar 05 '19 at 21:00
  • Took the risk to try it at the backup before reading your last post and worked. Thanks for all the help!! – JDaich Mar 05 '19 at 21:41

1 Answers1

0

Solved with gdisk from live USB

sudo gdisk /dev/sda

1 Option b to save partition table at USB disk as sda.gpt file

2 Option r

3 Option l to load the save sda.gpt file from USB drive

3 Option w to finish

And voile!

Previous to that I made a backup with gddrescue

sudo apt-get install gddrescue
sudo ddrescue -f -r3 /dev/sda /dev/sdc PATH$/mapfile

and performed as trials the above steps at /dev/sdc

JDaich
  • 1