0

I have recovered Windows7 from rescue DVD, that came together with my laptop. The recovery re-partitions the SSD drive as to factory defaults, but I would like to change that. More exactly, after recovery was completed the partitions are the following:

root@ubuntu:~# fdisk -l /dev/sda

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   419432447   209715200   27  Hidden NTFS WinRE
/dev/sda2   *   419432448   419637247      102400    7  HPFS/NTFS/exFAT
/dev/sda3       419637248   839067647   209715200    7  HPFS/NTFS/exFAT

Comments:

  • /dev/sda2 is small partition that has bootmgr and Boot.
  • Windows7 is installed on /dev/sda3, which does not have bootmgr on that partition.

Now I would like to copy Windows7 from /dev/sda3 to /dev/sda1 and make it bootable. As partitions have the same size, this is very simple in Linux:

root@ubuntu:~# dd if=/dev/sda3 of=/dev/sda1 bs=4096

After that I have changed the partition type:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   419432447   209715200    7  HPFS/NTFS/exFAT
/dev/sda2   *   419432448   419637247      102400    7  HPFS/NTFS/exFAT
/dev/sda3       419637248   839067647   209715200    7  HPFS/NTFS/exFAT

Then I have rebooted. Windows7 boots from /dev/sda3 (which becomes C:) and /dev/sda1 becomes D:. Now I make Windows7 copy bootable (see Switching my Windows 7 Boot Disk from D to C with BCDBoot and Is it possible to copy all Windows 7 files from one HD to another?):

C:\> bcdboot d:\windows /s d:
Boot files successfully created.

C:\> bootsect /nt60 d: /mbr
Target volumes will be updated with BOOTMGR compatible bootcode.
F: (\\?\Volume{b6e65e71-6179-11e5-82c7-806e6f6e6963})
Successfully updated NTFS filesystem bootcode.
\??\PhysicalDrive0
Successfully updated disk bootcode.
Bootcode was successfully updated on all targeted volumes.

Doublecheck:

C:\> bcdedit

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume2
description             Windows Boot Manager
locale                  en-US
inherit                 {globalsettings}
default                 {current}
resumeobject            {0b9ac05e-6182-11e5-b742-8dbb81fd6d74}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows 7
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {0b9ac060-6182-11e5-b742-8dbb81fd6d74}
recoveryenabled         Yes
osdevice                partition=C:
systemroot              \Windows
resumeobject            {0b9ac05e-6182-11e5-b742-8dbb81fd6d74}
nx                      OptIn

C:\> bcdedit /store D:\Boot\BCD

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=D:
description             Windows Boot Manager
locale                  en-us
inherit                 {globalsettings}
default                 {default}
resumeobject            {f38db522-680d-11e5-829a-18f46ae2d7b0}
displayorder            {default}
toolsdisplayorder       {memdiag}
timeout                 30

Windows Boot Loader
-------------------
identifier              {default}
device                  partition=D:
path                    \windows\system32\winload.exe
description             Windows 7
locale                  en-us
inherit                 {bootloadersettings}
osdevice                partition=D:
systemroot              \windows
resumeobject            {f38db522-680d-11e5-829a-18f46ae2d7b0}
nx                      OptIn
detecthal               Yes

After I have booted Linux and marked the partition bootable (one can do that on Windows, but I use the tools I am familiar with):

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   419432447   209715200    7  HPFS/NTFS/exFAT
/dev/sda2       419432448   419637247      102400    7  HPFS/NTFS/exFAT
/dev/sda3       419637248   839067647   209715200   27  Hidden NTFS WinRE

The contents of /dev/sda1 is the following (doublecheck):

root@ubuntu:~# ls -l /mnt/sda1
total 10749077
drwxrwxrwx 1 root root       4096 Sep 25 06:11 Boot
-rwxrwxrwx 1 root root     383786 Nov 20  2010 bootmgr
drwxrwxrwx 1 root root          0 Sep 23 21:50 Config.Msi
lrwxrwxrwx 2 root root         60 Jul 14  2009 Documents and Settings -> /mnt/sda1/Users
-rwxrwxrwx 1 root root 4717092864 Sep 23 21:50 hiberfil.sys
-rwxrwxrwx 1 root root 6289461248 Sep 23 21:50 pagefile.sys
drwxrwxrwx 1 root root          0 Jul 14  2009 PerfLogs
drwxrwxrwx 1 root root       4096 Sep 23 20:35 ProgramData
drwxrwxrwx 1 root root       8192 Sep 23 21:26 Program Files
drwxrwxrwx 1 root root      12288 Sep 23 21:12 Program Files (x86)
drwxrwxrwx 1 root root       4096 Sep 22 22:00 $Recycle.Bin
drwxrwxrwx 1 root root      20480 Sep 23 21:50 System Volume Information
drwxrwxrwx 1 root root       4096 Sep 23 21:05 Temp
drwxrwxrwx 1 root root          0 Sep 23 21:50 Update
drwxrwxrwx 1 root root       4096 Sep 22 21:58 Users
-rwxrwxrwx 1 root root       4112 Jul 19  2011 version
drwxrwxrwx 1 root root      24576 Sep 23 21:02 Windows

Looks good. Unfortunately when I boot I get Bootmgr is missing. Press Ctrl+Alt+Del to restart.

I have installed Grub to /dev/sda1 (overwrites default boot loader):

grub-install --force --no-floppy --boot-directory=/mnt/sda1/Boot /dev/sda1

with the following /mnt/sda1/Boot/grub/grub.cfg:

menuentry "Windows 7" {
    insmod ntfs
    insmod ntldr
    ntldr (hd0,msdos1)/bootmgr
}

Grub passed the control to bootmgr correctly, but it persistently boots from /dev/sda3. When I remove the partition /dev/sda3, the initial boot screen is shown but then nothing happens (booting just hangs).

Next I have installed ntldr to /dev/sda1 (copied NTDETECT.COM, NTLDR from 64ntfile.zip) with "native" boot sector:

C:\> bootsect /nt52 d:

and this boot.ini:

[Boot Loader]
timeout=30
Default=multi(0)disk(0)rdisk(0)partition(1)\Windows

[Operating Systems]
multi(0)disk(0)rdisk(0)partition(1)\Windows="Windows 7 (boot.ini)" /fastdetect

After boot it displays "A disk read error occurred". For sure SSD drive is unlikely to fail like that, so I think that the problem is in boot bytecode / logic that cannot correctly handle addressing / layout of the drive. I have installed Grub (as above) with this config:

menuentry "Windows 7" {
    insmod ntfs
    insmod ntldr
    ntldr (hd0,msdos1)/ntldr
}

and then I could see my menu as to boot.ini above. When I continue, the computer reboots without any error message (so I got in the loop).

How to fix the problem? Any solution to boot Windows from 1st partition is welcomed.

Other posts on the subject that I have inspected:

P.S.: No other drives or USB sticks are connected to notebook when testing.

4
  • When you are using linux / Windows dual boot i would recomend using grub boot manager. Commented Sep 29, 2015 at 10:04
  • I am not using Windows/Linux dual boot. I have only Windows.
    – dma_k
    Commented Oct 2, 2015 at 8:49
  • You're doing it wrong. Start again. This time delete the second partition after you've copied it and do not boot back into Windows. Update your boot entries from a WinRE disk or recovery.
    – qasdfdsaq
    Commented Oct 9, 2015 at 12:06
  • That's the point – I don't have recovery disk. What you say means that I cannot recover without bootrec /rebuildbcd or so. Finally after days of trying I gave up and let Windows leave on 3rd partition (/dev/sda3 in my example), however I was able to copy bcdboot from hidden partition to that one. The space in the beginning of drive I have allocated for drive D:. If you can explain why I couldn't boot from first partition (/dev/sda1) I will appreciate. Nevertheless as a last resort I have used the restore function. It has created the hidden partition again, however boot has failed.
    – dma_k
    Commented Oct 17, 2015 at 21:25

2 Answers 2

0

After you have copied sda3 to sda1 there are still some "pointers" in registry of Windows on sda1 which point to sda3. Check contents of HKLM\SYSTEM\MountedDevices\DosDevices\C: and D: if they point to correct partition. (\DosDevices\C: value is partition signature - should be signature for sda1)

To create boot files for sda1: (when booted to sda3 mapped to c:, sda1 mapped to d:)

  1. bootsect /nt60 d: /mbr - to set sda1 partition boot code (does not harm to write Windows boot code to MBR)

  2. bcdboot d:\windows /s d: - to create BCD on sda1

You don't have to edit existing System BCD on sda2 and BCD on sda1!!!

At last change active partition to sda1.

Reboot.

See How to move Windows 7 boot files to another drive/partition for help.

1
  • I did bcdboot d:\windows /s d: and bootsect /nt60 d: /mbr as you suggested (also I have updated the question with some extra information, namely with bcdedit output). I still get Bootmgr is missing. I think that is produced by code in boot sector – it cannot access Windows registry. Any further advice is welcomed.
    – dma_k
    Commented Oct 2, 2015 at 9:01
0

I wrote up some steps I took to resolve this issue and it worked for me, so I am hoping it will help future readers as well, and maybe even the OP even though it's been awhile.


Procedure I used to migrate Windows 7 from one partition on a smaller, slower hard drive to a faster hard drive partition in a Dell OptiPlex 780 MT

  1. Obtain USB flash drive(s)
    • 32 GB+ recommended
    • I used Amazon Smiles so it can generate a donation to charity while I shopped
  2. Create System Rescue CD on one of the bootable USB flash drives
    • It has become HUGE since I last used it, requiring 16 GB+
    • Follow SysResc CD instructions from Windows using Rufus
  3. Shrink volumes to minimum sizes, leaving ~40 GB free on OS partitions
    • The goal is to have enough unallocated space on the new hard drive to match or exceed the size of the original Windows 7 partition
    • Backup/move data from partitions to a USB flash drive or other external drive
    • Run disk cleanup and defrag
    • DiskMgmt.MSC in W7 can be used to extend/shrink volumes now
  4. Boot to System Rescue CD
    • Caveat: If you have BIOS system and administrator passwords that use capital letters, then System Rescue CD will think you are trying to custom boot it. It will leave you at the LILO style Boot: prompt with no instructions, help, commands, etc. to boot up. I cleared the BIOS system password so that it would reach the default boot menu
    • Once it boots successfully, run startx to get into the GUI
      • Run GPartEd
        • Go to the old slower drive with the current Windows 7 installation, and copy the Windows partition
        • Go to the new faster drive with the unallocated space, and paste the copied partiton
        • The operation could take a few minutes depending on your hardware, but provides a progress bar
        • Mark the copied Windows 7 partition as Active
      • Go to a Terminal/command window
        • Run testdisk and create/reset the boot sector of the new Windows 7 partition (Don't know if this step is necessary, but it's just what I did)
          • Google Using testdisk to restore boot sector on a partition
        • Create /mnt/Dell and /mnt/Win7 folders using mkdir
          • These will disappear when you next boot the System Rescue CD/USB stick
        • Mount the old Dell Recovery partition to /mnt/Dell using the mount command
          • mount /dev/hdb1 /mnt/Dell
        • Mount the new Windows 7 partition to /mnt/Win7
          • mount /dev/hda4 /mnt/Win7
        • Copy the Windows bootloader files to the new Windows 7 partition
          • Create /mnt/Win7/Boot folder using mkdir
          • Copy /mnt/Dell/bootmgr to /mnt/Win7/ using cp command
          • cp /mnt/Dell/boot.sdi /mnt/Win7/
          • cp /mnt/Dell/Boot/BCD /mnt/Win7/Boot/
          • You can copy the /Boot/BCD.LOG file as well, but not sure if that is necessary
          • Keep in mind that this boot configuration still points to the old Windows 7 boot and system partitions. It will need to be edited to point to the new Windows 7 boot and system partitions (same one in my case)
  5. Boot to BIOS
    • Change boot device from old drive to new drive
    • Alternatively you can use the boot menu Boot from new Windows 7 partition successfully
  6. Boot to Windows 7
    • Since it is pointing to the old boot and system partitions, it is still working off the old hard drive
    • The C: drive is the old system
    • Open a Cmd prompt as admin
      • Run DiskMgmt.MSC
        • Give the new Windows 7 partition a drive letter if it doesn't have one already assigned (G: in my case)
      • Navigate to the G:\Boot directory
        • G:
        • cd Boot
      • Show the boot configuration on the new partition using bcedit /store BCD
        • Make note of the current old boot GUID ({d57db94d-450e-11e5-a383-b8ac6f1ac098} in my case)
      • Edit the new copied boot configuration to add the new Windows 7 partition
        • Reference Adding Boot Entries
        • bcdedit /store /copy {d57db94d-450e-11e5-a383-b8ac6f1ac098} /d "Win7 Debug"
          • New W7 partition GUID now {c15e345e-9c47-11ea-a7d8-b8ac6f1ac098}
        • bcdedit /store BCD /enum /v (To view the GUIDs for reference)
        • Reference How do I move the Windows 7 boot files bootmgr to a different drive (Much appreciation for red.october posting his question and answer on this site!)
        • bcdedit /store BCD /set {bootmgr} device partition=G:
        • Additional steps in my case
          • bcdedit /store BCD /set {c15e345e-9c47-11ea-a7d8-b8ac6f1ac098} device partition=G:
          • bcdedit /store BCD /set {c15e345e-9c47-11ea-a7d8-b8ac6f1ac098} osdevice partition=G:
          • bcdedit /store BCD /displayorder {c15e345e-9c47-11ea-a7d8-b8ac6f1ac098} {d57db94d-450e-11e5-a383-b8ac6f1ac098}
          • Optionally, make the new boot partition the default
            • bcdedit /default {c15e345e-9c47-11ea-a7d8-b8ac6f1ac098}
  7. Reboot to System Rescue CD/USB
    • Use GPartEd to mark the old Windows 7 partition Hidden
    • Unmark the boot flag on the old Dell System Recovery partition
  8. Reboot to Windows 7 on the new drive

If you made no mistakes and had no difficulties or errors with any of the steps, then you like me have successfully migrated both the Windows 7 partition and the Windows 7 boot manager from one partition on the original hard drive to a new partition on a different hard drive, without using a Windows 7 recovery disk (which OEM resellers do not issue with a PC), and without using questionable third-party apps. A pleasant surprise is that if you had any EFS-encrypted files or folders before the migration, then they will still be accessible on the new partition without having to decrypt first. DiskMgmt.MSC now shows the new Windows 7 partition as C:, and the old Windows 7 partition without a drive letter.

Once booted to the new Windows 7 partition completely independent of the original hard drive, then you can explore how to clean up the boot loader on that partition to point everything to it instead of to the old Windows 7 partition. If you have a Windows XP partition on the new drive like I do, then you can add an entry to boot that using bcdedit as well. After you are confident that things are stable, then you can wipe the old partition and use it for other purposes. I truly hope this helps someone else to accomplish similar endeavors.


W7 Disk Mgmt After Migration:

W7 Disk Mgmt After Migration

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .