-   Linux - Newbie (
-   -   Backing up - lost boot to windows, Q about mbr,grub2,ntfsclone (

Zzipo 04-03-2013 03:45 AM

Backing up - lost boot to windows, Q about mbr,grub2,ntfsclone

This is not the continuation of the other topic, but it is related.

Step 1

Computer with MBR, only one hard disk (sda) and the next partition table:

/dev/sda1 extended 51.76 GiB
  /dev/sda5 ext4 /media/sda5 22.46 GiB 5.08 GiB 17.38 GiB
  /dev/sda6 ext4 /media/sda6 29.29 GiB 815.29 MiB 28.50 GiB
/dev/sda2 ntfs /media/sda2 win 43.95 27.11 16.84 - boot
/dev/sda3 linux-swap 2.00 GiB
/dev/sda4 ntfs /media/sda4 data 200.39 41.87 158.52

sda2 had Windows 7 OS.
sda5 had ArchLinux /
sda6 had /home

I did the next commands and store the results files in another external disk:

sfdisk -d /dev/sda > /.../sda_sfdisk.ptab
dd if=/dev/sda of=/.../sda.mbr bs=512 count=1
dd if=/dev/sda of=/.../sda.vbr bs=512 count=63
ntfsclone --save-image --output /.../windows.ntfsclone /dev/sda2
partclone.ext4 -c -s /dev/sda5 -o ~/image_sda5.pcl
partclone.ext4 -c -s /dev/sda6 -o ~/image_sda6.pcl

Step 2

I simulate that I change the computer and therefore the partitions in the system, to test if it is possible to recover the two systems + entry options (grub).

I used Gparted, and this is the next partition table:

/dev/sda1 ntfs win 50.78
/dev/sda2 logical
 /dev/sda5 ext4 linuxroot 23.55
 /dev/sda6 ext4 linuxhome 36.21
/dev/sda3 linux-swap linuxswap 2.00
/dev/sda4 ntfs data 185.55

As we see, the sda4,sda5,sda6 are coincident with the before use of them, but not in size. now, the windows OS will be in the sda1 instead of sda2, and again, with the size increased.

Step 3

I "dump" the partitions in the proper place:


ntfsclone --restore-image --overwrite /dev/sda1 /.../windows.ntfsclone
partclone.ext4 -r -s /.../image_sda5.pcl -o /dev/sda5
partclone.ext4 -r -s /.../image_sda6.pcl -o /dev/sda6

* In the whole process,everything goes correct (backing up and restoring)

* Remember that I put the flag "Boot" in the /dev/sda1 from Gparted, because in the previous system it was like that (in the /dev/sda2).

I reboot, grub2 appears and Linux is perfect, buuuuut, windows not. What shows? Only a "_" blinking in white over the whole dark screen.

Ok!, I know, the grub points to /dev/sda2, but now windows is in /dev/sda1.

Now, I'm going to shows in ministeps all the processes that I have tried during the day, with no results:

ministep 1
arch-chroot, restore grub2 with grub-mkconfig -o /boot/grub/grub.cfg
reboot, still blinking in the windows 7 loader (/dev/sda1)
I also check that the files in /dev/sda1 are about windows, and yes, correct. Also that in the menu of grub says really /dev/sda1.
In the /dev/sda1 there are "folders" with Boot, I suppose that it is because of the flag boot that I wrote from Gparted.

ministep 2
I have reboot from the USB Windows 7 installation, and instead of install, I go to the "Repair system".
First It is detected in "a weird way", after "repair and restore" (only option there), it is recognised, (Windows 7 (recovery) -- xxxx GB used - C:/ ) then appears some options, I press "Repair system - the boot of the system..
the same blinking.
* I know that there is command prompt - where i can write this there (like /fixmbr and other, but I haven't tried yet)

ministep 3
Again, from a live-cd:
ntfsresize /dev/sda1
Everything goes correct / OK
(I read about the size of the partition is not the same as the size of the filesystem, is because I did that)

ministep 4
I have reboot from the USB Windows 7 installation, and instead of install, I go to the "Repair system".
I press "Repair system - the boot of the system.. (AGAIN)
But now it detects that has some "errors to repair", after the errors are repaired (probably caused because of the ntfsresize option), I reboot.
the same blinking.

ministep 5
I have tried to disable the boot flag from /dev/sda1 , so, no partitions with boot flag.
Reboot... now, not even the grub.

ministep 6
I have tried to activate the boot flag to /dev/sda5 (I know, weird test, but I had time)
Reboot... now, not even the grub.
So, I put again in /dev/sda1 to can access the grub.

ministep 7
I try to put the same mbr that was before (when backing up).
dd if=/.../sda.mbr of=/dev/sda bs=446 count=1

ministep 8
ntfsfix --clear-bad-sectors /dev/sda1
ntfsfix --clear-dirty /dev/sda1

ministep 9
boot to USB Windows 7
Windows 7 Ultimate (recovery) 519999 MB (C:) win -> next
command prompt
write:bootrec /FixMbr
This operation comlpeted successfully.
nothing load-> just is stopped in the BIOS "screen" (where you can access F2 for Setup or F4 for Recovery.)

bootrec /?
show the different options:

ministep 10
boot to USB windows 7
...command prompt:
write: bootrec /FixBoot
This operation comlpeted successfully.

Still...nothing is loaded.

I have done arch-chroot and I see that the cfdisk is the same after these changes. The flag boot is still in sda1.

$ grub-install /dev/sda
Installation finished. No error reported.

$ grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
 WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
 No volume groups found.
[ 227.539831] SQUASHFS error: Can't find a SQUASHFS suuperblock on sda2
[ 227.544875] EXT4-fs (sda2): unable to read superblock
[ 227.549846] EXT4-fs (sda2): unable to read superblock
[ 227.554981] EXT4-fs (sda2): unable to read superblock
Found Windows 7 (loader) on /dev/sda1

Reboot... and now I have recover the grub, the option Linux works, but the option Windows 7 Loader is still with the _ (blinking).

ministep 11
Following that steps (Method 2) I do in command prompt of USB Windows 7 Repair..

$ C:
$ cd "Windows\winsxs"
$ dir /b "*.xml"
$ I try letters until get the USB flash: F:
$ COPY pending.xml "F:/pending.xml" /V
      1 file(s) copied.
$ COPY reboot.xml "F:/reboot.xml" /V
      1 file(s) copied.
$ DEL reboot.xml pending.xml
$ dir /b "*.xml"
File Not Found

Reboot... nothing, grub, windows with cursor blinking

I am going to paste here the grub.cfg part of Windows, maybe something is wrong with grub-mkconfig? I mean, not the program, but the result grub.cfg chainloader or something.

menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $.....
  insmod part_msdos
  insmod ntfs
  set root='hd0,msdos1'
  if ....
  chainloader +1

Someone says that maybe is because I had another device attached. No way.

You can think "Why he is posting here things about Windows... if maybe is in that OS the problem?" But I am posting because I did "ntfsclone" and It should work correctly. So, maybe is something with the boot connection.

Question 1
How to solve this problem? The only thing is how to "recover" and access Windows... because there are no errors, just the "_" blinking, like waiting for something.

Question 2
I want to understand better how it works. I read some manuals from /usr/share/man/.. for grub, boot,...

And also, in some "Theory" part I read that is not good use "extended partitions" for SWAP or DATA STORAGE.
And inside of extended partitions, those partitions cannot be used as "Boot" flag, because it is difficult to access/calculate...

BIOS ---> SDA --> MBR (Partition table (sfdisk access this), read the booteable flag, that is in /dev/sda1) ----> /dev/sda1 (Where to see, which sector? What reads? ---> ?? .-.-.>  /dev/sda5/boot/grub/grub.cfg???  ---> linux? ---> /dev/sda5/??
                                                                                                                                                                                                                      ----> windows 7 loader ----> /dev/sda1/ ?? NTLDR???

I don't know really how it works. What is the real connection between MBR and partition table // GRUB2 // NTLDR/WindowsBootLoader // Boot Flag.

Because I have been making tests, but without understanding really a lot how it works. I read some manuals, but there are steps that are not clear.

Question 3
Any way to see what is written in the MBR? And how to modify it?

dd if=/dev/sda of=/.../sda.mbr bs=512 count=1
cat sda.mbr shows lot of unreadable things.

syg00 04-03-2013 04:03 AM

Read the ntfsclone manpage - it specifically warns against changing partitions for Windows system partition. This is not a problem with Linux, or grub[2], or ntfsprogs. It is a problem with Windows, and its use of the registry.

There are all sorts of traps - it just isn't worth the grief - I long ago decided to leave it alone, and mess with Linux on separate disk(s). Linux is compliant enough to be able to move easily.

cliffordw 04-03-2013 04:33 AM

Hi there,

I'm afraid I don't know what is causing your problem. Just a quick post to offer some resources that might help you understand the theory, though. Check out these pages:


Good Luck!

Zzipo 04-03-2013 04:51 AM

ministep 12
I have found "relocntfs" that could solve the first sector boot problem. Then I found a new version called "ntfsreloc".
Downloaded from.
compiled and finally executed:

$ ./ntfsreloc -p /dev/sda1; echo "$?"
ntfsfixboot version 0.9
                Heads  Sectors  Start
partition:        255        63        2048
filesystem:        255        63        108546048
backup sector        0        0        0
target:                255        63        2048


$ ./ntfsreloc -w -p /dev/sda1; echo "$?"
partition:        255        63        2048
filesystem:        255        63        108546048
backup sector        0        0        0
target:                255        63        2048


When I reboot, it says:

Checking file system on \\?\Volume{afsdfasdfsdfSdfsdfsdf}
The type of the file system is NTFS
Volume label si data
Need to check for consistency... scan started.
Windows has checked the partition (chkdsk) and found no problems.

Thanks to Orgad Shaneh (ntfsreloc) and Daniel J. Grace. (relocntfs, original idea)

But I have still the questions 2 and 3.

Thanks for your answers.

I will have a look to those links, but so far I have read several things and I have some doubts on those 2 questions. Uf! The IBM link looks really great!!

syg00 04-03-2013 05:04 AM

Congratulations - good to know it; and that it worked.

Q2: Linux bootloaders don't use the boot flag at all - it is ignored. Grub[2] (at least) can boot from primary or logical partitions equally. Same may apply to lilo, but I don't use it.
The windows loaders (and some BIOS) require a boot flag on a primary partition. This is a Microsoft dictate.

Q3: The MBR is primarily binary code - by definition unreadable (in an ASCII sense). The reference to thestarman info in that ntfsreloc site is as good as you're likely to get.

Zzipo 04-03-2013 07:54 AM

Thank you all.

Finally, the "IBM" link was great!

I also found this quite useful: <-- I see that is a little mess.

To edit mbr, two options: "file" or "od -xa" to the img extracted with "dd" of the mbr sector.


All times are GMT -5. The time now is 09:36 AM.