📜 ⬆️ ⬇️

Manual installation of Windows 7/8 / 8.1 / 10 in a system with GRUB2 bootloader

Surely, almost every Linux and Windows user, and I mean those who, for a number of reasons, have both systems installed, from time to time the question arose: “Is it possible, hell, to think of a way, using which one could install these systems in any order? Without spoiling the bootloader settings? ”After all, if we install Windows first and then Linux is fine, a Linux bootloader (for example, GRUB) usually picks up bootmgr. If you put in the reverse order, alas. Even using GPT + EFI. In the case of EFI, there is no danger of overwriting the MBR, but there is one nuance that I personally don’t like - the Windows installer in EFI mode does not overwrite the disk sector with its code, but overrides NVRAM, slipping the path to its bootloader. So GBUB functionality still has to be restored. In the settings of the regular installer there are no options for customizing the bootloader installation process. And what if ... do not use the standard installer? Well, or almost do not use ...



And there is such a way. And it is based on the Windows installation technology, which we have in its distributions starting with the "seven". The method works for the case of Windows versions 7/8 / 8.1 / 10, as is the case with the MBR + system BIOS, as is the case with the EFI + GPT. You can install the system both in the HDD section and on the VHD. In this case, we need the installer functionality in general to run the BCD storage configuration utility of the bootloader configuration. Instead of the installation disk, you can use WinPE-based bootable media. If the bcdedit.exe and BootICE utilities had been a * nix alternative, the entire system deployment process could have been generally performed in a Linux environment.
')


Suppose you have a computer with a GRUB2 bootloader installed on the HDD and a free partition formatted with NTFS. We will install Windows 7 Ultimate SP1. This will require:

  1. Installation CD with Windows
  2. Net flash drive> = 4 Gb
  3. Archiver 7-zip of the corresponding digit capacity
  4. The BootICE utility is desirable, but completely optional, you can get by with bcdedit.exe, included in the Windows distribution


1. Create a bootable USB flash drive



The fact is that the seven does not want to be installed in the EFI-mode from DVD. That does not want it. In addition, on the installation media, we will need additional utilities that need to be placed there, and in the case of a flash drive it is somewhat simpler than in the case of DVD.

Mount the installation image with Windows, let's say it lies in / home / $ USER / install with the name win7-setup.iso

$ mkdir ~/iso
$ sudo mount -t udf ~/install/win7-setup.iso ~/iso


Insert the USB flash drive into the USB port. Suppose it got the device name / dev / sdb . Perform its markup in the format of MBR

$ sudo fdisk /dev/sdb


Create a single partition on the flash drive. Then format it in FAT
$ sudo mkfs.vfat /dev/sdb1


Copy the contents of the distribution of Windows on the USB flash drive
$ mkdir /tmp/flash
$ sudo mount /dev/sdb1 /tmp/flash -o uid=1000,gid=100,fmask=113,dmask=002
$ cp -rv ~/iso/* /tmp/flash/


Copy EFI loader configs to a higher level

$ cp -rv ~/tmp/flash/efi/microsoft/* ~/tmp/flash/efi/


Now we need an EFI-downloader for Windows. He will have to scratch out of the distribution. This is easily done using the 7-zip archiver, which is available in the extra / p7zip repository . All the contents of the Windows distribution are compressed into a wim-format image located on the installation DVD in the file source / install.wim . Usually this image has the following structure



In the directories with the names in the form of numbers 1-4 there are different editions of Windows. To select the one you need to look inside the file with the name [1] .xml. Unpack it in / tmp

$ cd /tmp
$ 7z e ~/iso/sources/install.wim \[1\].xml


and see with the help of some browser, because in a text editor it looks awful, and I did not have a special xml editor. Each edition of Windows is described by the structure of the form



where the EDITIONID node points to the revision. INDEX parameter is just the number of the directory in which the desired revision rolls. So, I need Ultimate, and this is index 4. So pick out the bootloader from there

$ 7z e ~/iso/sources/install.wim 4/Windows/Boot/EFI/bootmgfw.efi


Okie, now transfer the resulting file to the USB flash drive

$ mv bootmgfwm.efi /tmp/flash/efi/boot/bootx64.efi


Order, now we have a bootable USB flash drive for installing Windows. Now we add to it the utilities necessary for the installation - the vindose version of the 7-zip archiver and the BootICE utility. Download the archiver from the official site and unpack it on a USB flash drive in the utils directory

$ mkdir -p /tmp/flash/utils/7-Zip/
$ cd /tmp/flash/utils/7-Zip/
$ 7z x ~/downloads/7z1602-x64.exe


We also put the bootice there

$ cp ~/install/BOOTICEx64.exe /tmp/flash/utils


Phew, everything, unmount the USB flash drive.
$ cd ~
$ sudo umount /tmp/flash/


Reboot. If you have a system with EFI and removable drives are in the boot priority, then the computer will boot into the installation of Windows automatically. If the GRUB menu appears, do not worry, click "C" and type the exit command in the console. You will be thrown out in the EFI menu, where you select the boot from the USB flash drive. If your system is with a BIOS, then it is a bit more complicated here, because we did not bother with setting the MBR on the flash drive. Then in the GRUB console we give the ls command — a list of all disks and partitions will appear. We find our flash drive, it will appear as (hdX, msdosY), where X, Y is the disk and partition number, respectively. Now we drive in commands

grub> set root=hdX,Y
grub> ntldr /bootmgr
grub> boot


Windows installer download will begin. It will load, but we do not need it - we will do everything with our hands. To make it clear what's what, you have to consider some theory

2. About the deployment of Windows from a WIM image and the capricious nature of Sysprep



Starting with the seven, installing Windows consists of the following steps.

  1. Partitioning disk in accordance with the hardware initialization system architecture. If the BIOS - installer marks the disk in the MBR. With active EFI - the markup will be GPT.
  2. Unpacking the install.wim image to the selected partition
  3. Bootloader installation and reboot
  4. Initialization of equipment. Reboot
  5. Localization, key input, system setup completion


This is the standard way. We have the same disk already marked up. And we do not need automatic installation of the bootloader - we will install it manually. The disk layout must meet the following requirements.



Thus, before unpacking the system, we must make sure that the listed requirements are met. After we unpack all the system file and install the bootloader, the system will reboot. After the reboot, the Sysprep utility will start, among other things, configuring the hardware and checking the system configuration. So, if in EFI mode, Sysprep does not find the boot loader and its configuration in the EFI partition along the EFI / microsof / boot path, and in the system with the BIOS, the \ Boot directory and bootmgr will be in the inactive partition, then Sysprep will end with a sysprep generalize error , and in the log located at \ Windows \ Panther \ sysperr.log spits out something similar to

2015-03-11 16:55:42, Error [0x0e00b3] TOOL Sysprep_Specialize_Bcd: There was an error opening the system store. Status=[0xC0000098]
2015-03-11 16:55:42, Error [0x0f0082] SYSPRP LaunchDll:Failure occurred while executing 'c:\Windows\System32\spbcd.dll,Sysprep_Specialize_Bcd', returned error code 1006
2015-03-11 16:55:42, Error [0x060435] IBS Callback_Specialize: An error occurred while either deciding if we need to specialize or while specializing; dwRet = 0x3ee


and no dancing with a tambourine will help us. Winda requires that the boot loader lay in the boot partition and point. In the case of the BIOS, we simply make active the NTFS partition in which the Windows resides and put the boot loader there too. It will still be loaded with the help of GRUB, and it doesn’t matter what section will be active. In the case of EFI, the boot loader will have to be placed next to GRUB in the EFI partition.

3. Unpacking the system



So, we define where we want to put Windows. You can put in the NTFS-partition, but you can put in the VHD-disk. That's what you want. I’ll show an example process with an EFI virtual machine with the following markup.

The protective MBR's 0xEE partition is oversized! Auto-repairing.

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/loop1: 104857600 sectors, 50.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0D217C93-6699-435A-9BBB-61DFAA6F30B7
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 104857566
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number Start (sector) End (sector) Size Code Name
1 2048 206847 100.0 MiB EF00 EFI system partition
2 206848 104855551 49.9 GiB 0700 Basic data partition


There is no Linux on this disk, only GRUB is installed in the EFI partition. If we put the system directly into the NTFS partition, then we boot from the flash drive, wait for the installation program to start, and press Shift + F10 to bring up the console. Run the diskpart utility and view the list of mounted volumes.

X:\sources> diskpart
DISKPART> list vol




We see that the flash drive (8 GB capacity) is connected as a C: drive, and the partition for installation is not mounted at all. Disorder. Do so

DISKPART> sel vol 3
DISKPART> remove
DISKPART> assign letter=E
DISKPART> sel vol 1
DISKPART> assign letter=C
DISKPART> list vol
DISKPART> sel vol 2
DISKPART> assign letter=F


Now the order, the disk on which we will install the Windows became the disk C :, the flash drive - the disk E :, and the EFI partition - the disk F:



If we want to put the system on the VHD, then do so

DISKPART> sel vol 3
DISKPART> remove
DISKPART> assign letter=E
DISKPART> sel vol 1
DISKPART> assign letter=G
DISKPART> exit


For the order create a directory with images
X:\sources> md G:\vhd
X:\sources> diskpart


Create a virtual disk, create GPT markup and an NTFS partition on it and mount it to C:

DISKPART> create vdisk file="G:\vhd\win7.vhd" maximum=25600 type=fixed
DISKPART> attach vdisk
DISKPART> clean
DISKPART> convert gpt
DISKPART> create part primary
DISKPART> format fs=ntfs quick
DISKPART> assign letter=C


EFI partition mounted to F:

DISKPART> sel vol 2
DISKPART> assign letter=F


We get this picture



Very important! We are convinced that the EFI partition is formatted in FAT, and not in FAT32. Otherwise, Sysprep will not forgive us for this error. If the computer already has Linux, then the settings will be correct.

Now unpack the distribution kit on the C drive:

X:\sources> E:
E:\> utils\7-Zip\7zFM.exe


The 7-zip archiver GUI opens. In it, open the E: \ sources directory, find the file install.wim there



Right-click on this file to bring up the context menu and go to 7-zip -> Open archive. The image content will appear.



We climb in folder 4 - there is Ultimate



Select all Ctrl + A and click the button "Extract". A window will appear where we will be asked to specify the unpacking path.



Specify the root of the C: drive and click OK.



Well, now, as they say: "Lean back and ..."

4. Install and configure the bootloader



So, after some waiting time, the unpacking is over. And here, here in this place, the Windows objno makes byaku, namely, it spoils the MBR or reconfigures NVRAM. But we will not let her do this - we will install the bootloader manually.

In the case of EFI, go to the EFI partition mounted to F: and create the necessary paths and copy the bootloader files

E:\> F:
F:\> mkdir EFI\microsoft\boot
F:\> xcopy C:\Windows\Boot\EFI\* F:\EFI\microsoft\boot /s /e
F:\> mkdir EFI\microsoft\boot\Fonts
F:\> xcopy C:\Windows\Boot\Fonts\* F:\EFI\microsoft\boot\Fonts\ /s /e
F:\> copy C:\Windows\System32\config\BCD-Template F:\EFI\microsoft\boot\BCD


Ok, bootloader copied. Now tune it

F:\> E:\utils\BOOTICEx64.exe


Open the file F: \ EFI \ Microsoft \ Boot \ BCD. In case of installation on a partition, its parameters are set as follows.



If we installed the system on VHD, then the settings will be



Important! The name of the secondary bootloader for the EFI system is winload.efi , for the BIOS system - winload.exe .

In case we install the BIOS, the boot loader installation will look like this

F:\> mkdir C:\Boot
F:\> xcopy C:\Windows\Boot\PCAT\* C:\Boot /s /e
F:\> mkdir C:\Boot\Fonts
F:\> xcopy C:\Windows\Boot\Fonts\* C:\Boot\Fonts /s /e
F:\> copy C:\Boot\bootmgr C:\bootmgr
F:\> copy C:\Windows\System32\config\BCD-Template C:\Boot\BCD


Important! The partition mounted to C: (where the bootloader is located) must be active! Verify this before rebooting!

The configuration is done the same way using BootICE.

Well, everything seems to be. Close all windows and go to reboot. The flash drive can be pulled out of the computer.

5. Fingers crossed and prayers to you, O Great and Terrible Sysprep ...!



GRUB is not yet set up an item for Windows in the menu. As soon as the GRUB menu appears, click "C". In the console we type

grub> set root=hdX,Y
grub> chainloader /EFI/Microsoft/Boot/bootmgfw.efi
grub> boot


X, Y - respectively, the disk and partition where the boot loader lies. This is the case of EFI. In the case of the BIOS, we do this

grub> set root=hdX,Y
grub> ntldr /bootmgr
grub> boot


X, Y - disk and partition from NTFS. Where the Windows is unpacked and its bootloader lies.

In EFI mode, instead of the Windows logo, I saw a black screen, since I did not find the bootres.dll in the distribution kit, which should be placed in the EFI \ Mictosoft \ Boot \ Resourses folder. In the case of the BIOS, everything is in order - the familiar emblem of the "seven". And then in both cases we will see it.



This is running Sysprep. At 57% the screen will blink - the video is configured. And if we did everything correctly, the “Application of system parameters” sign will hang for quite a long time, then the system will inform you that the installation will continue after a reboot. If we screw up somewhere with the bootloader installation - the wrong EFI partition or inactive NTFS, then there will be an error :( But we are great and we will succeed, and after the next reboot we will see it



and then finally this



Then everything is as in the usual, regular installation.

6. Configure GRUB



We noticed that every time we load the system from the GRUB console with our hands. This is very good - it means neither MBR nor NVRAM is overwritten by insidious Microsoft. The time has come to load into the arch and add a new item to the GRUB menu.

menuentry 'Windows 7 Ultimate SP1 (EFI)' {

set root=hdX,Y
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}


in the case of EFI. Or

menuentry 'Windows 7 Ultimate SP1' {

set root=hdX,Y
ntldr /bootmgr
}


in the case of the BIOS. Apply the GRUB settings and reboot and see the system in the boot menu item



after choosing which we get the loaded Windows



Conclusion



Anticipating the anger of professional win-admins, I will say right away - I know about DISM . It is information about this system that led me to the solution described. The goal was one - to find out how much need Windows actually needs to install Windows.

It turned out that - to install Windows, its environment is needed only for one thing - to set up BCD storage. Everything. The rest can be done from the environment of any other operating system.

If you write an analogue of bcdedit.exe under Linux, then you can install Windows from Linux Live media.

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


All Articles