0

I'm trying to clone 1TB disk with PMBR partition and bad sectors. Which has working Windows partitions on it, and is bootable via MBR.
blkid doesn't recognize partitions

/dev/sdc: PTTYPE="PMBR"

gdisk /dev/sdc

    GPT fdisk (gdisk) version 1.0.7

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

Caution! After loading partitions, the CRC doesn't check out!
Warning: Invalid CRC on main header data; loaded backup partition table.
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: ERROR
Backup header: OK
Main partition table: ERROR
Backup partition table: ERROR

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

Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 

I tried in gdisk with (2) (r) (b) (w) but result didn't want to write

 Warning! Main partition table overlaps the first partition by 34 blocks!
You will need to delete this partition or resize it in another utility.

Warning! Secondary partition table overlaps the last partition by
17599083851618035976 blocks!
You will need to delete this partition or resize it in another utility.

Problem: partitions 121 and 119 overlap:
  Partition 121: 925735787758310161 to 13474437941687892909
  Partition 119: 11147454187938441805 to 15638604846186930334

Problem: partitions 121 and 120 overlap:
  Partition 121: 925735787758310161 to 13474437941687892909
  Partition 120: 3391649715396322562 to 7297187905800799496

Problem: partitions 122 and 120 overlap:
  Partition 122: 3391649715396322562 to 7297187905800799496
  Partition 120: 3391649715396322562 to 7297187905800799496

Problem: partitions 122 and 121 overlap:
  Partition 122: 3391649715396322562 to 7297187905800799496
  Partition 121: 925735787758310161 to 13474437941687892909

Problem: partitions 123 and 119 overlap:
  Partition 123: 925735787758310161 to 13474437941687892909
  Partition 119: 11147454187938441805 to 15638604846186930334

Problem: partitions 123 and 120 overlap:
  Partition 123: 925735787758310161 to 13474437941687892909
  Partition 120: 3391649715396322562 to 7297187905800799496

Problem: partitions 123 and 121 overlap:
  Partition 123: 925735787758310161 to 13474437941687892909
  Partition 121: 925735787758310161 to 13474437941687892909

Problem: partitions 123 and 122 overlap:
  Partition 123: 925735787758310161 to 13474437941687892909
  Partition 122: 3391649715396322562 to 7297187905800799496

Problem: partitions 124 and 119 overlap:
  Partition 124: 10336404087008029236 to 15113227714779688721
  Partition 119: 11147454187938441805 to 15638604846186930334

Problem: partitions 124 and 121 overlap:
  Partition 124: 10336404087008029236 to 15113227714779688721
  Partition 121: 925735787758310161 to 13474437941687892909

Problem: partitions 124 and 123 overlap:
  Partition 124: 10336404087008029236 to 15113227714779688721
  Partition 123: 925735787758310161 to 13474437941687892909
Aborting write operation!
Aborting write of new partition table.

clonezilla doesn't recognize partitions I tried gparted and Rescue system partitions but it was scanning all night and nothing.
using: cfdisk /dev/sdc works fine

                                                                              Disk: /dev/sdc
                                                        Size: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
                                                                    Label: dos, identifier: 0x9f9fd106

    Device                 Boot                              Start                   End               Sectors              Size            Id Type
>>  /dev/sdc1                                                    1                206846                206846              101M            ee GPT                        
    /dev/sdc2              *                                206848             617201663             616994816            294.2G             7 HPFS/NTFS/exFAT
    /dev/sdc3                                            617201664            1916342271            1299140608            619.5G             7 HPFS/NTFS/exFAT
    /dev/sdc4                                           1916342272            1953316862              36974591             17.6G            c0 unknown
    Free space                                          1953316864            1953525167                208304            101.7M     

                                 

How can I mount partitions under fedora or PartedMagic live? Thanks

DenisZ
  • 38
  • 7

2 Answers2

1

I ended up using tips from Nikita, and made emulation
qemu-img create -f qcow2 -b /dev/sdc -F raw /tmp/snap.qcow2
dnf install nbd
modprobe nbd
qemu-nbd -c /dev/nbd0 /tmp/snap.qcow2
gdisk /dev/ndb0
Then I used 2, r (recover), l (load MBR and create GPT - as GPT partition was corrupted), w (write to disk)
clonezilla didn't want to work as new disk was smaller and even though they suggest to use -C to skip checking target disk size in commandline, but it doesn't work. So command line for direct mirror would be (with clonezilla)
sbin/ocs-onthefly -g auto -e1 auto -e2 -j2 -r -rescue -icds -C -v -sfsck -k -pa choose -f nbd1 -t sdb

I had to manually create partitions in the new disk, format them, mount them and use rsync
The last step is to boot into Windows install USB - Repair mode. Go to command prompt
diskpart
inside choose
list vol - To list Volumes
sel vol X - Select volume of the first FAT32 partition for UEFI boot
assign letter b: - Assign letter to be able to write boot efi boot
bcdboot c:\Windows /l en-us /s c: /f All write MBR record if you need legacy boot (Assuming System disk is under C:)
bcdboot c:\Windows /s b: /f UEFI - Write EFI boot record to EFI partition so you can boot on new machines.

It has to be done manually, but it would actually be quicker then playing with clonezilla, ddrescue, trying to save/copy partitions. So if you come accross similar problem you can save some time.
Regards

DenisZ
  • 38
  • 7
0

Always begin with taking a sector-level backup of the disk. Do it with e.g. ddrescue or even something like dd conv=noerror,notrunc,sync, or whatever you see as appropriate. The low-level tools are preferred, because they give you much more control on what's going.

I suspect some of leading sectors of the disk is bad. That's why restoring of GPT doesn't work well. If that's the case (you can check this by reading dmesg or examining output of dd or logfile of ddrescue after taking a backup), you may succeed with the following: dump this sector-level backup onto the device with exactly same size as failed one. Then try to restore partition table on the cloned device.

Also, if the partition table you got with cfdisk is correct, you can try to set up partition block devices in the kernel "by hand" with partx or kpartx (please, read man partx for details).


The promising way of doing all recovery operations without using additional device of equal size is to use qemu virtual disk. You set up an image overlay of backing device, which will be your faulty disk or better its backup image file:

qemu-img create -f qcow2 -b /dev/sdX -F raw /tmp/snap.qcow2

/tmp must have enough space to accomondate all "updated" sectors, depending on the failure scale that could range from just tens of megabytes to some gigabytes. sdX is your faulty device.

Now, attach the image to the system as a network block device:

qemu-nbd -c /dev/nbd0 /tmp/snap.qcow2

You may need to load module nbd first.

Writes to the /dev/nbd0 will be end up into snap.qcow2, and reads will be performed from it, if there's such sector, and from backend device if there is still no such sector in the image. Now, do all recovery operations on the /dev/nbd0, for instance, try to fix GPT on it and then recover partitions.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45
  • Thanks @Nikita One of the problems is that my recovery disk is smaller (but original disk is not used fully), so maybe I should for larger drive. I don't exactly understand what to do once I make qemu and map nbd0 device. Should I run some recovery on it? I've also noticed (I'm fixing someone else's comp) that actually original HP machine is booting via DVD (so obviously MBR sector is corrupted on the HDD) so it can only boot via mbr on DVD, but still windows runs fine, so data is there. – DenisZ May 25 '21 at 07:45
  • The problem is that I can easily create same partitions on the new disk, and can even make disk bootable via win repair, but I can't access any partitions via linux to even manually copy data over. – DenisZ May 25 '21 at 07:48
  • I'm making copy to identical disk via `ddrescue -f -n -r2 -S -v /dev/sdc /dev/sdd /tmp/err.log` . I also mapped disk to /dev/nbd0 as instructed which works good, but still don't know what tool to use to recover partition, or checkdisk (fsck.ntfs -doesn't see partitions). – DenisZ May 25 '21 at 08:24
  • I meant you should repeat the procedure you did with `gdisk`, i.e. "2 r b w", but on the `nbd0`. Notice this is harmless, as you can always recreate the overlay image. – Nikita Kipriyanov May 25 '21 at 09:13
  • Aha, I've done it but it refuses to write it to the disk. Now I'm trying with testdisk also – DenisZ May 25 '21 at 09:18
  • Gdisk returns `Your answer: 2 Warning! Main partition table overlaps the first partition by 34 blocks! You will need to delete this partition or resize it in another utility. ` – DenisZ May 25 '21 at 09:25
  • This is probably because this partition is the protective one (shows as 1 in `cfdisk`)? I never used protective MBR, all my disks are either only MBR or only GPT. If that's the case, you may safely remove it, especially for the purposes of recovery. – Nikita Kipriyanov May 25 '21 at 10:00