📜 ⬆️ ⬇️

Unsuccessful experience in restoring pre-installed Windows 8.1 on an HP Pavilion laptop

Prehistory


A few weeks ago I won the HP Pavilion p170nr laptop with Windows 8.1 preinstalled. Since I am an avid Linux user - it was decided to install the main, working Ubuntu system, but also to leave Windows for toys and something whimsical, like a BIOS update. Greed also played a role - for 8 of them, in fact, the money was paid.

The first step was to free up disk space, since The system, according to the precepts of Microsoft, occupied all the available space with a single C drive. Google suggested that Windows finally learned to repartition its disks with regular tools. But, as it turned out, you can only reduce drive C by half. Then there were some "unmovable files", which the Windows categorically refused to move. “Unmovable files” turned out to be rollback points and swap files. After removing them and turning off swapping, we managed to start the disk trimming process up to 100GB, but after a few seconds of operation, a dialog box appeared saying that “not enough memory”. What memory, where and for what - was not reported. The disk did not have time to be heavily fragmented, but why there is still need for memory there is a mystery to me.

I had to use some kind of partition manager (I don’t remember the exact name and no longer recognize it), who promised that he could work with Windows 8, but, as a result, he killed my system partition. And completely, both his and the section with the image for recovery, although I didn’t perform any manipulations with him.

Naturally, there was nothing to restore the system with a laptop. As I found out later, HP sells them separately. And I did not bother to create something like this on my own.
')
SystemRescueCD came to the rescue. I will not describe the peripeteias with manipulations with fdisk and testdisk. But the output managed to get a structure identical to this.

image

All files seemed to be in place. testdisk regularly showed the contents of all partitions, except for Windows and MSR. The problem with Windows was, apparently, in a very large section size (it just fell out with the segmentation fault), and I did not understand what MSR is. It seems to be just storage for something even without a file system.

However, the system refused to boot. I gave a numbered error (something like 0x00000025), after trying to start the recovery tool, the message was changed to "the file \ windows \ system32 \ winload.efi is damaged or missing".

I had to download the PE image of Windows 8.1 (I found it on rutracker.ru) and dive into the study of bootloaders, images and other low-level parts. All of the following is the fruit of my research, so I was probably wrong about something.

Terms and Details


UEFI and .efi files . UEFI, as everyone knows, is a replacement BIOS with advanced features, and .efi is, in fact, executable files for it. As a rule, they contain loaders, the only purpose of which is to initialize the environment and start the OS boot. But not necessarily. For example, a memory test is implemented as an efi file.

wim images . New versions of Windows widely use files with the .wim extension. In essence, this is just an archive that is used to deploy a system. Can be broken down into volumes with the .swm extension. The dism utility is used to work with these images.

Boot order


After the start, UEFI analyzes the list of initial loaders. This is something like the start menu, which is edited by special utilities, for example efibootmgr in linux. The loaders themselves are located in the “System” section. The file system of this partition must be FAT32 (otherwise, UEFI simply will not see it). It seems to be supported by the UDF format for booting from CDs.

Downloaders are simply .efi files, which are usually located in the \ EFI \ NAME \ Boot directory. NAME is just a name, often by the name of the equipment manufacturer. In particular, in my \ EFI 2 directory there are subdirectories - HP and Microsoft, and the bootloader is configured for \ EFI \ Microsoft \ Boot \ bootmgfw.efi.

The standard Windows loader has its own boot menu. It is contained in the file \ EFI \ Microsoft \ Boot \ BCD. In essence, this is just a list of .efi files that can be run and their launch options. For example, from here starts a memory test, a system recovery environment, and normal Windows boot. This file is edited using the bcdedit utility. By the way, it was here that I had a problem after recovering the disks. One of the boot entry parameters defines the working disk for it “device partition =”. And the corresponding .efi-file will be loaded from it. But after re-creating the Windows partition, its UUID changed, so the file \ Windows \ System32 \ winboot.efi was not found. But I realized this much later, after I reformatted the entire section.

Boot order in case of failure


In the event of a Windows boot failure, the bootloader entry in BCD has a recoverysequence parameter that indicates which “point” to start in this case. This entry describes the preparation of the RAM disk from the \ Recovery \ WindowsRE \ winre.wim image from the “Recovery Tools” section and the launch of the corresponding Windows bootloader.

From the recovery environment, in turn, you can deploy the recovery image, which is stored on the appropriate section in the install.wim file (about 17GB). In addition to this, this section stores .wim files with drivers, manufacturer utilities, as well as scripts for installing all of this. My install.wim was broken into many .swm files, about 350GB in size.

On the same section, I found the winUCRD.wim file, in its size and structure very similar to winre.wim, but different in size by a couple of hundred kilobytes and containing some extra files. Perhaps some kind of workpiece for winre, which is being finalized during the installation process.

Job recovery


Everything looks quite simple - in the event of a system failure, a recovery tool is launched that tries to correct the situation, and if this is not possible, the factory state of the system is fully restored. Only, apparently, due to the complete re-creation of several disks, when I started the recovery, only a black screen appeared.

There are a few options left




At this point I decided to finish my research. A working laptop was needed by Monday, installation and configuration of Ubuntu and all the necessary took about 5 hours.

PS Gathering material for this article, I came across an interesting post explaining why the recovery tool might not run. For it in BCD, you need to specify the parameters of the RAM disk and the disk on which the installed WIndows is located (which I could also break.

PPS Yes, indeed, the point was that the device / osdevice parameter of the BCD recording with the download of the recovery tools indicated not a record with the RAM disk parameters, but it was not clear where. You can restore using the following commands ()

bcdedit /create {ramdiskoptions} /d "Ramdisk options" bcdedit /set {ramdiskoptions} ramdisksdidevice partition=Drive bcdedit /set {ramdiskoptions} ramdisksdipath \Recovery\WindowsRE\boot.sdi 

Here: Drive is the disk on which the recovery image is stored. This is not a UUID, but simply 'c:'


Now we edit the recording parameters of the startup recovery environment (you can create it again):
 bcdedit /create /d "Boot from WIM" /application OSLOADER bcdedit /set {GUID} device ramdisk=[c:]\Recovery\WindowsRE\winre.wim,{ramdiskoptions} bcdedit /set {GUID} path \windows\system32\winload.efi bcdedit /set {GUID} osdevice ramdisk=[c:]\Recovery\WindowsRE\winre.wim,{ramdiskoptions} bcdedit /set {GUID} systemroot \windows 


Here:

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


All Articles