Tuesday, January 29, 2019

Repair the Boot Files (bcdedit) in Windows Server

Introduction

When booting to the Windows Recovery Environment (WinRE), the drive letters are assigned on a first-come, first-serve basis. For example, the C: drive in Windows will often have a different letter in WinRE. The DiskPart utility can be used to keep track of the drives and what is stored on them.
  • First Partition: 100 MB System Reserved (No drive letter)
  • Second Partition: 60 GB (C:) OS
  • Third Partition: 1.5 TB (D:) Data
  • DVD Drive: E:


Figure 1: Illustration of Drive lettering in Windows and WinRE
Note: If there is no System Reserved partition. It is okay to select the drive containing the Windows folder.


Restoring Boot Files

  1. Boot to the Windows Server DVD.
  2. Open the command prompt.
    1. Server 2008 R2 and other OSes:
      1. If no driver is needed, press Shift-F10 to open the command prompt.
      2. Continue with step 3.
    2. Server 2008 (or 2008 R2 if a driver is required)
      1. Click Next at the first screen.
      2. Click Repair your computer.
      3. If no driver is needed, click Next and proceed to step vii below.
      4. If a driver is needed, click Load Drivers.
      5. Insert the media containing the needed driver.
        Note: The media can be a CD, DVD, or USB storage device
      6. Navigate to the folder containing the driver, select it, and click Open.
      7. Click Command Prompt.
  3. The command prompt appears.
  4. Type DiskPart at the command prompt.


    Figure 2: DiskPart result (english only)

  5. Type List vol at the DiskPart prompt.
  6. Write down the drive letter of the DVD drive. In this example, it is F.
  7. Write down the drive letter of the system reserved drive. In this example, it is C.
  8. Type Select vol 1 (assuming volume 1 is the System Reserved volume, as it is here).
  9. Type active. This sets the selected volume as active.
  10. Type exit to return to the command line.
  11. Type Copy f:\BootMgr c:\ at the command prompt. One of two things will happen:
    1. If the file Bootmgr already exists on C:, type N to avoid overwriting it.
    2. If the file Bootmgr doesn't already exist on C:, it will automatically be copied.
  12. Type Bootrec /Fixmbr at the command prompt.
  13. Type Bootrec /Fixboot at the command prompt.
  14. Type Bootrec /rebuildBCD at the command prompt.
    1. If no OS is found, the following appears:


      Figure 3: Result when no OS is found (English only)


      This means that one of the following is true:
      1. The boot configuration database (BCD) already exists.
      2. The OS is not there.
      3. The OS is damaged beyond the ability of BootRec to recognize it.
    2. If BootRec /RebuildBCD succeeds, it will list any installations of Windows that it found. Press Y to accept and add them to the BCD.
  15. The server is now configured to boot from the proper partition. Close the command prompt and reboot the system into normal mode