📜 ⬆️ ⬇️

Recover killed MBR and partition table

0. Intro.


The situation is as follows. There is a screw on 160GB. It has 2 sections - 40GB and 120GB. In order to install ubunt as a second system, a breakdown of 120GB -> 100 + 10 + 2 + 8 was made.

Further, in order to roll back the changes, the disks (10, 2 and 8) were merged back into one 20GB and formatted with NTFS. In the load to this, operations were carried out with the MBR, the result of which was her death.

Results

1. When the system is booted, the message MBR helper not found;
2. fdisk shows one big 160GB disk.
')
Fool it is clear that this is the beginning of a fun night.
Further, under the cut, address the issue.

1. Restore Partition Table


1.1. Parted magic

This LiveCD \ USB distribution , 100 MB in size carries a huge pile of software for working with disks. From breakdown to recovery.
Of these, we will need gpart , testdisk , fdisk, and ms-sys .

1.2. Gpart

gpart is a utility that scans sector-by-sector for the presence of partitions that are present on the media but not in the table. In her work, she ignores an already existing table (if present). The program was developed by the German programmer Michail Brzitwa and is no longer supported by them. Sluggish development is done by the Fedora and Debian teams. The current version is 0.1h.

The utility allows you to quickly and easily restore the partition table, but it has several drawbacks. Firstly, the development was abandoned long ago, and secondly, it sometimes does not quite correctly define sections.

gpart can work in 2 modes. This is a quick analysis and detailed scan. In some cases, the first mode is sufficient. We will look at the second.

gpart -if /dev/sda

-i - interactive mode. For each partition found, a question will be asked, save it, or skip it.
-f - full disk scan.

After quite a long time, a report will be created with possible sections. It is something that you should definitely review as carefully as possible before recording.
Report example (not mine):

Begin scan...
Possible partition(DOS FAT), size(1907mb), offset(0mb)
Possible partition(SGI XFS filesystem), size(5730mb), offset(1907mb)
End scan.
Checking partitions...
Partition(DOS or Windows 95 with 32 bit FAT, LBA): primary
Partition(Linux ext2 filesystem): primary
Ok.
Guessed primary partition table:
Primary partition(1)
type: 012(0x0C)(DOS or Windows 95 with 32 bit FAT, LBA)
size: 1907mb #s(3906544) s(16-3906559)
chs: (0/1/1)-(1023/19/16)d (0/1/1)-(12207/19/16)r
Primary partition(2)
type: 131(0x83)(Linux ext2 filesystem)
size: 5730mb #s(11736000) s(3906560-15642559)
chs: (1023/19/16)-(1023/19/16)d (12208/0/1)-(48882/19/16)r
Primary partition(3)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
Primary partition(4)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r


If everything is OK, then we agree to write to the partition table, cross our fingers and reboot.
In my case, the program identified sections that were before the breakdown (40 and 120), which did not fit and forced to look for alternative ways to restore.

1.3. testdisk

Note: this utility is described in more detail in this post , I will not repeat here.

This utility is similar to the previous one, but it has a number of advantages:
1. more recent and actively maintained;
2. subjectively, it works much faster;
3. more functional;
4. There is a simple console interface based on ncurses.

Go!
1. in the first window, select Create a new log file;
2. select the desired disk (/ dev / sda) -> Proceed;
3. mark the type of partitions as Intel;
4. select the Analyze current partition structure;
5. If the partitions found are correct, click Backup and go to step 6, you can quickly rescan the disk if there is an error somewhere (Quick search);
6. There is already a green list with sections. If ok, then write, otherwise run Deep search .;

In my case, the result was similar to the result of gpart, which is incorrect.
Having started the Deep search, after waiting for about 40 minutes, I received an answer, from which my heart felt so good.
Several partitions were found that overlapped one another (they were the original (before manipulations) 120GB and new, 100GB). Noting the unnecessary, as remote, I wrote the table to disk and rebooted. Fortunately, everything worked out and the computer returned to the state it was in, and I could go to bed with a clear conscience.

3. Recovery MBR


For this task, we have ms-sys tools in our arsenal.
First, we learn that with our MBR.

ms-sys /dev/sda
/dev/sda has an x86 boot sector
it is unknown boot sector

Now you can see that there is no boot sector on this disk.
The utility can work with the MBR of various operating systems. The list can be obtained by running the program without arguments. In my case, it was necessary from Windows 7.
Write the MBR to disk:

ms-sys -7 /dev/sda
Windows 7 master boot record successfully written to /dev/sda

Checking:

ms-sys /dev/sda
it is Microsof 7 master boot record, like the one this
program creates with the switch -7 on a hard disk device.

That's all, the necessary MBR is installed and you can reboot.

3. Outro


This post is an example of how from scratch you can create a problem for yourself and do not do half the night with what you need. But it gave invaluable experience, which I tried to present here.
Perhaps someone will find it useful. After all, it is not very difficult to get into such a situation, but there is no particular manual.

Source: https://habr.com/ru/post/117661/


All Articles