Author image

Fix Windows Boot issues - Your PC needs to be repaired | The drive where Windows is installed is locked


Difficulty:
2/5


I have wrestled a few times with this unsurprisingly common BSOD, both with my own computer and on friends'. A quick online search led me to believe that many are suffering from it, so I thought about making this post to help somebody out. I know it can be alarming to see such an error for the first time, as it's a BSOD error basically totally preventing you from using your computer. But go through this article and with a little patience, we can, and we will, fix it together. (Honest!)

bsod_error

Causes

There are a few potential causes of this error:

  • corrupted file system due to power failure or malware such as a virus targeting the boot sector
  • hardware fault: eg. damaged data (SATA) cables
  • disk write errors (very unlikely nowadays)

If you've never replaced your SATA cables and you have your desktop PC for years (as I do) then I'd suggest you eliminate the hardware error probability, by first doing a thorough inspection of your disks and cables and then buying brand new SATA cables. They're very cheap, buy a few SATA III ones, be future proof, just in case.

Sata_cable

The above is my own SATA cable, if you can tell it's in fact slightly impaired on its leads due to the ordeals it suffered being stuffed in the box in a clumsy way for years. Thankfully I had spare ones to replace it and so I learned my lesson.

A tiny bit of theory

Feel free to skip.

You took all this time to search up the internet for a solution to a problem. Might as well learn a couple of things about it so you can be more aware in the future and possibly prevent it from happening again. I took the most juicy parts of relevant documentation and compressed it in 2-3 paragraphs with as succinct explanations as humanly possible - I promise!

With this error Microsoft basically tells us that it can't find a device to boot from as specified in its BCD.

The Windows boot loader includes a firmware-independent boot configuration and storage system called Boot Configuration Data (BCD) and a boot option editing tool, BCDEdit (BCDEdit.exe).

There are 3 components that make up the Windows boot loader:

  1. Windows Boot Manager (Bootmgr.exe) - this is located in the “System Reserved Partition” or plainly System partition
  2. Windows operating system loader (Winload.exe) - this is located in the Windows partition where the Windows\ folder resides
  3. Windows resume loader (Winresume.exe)

The Windows Boot Manager is generic and unaware of the specific requirements for each operating system while the system-specific boot loaders are optimized for the system that they load. That's why very similar or identical renditions of the error can occur in Windows 7, 8, 8.1, 10.

Requirements

We will need to boot into WinRE or Windows Recovery Environment. This is a sort of emergency room, made by Microsoft for Windows operating systems that can be used to test, repair and diagnose various fatal issues with Windows, including BSODs such as an unbootable Windows installation that we're up against now.

For this you need to have a physical Windows installation disk. For those of you who don't have a disk, fear not! I know we are in the digital age and most of you bought Windows digitally, including me, but there's no going around the dvd here. We need it - it's our only hope.

You can leisurely download your desired authentic Windows version from the Microsoft website, and proceed to “burn” the image into a disk (dvd). Here's some links: Windows 7, Windows 8.1, Windows 10. You will find both 32 and 64 bit versions with all languages and Windows editions available.

We will use this “image” or iso file (which is basically a bit-by-bit copy of a physical disk) and copy it into an empty DVD specifically using a completely free open source program called ImgBurn.

Of course there are a multitude of other free and paid programs that allow you to burn files to disks, but I've had an excellent experience with ImgBurn, as I've been using it for years and I urge you to give it a try. The instructions are here:

  1. download imgburn and install it
  2. download the iso file from Microsoft
  3. launch Imgburn and select “Write Image File to Disc”
  4. browse for the image file you downloadedimgburn
  5. Hit Write (the big button)

Of course on Windows 10 you can burn files out of the box without additional software, just plug in an empty disk and select BURN Files to disk and proceed with the straightforward instructions.

!!! WARNING: You must in fact burn your image into an optical media disk - dvd. DO NOT write your image file into a USB drive or other external mass media device. This is because some of the commands that we'll use don't work from a USB (at least not on all Windows versions). A bummer I know, but to prevent you from pulling your hair out for days trying to figure out what's wrong, just grin and bear it and use a DVD.

Fixes

We'll go through each step one by one and eliminate the candidate solutions. After each step restart your computer ()unless otherwise specified) and see if it boots. If it does you're all set, if not move on to the next step.

It is best to do this process with the fewest number of external USB devices and external drives plugged into the computer as possible (ideally the offending drive, keyboard and mouse). This will ensure we get no conflicts from other devices. Yes, Windows often is clunky and things tend to jam up.

I. Automated System Repair

  1. Insert your recovery bootable dvd on your computer and restart
  2. Make sure your desired problematic windows hard drive has the highest hard drive priority. And you must also make sure that your optical disk has priority over any hard disk drive. You can set this in your BIOS. Here's an image of Gigabyte GA-Z77X-UD3H motherboard BIOS:

bios

ATAPI is the optical disk drive.

  1. You will be prompted to press a button to boot to your bootable dvd
  2. choose your language
  3. you will now see Install in the center of your screen. On the lower left side you will see Repair your computer -> press itrepair
  4. Choose Advanced Options -> System Repair. Let it do its thing.

II. Disk Check

If step I. didn't do it for you restart with the bootable disk as before, but now head to Command Prompt:

startup_repair

and run the command:

chkdsk C: /f /r /v

This may take some time, because it will do a thorough complete disk check of your Windows partition. We assume that the letter assigned to it is C. It should be the same in your case, but if you want to be certain find the letter by doing diskpart and then list volume, like so:

diskpart_chkdsk

I have two “Windows” drives, one with Windows 8.1 and one with Windows 10 and the malfuctioning one is Windows 8.1 which is on partition letter (Ltr) C.

III. Bootloader status check

Once again boot into WinRE command prompt.

Run the plain command:

bcdedit

which is equivalent to running (bcdedit /enum). or:

bcdedit /v

For verbose mode output which replaces user friendly identifiers with codes.

bcdedit lists entries in Boot Configuration Data (BCD) store. What we want to find out is whether it lists a bootmgr and OS loader.

If the command outputs something along the lines of:

The boot configuration data store could not be opened.
The requested system device could not be found.

then the BCD store needs to be rebuilt. For this go to step V. Otherwise if it lists the boot manager and OS loader proceed to step IV.

Type:

exit

To exit the command prompt and restart the computer once more.

IV Fix the BCD Store

Run the following commands, one by one:

bootrec /fixmbr

Fix MBR - it should output “The operation completed successfully.”

bootrec /fixboot

Fix boot sector - it should output “The operation completed successfully.”

bootrec /scanos
bootrec /rebuildbcd

If the command doesn't find any operating system (like in the image below), or it just fails then you need to reestablish your boot Sector or system partition since the files have been corrupted; see step V.

fixing_bootrec

V. Repair the Boot Sector

Run:

bcdboot C:\Windows

again, assuming that C is the partition letter of your desired Windows partition.

BCDBoot creates the BCD store in the same partition.

If the above doesn't work use this command instead:

bcdboot C:\Windows /s F:

or even better this one:

bcdboot C:\Windows /l en-us /s F: /f ALL

The ALL flag ensures that both UEFI and BIOS boot files get copied from the Windows partition (C) to the System Partition (F). To find the appropriate letters assigned for your System, use diskpart and list volume and as we demonstrated a few steps back (step II).

You should start to get the big picture now. The Windows partition stores “backup” files of the bootable files belonging to the System partition exactly for the reason a fatal error like this comes up.

If any of the 3 commands above output:

“Failure when attempting to copy boot files.”

it means that the Windows partition is set as inactive. We must make it active. But how? Simple, using diskpart:

diskpart
list disk
select disk 0
list partition
select partition 2
active

You have to select the disk and partition numbers respectively that your Windows partition is located in. Finally press active to make the Windows partition active.

Caveat: Note that the command group above can only be used on MBR -BIOS- disks (as was my case), not on GUID GPT -UEFI- drives. To find if a disk is GPT or MBR, it will have an asterisk (*) character under the respective column when you press list disk on diskpart.

Now that we made the Windows C partition active we'll just run the bcdboot command once again.

If it still refuses to work, no need to panic! It means the boot files in the System Partition are damaged or corrupted (as often is the case). So we will have to rebuild them from scratch by copying them over from the Windows partition. Execute the following commands:

bootrec /fixmbr
bootrec /fixboot
F:
attrib F:\boot\bcd -s -h -r
ren F:\boot\bcd bcd.old
bcdboot C:\Windows /l en-us /s F: /f ALL
bootrec /rebuildbcd

For your information, the attrib command above unhides and un-protects the bcd file, such that we can rename (or delete) it as we've done here.

On Windows 10 the last command above, should output something like this:

Successfully scanned Windows installations: 1
[1] C:\Windows
Add installation to boot list? Yes(Y)/No(N)/All(A):Y

Press Y on on your keyboard to add it and it should output

“The operation completed successfully.”

Finally run:

exit

to exit the command prompt, eject the optical disk from the tray and restart the computer. It should boot to Windows normally.

Note: Always use backslashes \ (not slashes /) in Windows command line when specifying paths.

Aftermath

Now that you are (hopefully) able to log in back to Windows you should run a few more commands to make sure everything's back to normal by clearing out any leftover file corruptions.

Launch the command prompt. First run a disk check on your Windows partition:

chkdsk C: /f

Check the integrity of Windows files:

sfc /scannow

If problems were found run this command to recover the files:

DISM /Online /Cleanup-Image /RestoreHealth

Run sfc /scannow again.

If you still get some problems showing up after repeated executions, just don't worry about it, it shouldn't be anything to worry about. “Go along and we'll get along.”


Leave your comments, subscribe, contact if you wish and hope it helps.

References

  • https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/bcdboot-command-line-options-techref-di
  • https://neosmart.net/wiki/the-drive-where-windows-is-installed-is-locked/#Applicable_Systems


0 likes