In this article I want to consider the issues of installing on an external USB-drive not the usual set of resuscitation tools, but a full-fledged working OS that you can carry with you. And if Linux is installed out of the box on any device and works without problems, then Windows is not installed and does not work.
Also, a
section of this article may be useful when booting Windows on new hardware (when updating a motherboard, etc.).
Initially, there were 2 contradictory demands of the soul: “I carry everything with me” and “I don’t want to be loaded,” which ultimately resulted in the installation of Ubuntu on an external disk. Everything was wonderful, but there was some kind of incompleteness. And I decided to install Windows 7 there too.
But there were problems:
- Windows 7 warns of the impossibility of booting from USB (which cares) and does not want to be installed on it;
- The installer does not know how to work with VHD;
- When you boot Windows 7 with USB storage, BSOD appears.
And they were successfully resolved.
We will need
- The external USB drive itself (in this case, USB-HDD) with partitions created.
- Virtual machine (in this case I will rely on VMWare Player).
- It is worth noting that you can use the ImageX utility from the WAIK (Windows Automated Installation Kit, available for free download from the developer’s site) to unpack the install.wim, you can read about it in other articles, for example, here , but my soul was very much against downloading something extra, so I decided to get by with VMWare already installed (VMWare Player is available for free download)
- Windows 7 Enterprise or Ultimate (only they support the Native VHD boot). But you can use another version and put it on the physical partition, and not on the VHD - in this case, you just need to skip the console manipulations during installation.
Go
In the virtual machine settings, we connect to the Windows 7 CD-ROM and add the HDD: “Use physical disk” -> select the disk corresponding to USB (most likely, it is the last). It is worth noting that other disks at this stage are best removed from the virtual machine. Boot from the CD and get into the installer.
')
Installation
Now is the time to point the VHD installer. The command Shift + F10 opens the console. Suppose we want to install Windows on C: \ win7.vhd:
diskpart
create vdisk file=C:\win7.vhd type=fixed maximum=25000
select vdisk file=C:\win7.vhd
attach vdisk
create partition primary
list volume
Make sure we have 3 volume with Fs: UDF, NTFS, RAW. Well, or more, if the disk has other sections.
Now you can leave the console and go to the direct installation. When choosing an installation destination, we should see Disk 1 Partition 1, which, when selected, will carefully warn Windows 7 about possible problems, but will allow it to continue.
Now you can sit back and relax. Upon completion of this step, the installer should write the bootloader to a physical partition that will start Windows from a virtual disk. As a result, we get a working Windows 7 inside the virtual machine. It's time to get ready to run from USB.
Setup to run from USB
I am not particularly familiar with the features of Windows 7 bootup, but briefly the essence is something like this: the bootloader reads the kernel and the most important drivers (to which USB does not apply) and transfers control to the kernel, which should read everything else, but in our case it will not find anything. Accordingly, the option itself suggests itself: you must tell the bootloader that USB is crucial and you need to load it first and then transfer control. And, characteristically, Microsoft gave such opportunities: you need to set the Start key to 0 in the registry at [HKLM / System / CurrentControlSet / services / usb *] addresses. The most annoying thing is that periodically this field itself is reset to 3, judging around when new devices appear. But this is not a problem. There are 2 possible solutions (the essence of which, of course, is the same):
- usbbotfix.bat - I liked it more, because the batch file is easy to edit. I added improvements from here and I added: disabling the creation of 8.3 names, disabling the update of the last access time (well, why do we need extra write operations) and the prohibition of deleting pages with executable code so that the USB driver code is not accidentally dropped (it is quite possible that this is not necessary) , but better to be safe). This file will also tell the scheduler to call it during Event 20003 - i.e. when adding new devices.
The content of the file is:
@echo off
if "%1"=="fix" goto :fix
rem -- install task
copy /y "%~f0" "%SystemRoot%\system32\usbbootfix.bat"
SCHTASKS /Create /RU SYSTEM /SC ONEVENT /MO "*[System[Provider[@Name='Microsoft-Windows-UserPnp'] and EventID=20003]]" /EC System /TN USBBootFix /TR "'%SystemRoot%\system32\usbbootfix.bat' fix" /F
rem -- apply other settings
fsutil behavior set disablelastaccess 1
fsutil behavior set disable8dot3 1
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v DisablePagingExecutive /t REG_DWORD /d 1 /f
reg add HKLM\SYSTEM\CurrentControlSet\services\pciide /v Start /t REG_DWORD /d 0x0 /f
reg add HKLM\SYSTEM\CurrentControlSet\services\msahci /v Start /t REG_DWORD /d 0x0 /f
reg add HKLM\SYSTEM\CurrentControlSet\services\intelide /v Start /t REG_DWORD /d 0x0 /f
reg add HKLM\SYSTEM\CurrentControlSet\services\viaide /v Start /t REG_DWORD /d 0x0 /f
rem -- run :fix once after install
:fix
call :fixservice usbehci "Boot Bus Extender"
call :fixservice usbohci "Boot Bus Extender"
call :fixservice usbuhci "Boot Bus Extender"
call :fixservice usbhub "System Bus Extender"
call :fixservice usbstor "SCSI miniport"
goto :eof
:fixservice
setlocal
set Start=
set Group=
for /f "skip=2 tokens=1,2,*" %%I in ('reg query HKLM\SYSTEM\CurrentControlSet\services\%~1') do (
if "%%I"=="Start" set Start=%%K
if "%%I"=="Group" set Group=%%K
)
if not "%Start%"=="0x0" reg add HKLM\SYSTEM\CurrentControlSet\services\%~1 /v Start /t REG_DWORD /d 0x0 /f
if not "%Group%"=="%~2" reg add HKLM\SYSTEM\CurrentControlSet\services\%~1 /v Group /t REG_SZ /d "%~2" /f
endlocal
goto :eof
- UsbBootWatcher.exe is a time-tested solution, is installed as a service and is called when the registry keys that we select are changed. You can take it here .
If the system does not boot
If we have already arrived at a new place and it turned out that the OS does not want to start up, it will have to be repaired with what we have: the Repair boot section, into which Windows will most likely offer to boot after an unsuccessful attempt (if it does not, then before loading) press F8). Then open the “Command Prompt” (in case of a failed automatic recovery, click “View advanced options” before this).
- Run the registry editor with the command "regedit". It is worth noting that this is the registry of the recovery system.
- We connect the necessary register (more precisely, a beehive). We are interested in "[HKLM / SYSTEM /]", it is stored in the% WINDIR% \ System32 \ Config \ System file. To do this, we focus on “HKEY_LOCAL_MACHINE”, in the menu choose File -> Load Hive -> desired file -> Key name: “nn” (if installed on the VHD, you need to connect it to the console).
- In a loaded hive, there should be several ControlSet *s, the desired one is recorded in “Select / Current”. Go to "ControlSet * / services". The section above describes what to do and why. But It is worth noting that in the case of launch not from USB, keys like “atapi”, “pciide”, “intelide”, “msahci” and similar ones may be of interest.
USB boot
Because restart once again all the laziness, we check again in the virtual machine. Turn it off, delete all HDDs in the settings, start up, transfer USB-HDD to the virtual machine and ... We understand that our disk is not visible. But in the list of what is required, BIOS support for booting from USB was not mentioned.
Downloading the
plop boot manager - there are iso and img images in the archive. We indicate to the virtual machine to boot from the plpbt.iso disk (or plpbt.img for floppy) and already it will transfer control to the bootloader from USB. Everything should go well and eventually Windows 7 will start and say that a new device has been found.
Now we can transfer the external drive to any other real machine and start. That's all. Your suggestions on practical application are interesting.
Brief summary
- we start the virtual machine, having connected usb-hdd and the installer of Windows 7;
- during the installation process, we indicate that we want to install on the VHD (optional);
- change driver loading priority;
- we start from USB, if the BIOS fails, then we use plpbt.
Important notes / unresolved issues
- before loading the kernel, there may be problems with accessing the disk to addresses above 137Gb (I had) - you can only advise to transfer the partition to the beginning of the disk (actually, including because of this restriction, I installed it on the VHD and did not create new section);
- after each booting, Windows reports that something has changed and it is necessary to re-order the swap - it is best to specify the explicit size of the swap and assign it to D: (physical partition, C: - virtual disk), but when you run it on another machine, the question again will occur, and if the memory size is different there, the swap will be automatically selected;
- honest guys offer to call% windir% \ system32 \ sysprep \ sysprep.exe before transferring to another hardware, but I noticed that this is not necessary and even harmful (they re-suggest creating a user / settings are reset / an extra restart is required after searching for drivers) - personally everything works fine for me and on condition of normal shutdown and, which is typical, if the system was previously started on this equipment, then the restart will take place instantly, all drivers will pick up automatically and without restarts;
- the boot loader (bootmgr, Boot \) must be located on the physical disk (done automatically), but I would like to reset everything inside the VHD and transfer control to it from grub. These guys made their grub with the vhd module, but I didn’t master it (first I had to edit the Makefiles to create the vhd.mod, but after copying to / boot / grub /, the “insmod vhd” command ended with the error “incompatible license "; A more detailed study of the vhd.c code showed that changes were made to the code of grub-1.97 itself, which did not suit me, because Ubuntu uses grub-1.99).
Used sources
PS And the prices for drives have recently skyrocketed due to the flooding of Taiwan.