Sunday, December 19, 2010

How to image a Windows 2008 Server using WinPE and imagex

We have a windows server 2008 R2 that we want to image to another server.
First we must create a Windows PE boot CD, that it will be used for the imaging of the server.
In a windows 7 PC, running a 64-bit Windows (a technician computer according to Microsoft documentation) we install Windows AIK. After that we open an elevated Deployment Tools Command Prompt from Windows 7 Start Menu and we enter the following commands:
DISM /Cleanup-Wim
copype.cmd amd64 c:\winpe_amd64
copy c:\winpe_amd64\winpe.wim c:\winpe_amd64\ISO\sources\boot.wim
Dism /Mount-Wim /WimFile:C:\winpe_amd64\winpe.wim /index:1 /MountDir:C:\winpe_amd64\mount
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\en-us\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\en-us\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\en-us\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\"
Dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\en-us\"
copy /y "C:\Program Files\Windows AIK\Tools\amd64\imagex.exe" C:\winpe_amd64\mount\Windows\System32\
copy /y "C:\Program Files\Windows AIK\Tools\amd64\bcdboot.exe" C:\winpe_amd64\mount\Windows\System32\
copy /y "C:\Program Files\Windows AIK\Tools\PETools\amd64\BootSect.exe" C:\winpe_amd64\mount\Windows\System32\
copy /y "C:\Windows\System32\bcdedit.exe" C:\winpe_amd64\mount\Windows\System32\

If we have a folder with 3rd party drivers we can inject these drivers to windows PE image using the following command:
DISM /image:C:\winpe_amd64\mount /Add-Driver /driver:C:\tmp\drv\ /recurse
After the driver injection we unmount the wim file and commit changes using this command:
Dism /Unmount-Wim /MountDir:C:\winpe_amd64\mount\ /Commit
Then we copy the wim file to the iso folder of the working folder:
copy /y c:\winpe_amd64\winpe.wim c:\winpe_amd64\ISO\sources\boot.wim
Finally we create the bootable iso image entering this command:
oscdimg -n -bc:\winpe_amd64\ c:\winpe_amd64\ISO c:\winpe_amd64\winpe_amd64.iso
This ISO image can be written to a blank CD  using a tool like ISO Recorder
Optionally we can create a bootable USB stick using the article How to create a bootable WinPE 2.0 USB key
Optionally we can use a tftp server to boot this WIM using these instructions:
Mount the Windows PE image to the \Mount folder of the working directory:
Dism /Mount-Wim /WimFile:C:\winpe_amd64\winpe.wim /index:1 /MountDir:C:\winpe_amd64\mount
Map a network connection to the root TFTP directory on the TFTP server and create a \Boot folder:
net use N: \\tftpServer\TFTPRoot
md N:\Boot

md N:\Boot\Fonts
Copy the PXE boot files from the mounted directory to the \Boot folder:
copy /y C:\winpe_amd64\mount\Windows\Boot\PXE\*.* N:\Boot
Copy the boot.sdi file to the PXE/TFTP server:
copy /y C:\Program Files\Windows AIK\Tools\PETools\amd64\boot\boot.sdi N:\Boot
Copy fonts files to Fonts directory:
copy /y C:\winpe_amd64\ISO\boot\fonts\*.* N:\Boot\Fonts\
Unmount the current Windows PE image and copy the bootable Windows PE image to the \Boot folder renaming this file to boot.wim:
Dism /Unmount-Wim /MountDir:C:\winpe_amd64\mount\ /Commit
copy c:\winpe_amd64\winpe.wim N:\Boot\boot.wim
Then we we must create a BCD store by using the BCDEdit tool. Using this link we create the following batch file to create the BCD store:
file name: createBCD.cmd
Rem Creates BCD (boot configuration data) for Windows PE
set BCD-File=c:\tmp\BCD
del %BCD-File%
Bcdedit /createstore %BCD-File%
Bcdedit /store %BCD-File% /create {ramdiskoptions} /d "Ramdisk options"
Bcdedit /store %BCD-File% /set {ramdiskoptions} ramdisksdidevice boot
Bcdedit /store %BCD-File% /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
Bcdedit -store %BCD-File% -create {dbgsettings} /d "Debugger settings"
Bcdedit -store %BCD-File% -set {dbgsettings} debugtype serial
Bcdedit -store %BCD-File% -set {dbgsettings} baudrate 115200
Bcdedit -store %BCD-File% -set {dbgsettings} debugport 1
for /f "tokens=1-3" %%a in ('Bcdedit /store %BCD-File% /create /d "MyWinPE Boot Image" /application osloader') do set guid1=%%c
Bcdedit /store %BCD-File% /set %guid1% systemroot \Windows
Bcdedit /store %BCD-File% /set %guid1% detecthal Yes
Bcdedit /store %BCD-File% /set %guid1% winpe Yes
Bcdedit /store %BCD-File% /set %guid1% osdevice ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
Bcdedit /store %BCD-File% /set %guid1% device ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
Bcdedit /store %BCD-File% /create {bootmgr} /d "Windows BootManager"
Bcdedit /store %BCD-File% /set {bootmgr} timeout 30
Bcdedit /store %BCD-File% /set {bootmgr} displayorder %guid1%
Bcdedit /store %BCD-File% /enum all

 Running this batch file the BCD file is created. After that we can copy this file to the tftp server:
copy /y c:\tmp\BCD N:\Boot
After this we can use a tftp server like this to boot our PE image. I use these settings for the tftpd configuration:

 TFTP Security: Standard
Advanced TFTP Options
Option negotiation
Translate Unix file names
Allow '\' As virtual root
Use anticipation window of 8192 bytes (optional for higher transfer rates)
tftpd settings
We must also configure a DHCP server to give the boot client an IP address and this boot file: pxeboot.n12 (DHCP options 066 and 067)
dhcp options
Using the boot CD or the bootable USB stick or a tftp server we boot the PE image we created and we enter this command to find the partitions of our server:
DISKPART> list disk
If we have only one disk this is disk 0 so we enter these commands:
DISKPART> select disk 0
DISKPART> list part
With this command we found the partitions we want to image. Usually there is a small System partition and a bigger Windows partition. Use the diskpart command "assign letter" to assign letters to these partitions so that we can use the imagex command to image these partitions:
imagex /capture C:\ D:\SystemPartition.wim "My System Partition"
imagex /capture D:\ D:\WindowsPartition.wim "My Windows Partition"
In this example C: is the system partition and D: is the Windows Partition.
Using the net use command map a network drive to a file server so that we can store these wim files to a network folder:
net use F: \\server\share
copy /y D:\SystemPartition.wim F:\Images
copy /y D:\WindowsPartition.wim F:\Images
In this example we copied the wim files to the Images folder in our file server.
Image restoration
We can restore these image files to another server using this procedure:
Boot the new server using one of the three aforementioned methods (boot CD, boot USB or tftp server)
Enter diskpart and create the partition scheme of the old server. For example:
DISKPART>select disk 0
DISKPART>create partition primary size=300 
DISKPART>format quick fs=ntfs label="System"
DISKPART>assign letter="S"
DISKPART>create partition primary
DISKPART>format quick fs=ntfs label="Windows"
DISKPART>assign letter="W"
If we are working with a UEFI based PC we use the following diskpart commands:
DISKPART>select disk 0
DISKPART>convert gpt
DISKPART>create partition efi size=100
DISKPART>format quick fs=fat32 label="System"
DISKPART>assign letter="S"
DISKPART>create partition msr size=128
DISKPART>create partition primary
DISKPART>format quick fs=ntfs label="Windows"
DISKPART>assign letter="W"

For more info take a look at Technet documentation from Microsoft
We can also create a diskpart script using the above command an aply script using the command
diskpart /s
Use net use to create a network drive to map to the file server holding the the wim files:
net use F: \\server\share
After this we can apply the wim files to the new partitions:
imagex /apply F:\Images\SystemPartition.wim 1 S:\
imagex /apply F:\Images\WindowsPartition.wim 1 W:\
Finally use the BCDboot tool to copy common system partition files and to initialize boot configuration data:
W:\Windows\System32\bcdboot W:\Windows /l en-US
After this command we can reboot our new server to windows 2008 and make any customizations we want to do.

Friday, December 10, 2010

Setting up sysprep for use with vCenter running in Windows Server 2008

When deploying a virtual machine through a vCenter Server running on Windows 2008, the customization option is not available.
According to this VMware KB article this issue occurs when the subfolders within the %ALLUSERSPROFILE%\VMware\VMware VirtualCenter\sysprep folder do not have the appropriate sysprep files for the version of Windows you are trying to deploy. The default directory for the sysprep files is
C:\ProgramData\VMware\VMware VirtualCenter\sysprep
By default, the ProgramData folder is a hidden folder in Windows 2008.

To view the ProgramData folder:
   1. Click Start > All Programs > Accessories > Windows Explorer.
   2. Click Organize > Folder > Search Options.
   3. Click the View tab.
   4. Select the Show hidden files and folders option and click OK.

The ProgramData folder has subfolders for each of your Windows operating system. You must extract and unzip the from all the Windows installation DVD's SUPPORT\TOOLS folder and place the files in the appropriate folder within the
C:\ProgramData\VMware\Infrastructure\VirtualCenter\sysprep folder.
Within a Windows 2003 64bit operating system, the \SUPPORT\TOOLS\ file of the installation media has these files:

The subfolders within the C:\ProgramData\VMware\Infrastructure\VirtualCenter\sysprep folder are:
    * 2k
    * svr2003
    * svr2003-64
    * xp
    * xp-64

For example if the machine to be deployed has a 64bit version of Windows 2003, you must place the sysprep files (contents of within the C:\ProgramData\VMware\Infrastructure\VirtualCenter\sysprep\srv2003-64 folder.

How to image OpenSuSE to a virtual machine

This procedure was tested under OpenSuSE 11.x but it should also work for OpenSuSE 10.x.
The situation is this:
You want to convert a Linux machine running OpenSuSE to a virtual machine running under VMware Workstation.
The utility used to image the physical Linux machine was Clonezilla but the procedure should also work with Ghost or Acronis. After we made an image of the physical machine that image was restored to a new virtual machine that was created in VMware workstation 7. The problem is that the new VM won't boot because of the lack of appropriate drivers from initrd image of it. To correct this issue we must boot the VM using the OpenSuSE DVD and choosing to boot to rescue mode.
After that login to rescue system with username root and no password.
Find the partition layout of your system using the command fdisk -l
In my case the root and boot filesystem was in /dev/sda2
I created the following mount points:
mount /dev/sda2 /mnt
mount -t proc none /mnt/proc
mount -t sysfs none /mnt/sys

We now have the imaged system available under /mnt
We must also remount the dev filesystem using this command
mount -o bind /dev /mnt/dev
After this we chroot to the root filesystem of the imaged system using the command
chroot /mnt
Edit the files fstab, mtab, menu.lst and to reflect the correct mount points and boot partitions
Include the necessary drivers in /etc/sysconfig/kernel editing the section INITRD_MODULES in this file.
In my case the new entry was
INITRD_MODULES="processor thermal ata_piix fan reiserfs mptspi"
but you can add more drivers if you want to.
Now change to the boot directory using the command
cd /boot
Rename the current initrd file for safekeeping
mv initrd-xxxx initrd-xxxx.old
where xxxx is different from one SuSE release to another
Enter this command to create a new initrd
mkinitrd -d /dev/sda2 (sda2 points to /)
extra modules can also be added with the -m switch if you want to:
mkinitrd -d /dev/sda2 -m mptspi
Make sure the name of the created initrd is the same as stated in the menu.lst or that the initrd link points to the new initrd file.
You can now reboot the system and if all went as planned the system now boots up and you can modify other needed components like networking.
You can remove your old nic entry (the nic used in the previous machine) by editing
and reboot. That should bring the new nic back as eth0
For more info take a look in this link
Good Things To Know When Imaging Linux To Different Hardware