Tuesday, 26 July 2016

How to automate the installation of Windows and Lenovo drivers using SDI_CHOCO

Here is how I modified SDI_CHOCO on my E2B drive so that instead of using Snappy to install generic drivers, it installs all the correct official Lenovo drivers and applications.

New user files are created by the end user to modify the install behaviour, so updating E2B to the latest version will not delete these new files because only the original E2B files are updated.

If you have several different models of PCs and Notebooks to install, then the XML file and SDI_CHOCO folder structure should be duplicated, renamed and modified accordingly, for each different model.



Introduction

Lenovo provide Windows 10 downloads for the IdeaPad 300 notebook in the form of executables.
I needed these 64-bit drivers and applications to create a fully automated Windows 10 install from a standard Microsoft Windows Installer ISO.

I used choco to install a few applications, although I could have also copied bespoke application install files from the APPS folder and installed those too, if I had wanted to, instead of using choco. The whole installation would then be offline and an internet connection would not be needed.

Extract the Lenovo files

The IdeaPad 300 drivers and apps must first be downloaded from the Lenovo support website and then extracted as follows:
1. Double-click each Lenovo .exe file to run it (e.g. 8e3901af.exe)
2. Click Next\OK to extract the files to the C:\DRIVERS folder - I suggest you rename the folder name that it supplies by default and remove any spaces. e.g. 'C:\DRIVERS\Camera'.
3. Do NOT proceed to install the drivers - just untick the box and click Finish.


Do this for all the drivers. Leave the extraction path as C:\DRIVERS\xxxxx.

Copy drivers to the E2B drive

Now copy all the new sub-folders that are in C:\DRIVERS to a new folder at \_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_64


Here is an example folder file structure for Windows 8 and Windows 10 64-bit drivers for the IdeaPad 300:

\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_64\ID300_DRIV_INST.cmd
\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_64\CHIPSET
\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_64\VGA
etc.

Prepare the script

Now prepare a .cmd script that will install each driver \_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_64\ID300_DRIV_INST.cmd

(see below for the file I created)

The trick is in finding the correct switches to make the drivers install silently! I used Google and also searched the Lenovo site and the MSFN site here to find out which switches were required. Some experimentation was often required.

Integrate into SDI_CHOCO

We need to add some files to the \_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO folder (see below for the files I created)

Now create a \_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO\MySpecialize.cmd file.
It should copy the whole folder from the USB drive to the target hard disk and then run ID300_DRIV_INST.cmd script.

Create a \_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO\NoSDI.tag file to prevent Snappy SDI from installing the wrong drivers.

If you want to install any choco applications, then create a MyStartup.cmd file with the correct lines of code (see Sample_MyStartup.cmd).

Because WSUS causes a reboot and can interfere with initial testing, add a NoWSUS.tag file.





Testing

I chose a Windows 10 x64 Home+Pro standard Microsoft ISO and the Auto_WipeDisk0_Win10ProUK_with_SDI_CHOCO.xml file.

If the ID300_DRIV_INST.cmd did not correctly work, I simply tried a few different switches until I found one that worked. 

I found it useful to put a 'pause' at the end of the MySpecialize.cmd file.
I then pressed SHIFT+F10 to open a second command shell and could then try out different commands. All drivers should have been copied to the C:\DRIVERS folder, so any commands can be tried from this folder.

You can use NotePad to edit the C:\DRIVERS\ ID300_DRIV_INST.cmd file and then run it again to re-test the script until it works correctly.

It took me three attempts to get find the correct switches and get it all working fully automatically.

Note that this installation only works for 64-bit Windows. Some of the 32-bit applications and drivers are different. If you want to support 32-bit Windows, you can use the %BIT% variable to copy a \_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W10_8_32 folder...

:: Install bespoke drivers for IdeaPad 300
if "%BIT%"=="amd64" xcopy /herky %USB%\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W8_10_64\*.* %systemdrive%\DRIVERS\IDPAD300\W8_10_64\
if "%BIT%"=="x86" xcopy /herky %USB%\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W8_10_32\*.* %systemdrive%\DRIVERS\IDPAD300\W8_10_32\
:: Now install drivers
if "%BIT%"=="amd64" call %systemdrive%\DRIVERS\IDPAD300\W8_10_64\ID300_DRIV_INST.cmd
if "%BIT%"=="x86"      call %systemdrive%\DRIVERS\IDPAD300\W8_10_32\ID300_DRIV_INST.cmd

If you want to be able to remove the USB drive sooner, then install the drivers later by moving the lines
:: Now install drivers

call %systemdrive%\DRIVERS\IDPAD300\W8_10_64\ID300_DRIV_INST.cmd

from the MySpecialize.cmd file to the MySetupComplete.cmd file (once it is working correctly).

Details

Note that if any of the folders have spaces in their names, you will need to add double-quotes to the paths - e.g. start /wait ".\camera drivers\Alcor_2.44.50.23\setup" -s . I prefer to avoid the problem by not using spaces in folder or file names!


ID300_DRIV_INST.cmd

pushd "%~dp0"
dir
@echo on
:: Possible switches -s or /SILENT /NORESTART or  /S /v/qn  or /qn /norestart  or -s -sms ???
start /wait .\Power\POWER_ACPI_acpidriver.exe /SILENT /norestart
start /wait .\chipset\setupchipset.exe -s -norestart
start /wait .\IME\MEISetup.exe -s
start /wait .\RealtekLAN\setup.exe -s
:: add patches supplied by Lenovo (see IRST_PATCH 2tll01af.exe contents)
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iastora\Parameters\Device /v Controller0Phy1ANEnable /t REG_DWORD /d 0 /f
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iastora\Parameters\Device /v Controller0Phy1ANEnable | find /i "0x0"
start /wait .\RealtekCardRdr\setup.exe -s
start /wait .\ConexantAudio\setup.exe -s
start /wait .\VGA\Setup.exe -s
timeout 5
start /wait .\camera\Alcor_2.44.50.23\setup -s
start /wait .\camera\Realtek_6.3.9600.11105_WHQL\setup -s
start /wait .\LenovoUtility\setup.exe /SILENT
start /wait .\LenovoOptimizer\pt_install_msi.exe /Q /SILENT
start /wait .\SysIntFoundation\SystemInterfaceFoundation.exe /SILENT /norestart
start /wait _Solution_centre_updates_lscsetup_x64_33003.exe /s /v/qn
start /wait .\TPAD\install.exe /S
:: tpad\install.exe doesn't wait - so delay to allow it time to install
timeout 20
@echo off
echo Finished!


MySpecialize.cmd

:: Environment variables that are already available:
:: %USB% is the USB drive - e.g. D:
:: %BIT% will either be x86 or amd64
:: %WINVER% will be 7 or 8 or 10
:: %CONFIGDIR% will be %USB%\_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO
:: %log% will be the log file
:: %errlog% will be a log file to record errors
:: %systemdrive%\DRIVERS folder will hold all files that were in %USB%\_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO

:: Download and install some choco applications - it is best to install choco apps using Startup.cmd
:: Some choco apps installed at this stage of Setup may not register correctly

if exist %systemdrive%\DRIVERS\NoChoco.TAG start /wait %systemdrive%\DRIVERS\nircmd speak text "WARNING: The file No Choco dot tag was found - choco installs will NOT work"

:: Install bespoke drivers for IdeaPad 300
xcopy /herky %USB%\_ISO\WINDOWS\INSTALLS\DRIVERS\IDPAD300\W8_10_64\*.* %systemdrive%\DRIVERS\IDPAD300\W8_10_64\
:: Now install drivers
call %systemdrive%\DRIVERS\IDPAD300\W8_10_64\ID300_DRIV_INST.cmd

choco install 7zip.install -r -y >> %log%


MyStartupComplete.cmd

:: Environment variables that are already available:
:: %USB% is the USB drive - e.g. D:  NOTE: IT MAY BE DISCONNECTED BY NOW!
:: %BIT% will either be x86 or amd64
:: %WINVER% will be 7 or 8 or 10
:: %log% will be the log file
:: %errlog% will be a log file to record errors
:: %systemdrive%\DRIVERS folder will hold all files that were in %USB%\_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO

:: --- WARNING: No console is visible and no mouse pointer!!!

if exist %systemdrive%\DRIVERS\NoChoco.TAG start /wait %systemdrive%\DRIVERS\nircmd speak text "WARNING: The file No Choco dot tag was found - choco installs will NOT work"

%systemdrive%\DRIVERS\nircmd.exe speak text "Downloading and installing NotePad + +"
choco install notepadplusplus -y -r >> %log%


MyStartup.cmd

:: Environment variables that are already available:
:: %USB% is the USB drive - e.g. D:  NOTE: IT MAY BE DISCONNECTED BY NOW!
:: %BIT% will either be x86 or amd64
:: %WINVER% will be 7 or 8 or 10
:: %log% will be the log file
:: %errlog% will be a log file to record errors
:: %systemdrive%\DRIVERS folder will hold all files that were in %USB%\_ISO\WINDOWS\INSTALLS\CONFIGS\SDI_CHOCO

if exist %systemdrive%\DRIVERS\NoChoco.TAG start /wait %systemdrive%\DRIVERS\nircmd speak text "WARNING: The file No Choco dot tag was found - choco installs will NOT work"

echo Installing Classic shell...
%systemdrive%\DRIVERS\nircmd.exe speak text "Downloading and installing Classic Shell"
choco install classic-shell -r -y >> %log%

:: Install Google Chrome (internet connection required) - automatic install
echo Installing Google Chrome...
%systemdrive%\DRIVERS\nircmd.exe speak text "Downloading and installing Google Chrome"
choco install googlechrome -y -r >> %log%

echo Installing TeamViewer...
%systemdrive%\DRIVERS\nircmd.exe speak text "Downloading and installing Team Viewer"
choco install teamviewer -r -y >> %log%