# Create a Boot Camp image

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This article describes how to create a Boot Camp image for end-users and how to apply it to computers in a non-destructive manner using DeployStudio. Before proceeding, please back up the user's data.

## DeployStudio

This section will show you how to create and capture a Boot Camp Windows image using DeployStudio. It will also show you how to do a restore to apply the image.

### Create a Boot Camp image

1. Create a Windows 7 image in a virtual machine. Once you have a Windows 7 image just about ready to capture before running sysprep, you will need to do a few things for full Mac compatibility:
1. Copy all Boot Camp drivers to C:\Drivers (you can hide this folder). Make sure your Answer file scans this folder to pick up drivers. It should pick up most drivers, but not all.
2. In your Answer file, create a First Logon command (oobeSystem/arch_Microsoft-Shell-Setup) as follows:
msiexec.exe /i c:\Drivers\path\to\BootCamp.msi /qn /norestart /log "%SystemDrive%\Windows\BootCamp\BootCamp_Install.log
Note: You should use the latest supported Boot Camp version available when at all possible. Sometimes older Mac hardware may not be compatible in which case you may need to resort to using an older version of Boot Camp.
Boot Camp v5 is only available for 64-bit versions of Windows 7/8. Older versions of Boot Camp support up to Windows 7 and will usually have 32-bit (BootCamp.msi) and 64-bit (BootCamp64.msi) drivers.
3. If this is for a lab image, you will probably want to disable users from being able to read the Apple HFS partition. In your Answer file, create 2 First Logon commands (oobeSystem/arch_Microsoft-Shell-Setup) as follows:
cmd.exe /c move C:\Windows\System32\drivers\AppleHFS.sys C:\Windows\System32\drivers\AppleHFS.sys.donotusecmd.exe /c move C:\Windows\System32\drivers\AppleMNT.sys C:\Windows\System32\drivers\AppleMNT.sys.donotuse
4. There is a known issue where OS X and Windows are out of sync in time. To resolve this problem, in your Answer file, create a First Logon command (oobeSystem/arch_Microsoft-Shell-Setup) as follows:
cmd.exe REG ADD HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v “RealTimeIsUniversal” /t REG_DWORD /d “1” /f
5. Because the Windows Assessment Tool runs during sysprep before the Boot Camp drivers are installed, its assessment of the machine is not accurate. To resolve this problem, in your Answer file, create a First Logon command (oobeSystem/arch_Microsoft-Shell-Setup) as follows:
cmd.exe /c winsat formal
7. Run sysprep with the /generalize /oobe /shutdown parameters:
sysprep.exe /oobe /generalize /shutdown /unattend:NameofAnswerFile.xml
2. Create a snapshot of your VM while shutdown (before it boots back up).
3. Capture an image of the VM using your PC imaging solution of choice.
4. Connect a HDD to a USB external SATA dock attached to your PC. Apply the newly created Windows image on a spare HDD.
5. Disconnect the USB external SATA dock from your PC and attach it to a Mac.
6. Netboot into DeployStudio on the Mac with the USB external SATA dock attached and powered on.
7. Create a workflow called Create Windows image in DeployStudio Admin:
1. Run DeployStudio Admin.app located in /Applications/Utilities/
2. Click on the WORKFLOWS section in the left side menu.
3. Create a workflow by clicking on the ( + ) button in the bottom of the screen.
4. Name the workflow in the title column: Create a Windows image.
5. Add a task to this workflow by clicking on the ( + ) next to where it says Drop tasks here. Use the the Disk Image task.
1. Leave Source empty
2. Type: Compressed - faster restoration, small footprint
3. Format: Auto-detect
4. Leave Keywords empty
5. Select Try to create intermediate files on a local volume to preserve network bandwidth.
6. Select Try to shrink the size of NTFS volumes before imaging.
7. Uncheck Cleanup Mac OS X machine dependent files and caches and Image NTFS volumes with Mac OS X tools to allow multicast deployment
6. Click Save in the bottom right of the screen to preserve changes.
8. In the Create a Windows image workflow, you will make sure the following is selected:
1. In the left drop down menu, select the HDD on your USB external SATA dock. If you do not see it, try to turn off the dock and turn it back on and make sure the device is plugged into the Mac.
2. Image name: Win7x64-MM-DD-YY (if 64-bit) or Win7x32-MM-DD-YY (if 32-bit) where MM-DD-YY is the date the image was made.
3. Keywords: Type in something descriptive about image.
4. Type: Compressed - faster restoration, small footprint
5. Format: Auto-detect
9. Click on the button to continue the workflow. This process may take quite a few hours.

### Restore a Boot Camp image

In order to image a Mac with Boot Camp, the Mac must have a FAT partition available for your Boot Camp image to be restored to. You can use Disk Utility to create partition, Boot Camp Assistant located in /Applications/Utilities/, or the command diskutil resizevolume in Terminal. However that all requires manual intervention which is why a script has been created for use in DeployStudio that will automatically take the steps needed to ensure your Mac can have Boot Camp installed properly.

Create a script called ds_create_bootcamp_partition.sh in TextWrangler or any other text editor and save it to the Scripts folder in the DeployStudio repository.  

#!/bin/sh #This script was created by Balmes Pavlov. #Determine the partitions used up. If 4 partitions are used up, then script cannot run. PartCount="$(diskutil list | awk '/disk0s/ {print$1}' | wc -l)" PartLimit="4" if [ "$PartCount" -ge "$PartLimit" ]; then echo You have $PartLimit or more partitions on this computer. echo You need less than$PartLimit partitions on this computer to install Boot Camp. echo Please remove partitions accordingly. exit 1 fi #Variables for determining whether Boot Camp partition exists already. FATPart="$(diskutil list | awk '/Microsoft/ {print$5}')" PartName="BOOTWIN" MSCheck="$(diskutil list | awk '/Microsoft/ {print$2 $3$4}')" #Determine whether a FAT partition already exists if [ "$MSCheck" == "MicrosoftBasicData" ]; then echo There is a already one or multiple FAT or NTFS partition here. echo Those partitions must be deleted in order for Boot Camp to be installed. echo Please remove those partitions. exit 1 #Ensure that partitions with the same name do not exist. elif [ "$FATPart" == "$PartName" ]; then echo A partition called$PartName already exists. exit 1 else #Determine whether disk0s2 is using Apple_HFS file system disk0s2="$(diskutil list | awk '/disk0s2/ {print$2}')" if [ ! "$disk0s2" == "Apple_HFS" ]; then echo disk0s2 is not using file system Apple_HFS and therefore cannot be split into two partitions. exit 1 fi #Set the volume that will be split using diskutil resizeVolume BOOT_VOL=disk0s2 #Find maximum and minimum size that volume can be resized. MaxSize="$(diskutil resizeVolume $BOOT_VOL limits | awk '/Maximum/ {print$3}')" MinSize="$(diskutil resizeVolume$BOOT_VOL limits | awk '/Minimum/ {print $3}')" echo echo "Maximum size volume can be resized${MaxSize}GB" echo "Minimum size volume can be resized ${MinSize}GB" #Calculate available space for resizing on volume. AVAILABLE="$(echo ${MaxSize}-${MinSize} | bc)" echo Space available on $BOOT_VOL is${AVAILABLE}GB #Variables WinLimit="80" #determines the cap at which partition size will be determined by either WinPercent or WinMin. WinPercent="35" #determines percentage of free space that will be used for Boot Camp. WinMin="30" #determines minimum size for Boot Camp partition. #Functions WinPercentResize () { diskutil resizeVolume $BOOT_VOL$(echo ${MaxSize}-${AVAILABLE}*${WinPercent}/100 | bc)G MS-DOS$PartName $(echo${AVAILABLE}*${WinPercent}/100 | bc)G } WinMinResize () { diskutil resizeVolume$BOOT_VOL $(echo${MinSize}+${AVAILABLE}-${WinMin} | bc)G MS-DOS $PartName$(echo ${WinMin}/1 | bc)G } echo echo "Windows requires at least${WinMin}GB" echo if [ "$(echo${AVAILABLE}/1 | bc)" -le "$(echo${WinMin}/1 | bc)" ]; then { echo "Windows cannot be installed on this volume due to insufficient volume space." echo "Script will terminate in 5 seconds." sleep 5 exit 1 } elif [ "$(echo${AVAILABLE}/1 | bc)" -ge "$(echo${WinLimit}/1 | bc)" ]; then { echo "The Boot Camp partition will take up approximately "$(echo${AVAILABLE}*${WinPercent}/100 | bc)"GB, which is${WinPercent}%, of the free volume space available." echo WinPercentResize if [ $? -ne 0 ]; then { echo "There was an error in how Disk Utility moved the partitions and therefore the command could not finish." echo "The last command will run again." echo "The Boot Camp partition will take up approximately "$(echo ${AVAILABLE}*${WinPercent}/100+2 | bc)"GB, which is ${WinPercent}%, of the free volume space available." echo diskutil resizeVolume$BOOT_VOL $(echo${MaxSize}-${AVAILABLE}*${WinPercent}/100-2 | bc)G MS-DOS $PartName$(echo ${AVAILABLE}*${WinPercent}/100 | bc)G } fi } else { echo "The Boot Camp partition is going to take up "$WinMin"GB since you have 80GB or less of free volume space available." echo WinMinResize if [$? -ne 0 ]; then { echo "There was an error in how Disk Utility moved the partitions and therefore the command could not finish." echo "The last command will run again." echo "The Boot Camp partition is going to take up "$(echo${WinMin}+2 | bc)"GB since you have 80GB or less of free volume space available." echo diskutil resizeVolume $BOOT_VOL$(echo ${MinSize}+${AVAILABLE}-${WinMin}-2 | bc)G MS-DOS$PartName $(echo${WinMin}/1 | bc)G } fi } fi fi exit 0 

With this script created, you can make a workflow that specifically restores the Windows image you created earlier on your Mac.

1. Open up DeployStudio Admin located in /Applications/Utilities on the server.
2. Click on the WORKFLOWS section in the left side menu.
3. Create a workflow by clicking on the ( + ) button in the bottom of the screen.
4. Name the workflow in the title column: Restore a Windows image. You can be a bit more descriptive than this if you will be creating multiple workflows to restore Windows images.
5. Add a task to this workflow by clicking on the ( + ) next to where it says Drop tasks here. Use the Generic task.
1. Description: Enter a brief description of the script and what it does.
2. Error message: Enter a quick error message that can let the end user know what to do in case the script fails.
3. Command: ds_create_bootcamp_partition.sh
4. Parameters: Leave empty
5. Uncheck Postponed execution (command will be launched at first boot).
6. Check Automate
6. Add a task to this workflow by clicking on the ( + ) in the middle of the DeployStudio Admin window. Use the Restore task.
1. Target Volume: BOOTWIN
2. Image: NTFS should be the default. Specify the Windows image you wish to deploy.
3. Everything under HFS only options: should be unchecked EXCEPT:
Expand restored NTFS volume
Set as default startup volume
Automate.
4. Click Save in the bottom right of the window to preserve changes.

You should be able to netboot into DeployStudio, run the newly created workflow on any Mac and apply the Boot Camp image.

### Dual-Boot Lab image

The previous instructions showed you how to apply a Boot Camp image to a Mac that already had Mac OS X running. If you want to re-image a Mac with both OS X and Windows, then the workflow should be as follows:

1. Open up DeployStudio Admin located in /Applications/Utilities on the server.
2. Click on the WORKFLOWS section in the left side menu.
3. Create a workflow by clicking on the ( + ) button in the bottom of the screen.
4. Name the workflow in the title column: Restore Dual-Boot OS X and Windows. You can be a bit more descriptive than this if you will be creating multiple workflows for different dual-boot scenarios.
5. Add a task to this workflow by clicking on the ( + ) next to where it says Drop tasks here. Use the Partition task. This will wipe the entire drive.
1. Target Volume: First disk available.
2. Apply layout template: Macintosh + HD.
3. Split the partitions Macintosh HD and Windows 50%/50%.
4. Check Automate.
6. Add a task to this workflow by clicking on the ( + ) in the middle of the DeployStudio Admin window. Use the Restore task.
1. Target Volume: WINDOWS (Enter value...)
2. Image: NTFS should be the default. Specify the Windows image you wish to deploy.
3. Everything under HFS only options: should be unchecked EXCEPT:
Expand restored NTFS volume
Set as default startup volume
Automate.
7. Add a task to this workflow by clicking on the ( + ) in the middle of the DeployStudio Admin window. Use the Restore task.
1. Target Volume: Macintosh HD (Enter value...)
2. Image: HFS should be the default. Specify the OS X image you wish to deploy.
3. Everything under HFS only options: should be unchecked EXCEPT:
Dont't check restoration (faster)
Erase target for block copy restoration (faster)
Rename ByHost.prefs
Cleanup machine dependent files and caches
Automate
8. Add a task to this workflow by clicking on the ( + ) in the middle of the DeployStudio Admin window. Use the Package install task.
1. Target volume: Macintosh HD (Enter value...)
2. Package: rEFInd 0.6.11.pkg
3. Check Postponed installation (packages will be installed on first boot)
4. Check Automate
5. Click Save in the bottom right of the window to preserve changes.

Just to describe what has been done with this workflow. You've wiped the machine clean of all partitions and created 2 new partitions called Macintosh HD and WINDOWS split 50%/50%. The first restore task will restore the Windows image first and set it as the default start up volume. The second restore task will restore the OS X image. The last task will install the rEFInd package which allows the user to select their OS when the Mac powers on. This package will only install once you boot into the OS X partition.

Make sure that the Windows partition goes through sysprep completely before booting into the OS X partition.

The first time you boot into the OS X partition, you will have to hold the OPTION key at startup and select the OS X partition (which may be labeled EFI). After this one initial startup into OS X, the rEFInd boot manager will take over after any subsequent restarts.

## Getting Boot Camp drivers

There are many ways to download the Boot Camp drivers. This section will cover how to manually download Windows drivers for Macs running Boot Camp 4 or Boot Camp 5.

1. Download the following file from Apple's Software Update Server: http://swscan.apple.com/content/catalogs/others/index-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog (Don’t double-click it, that won’t help.)
2. Open the .sucatalog file in a text editor such as Text Wrangler or TextEdit.
3. Search for each occurrence — as of August 2012 there were 6 — of BootCampESD.pkg. For instance, the one I needed is http://swcdn.apple.com/content/downloads/33/54/041-2011/pRtCDYcWShMLxFggy3TzFzmfnnWQNFQBfJ/BootCampESD.pkg
4. Notice in each such URL, the /041-2011/ or similar /041-XXXXX/ bit of it.
5. Below each such occurrence, notice a URL for a file with the same 041-XXXXX in it and ending in English.dist, e.g. 041-2011.English.dist
6. Paste the URL for each such English.dist file into your browser and open the URL. Here’s a list of them:
7. Search for the Model Identifier for your Mac. For instance MacBookPro5,2 or Macmini4,1, and so on.

For instance the 041-2011 file contains these models: MacBook2,1 MacBook3,1 MacBook4,1 MacBook5,1 MacBook5,2 MacBook5,3 MacBook6,1 MacBook7,1 MacBookAir1,1 MacBookAir2,1 MacBookAir3,1 MacBookAir3,2 MacBookPro2,1 MacBookPro2,2 MacBookPro3,1 MacBookPro4,1 MacBookPro5,1 MacBookPro5,2 MacBookPro5,3 MacBookPro5,4 MacBookPro5,5 MacBookPro6,1 MacBookPro6,2 MacBookPro7,1 MacBookPro8,1 MacBookPro8,2 MacBookPro8,3 MacPro1,1 MacPro2,1 MacPro3,1 MacPro4,1 MacPro5,1 Macmini2,1 Macmini3,1 Macmini4,1 iMac5,1 iMac6,1 iMac7,1 iMac8,1 iMac9,1 iMac10,1 iMac11,1 iMac11,2 iMac11,3 iMac12,1 iMac12,2

How do you know your Model Identifier? Open System Information, and look in the Hardware Overview section:
4. Click Report
5. Click Hardware
6. Read down the Hardware Overview looking for Model Identifier:
8. Having found your 041-XXXXX number, use the URL associated to the BootCampESD.pkg that has your number in it. I try to keep the page at bootcamp-driver-download up to date with all the pkg download URLs.
9. Be patient as it’s probably 600MB.
10. Once your pkg is downloaded, double click it and install to a folder on your hard drive so you know where to find it.
11. The folder contains a nest of folders, the last of which contains a DMG disk image file. Double click to open. Here are your Windows installer files. Again, the page at bootcamp-driver-download has pictures to help.
12. Copy the folder to a thumb drive or to a server share where they can be accessed later. These drivers can now be integrated into your Boot Camp image.

If all else fails you can also use Boot Camp Assistant which should work for the most part to get you Boot Camp drivers for that particular hardware you are currently using. In OS X, open up Boot Camp Assistant which is located in /Applications/Utilities/. You will get the option to Download the latest Windows support software from Apple onto a USB flash drive.

To automate the process of using Boot Camp drivers in your Boot Camp image, you can also use the utility called Brigadier. This tool has been made available by Tim Sutton. Please check it out at: https://github.com/timsutton/brigadier

## Technical Notes

Boot Camp is only compatible with OS X 10.5 or higher (Leopard, Snow Leopard, Lion and Mountain Lion). OS X 10.4 (Tiger) and older does NOT support Boot Camp.

The ability to apply the Boot Camp image to a Mac without wiping the machine is possible because of a script that was created by Balmes Pavlov. The script has a couple of checks in it to make sure that the computer HDD partitions have not been altered from the default configuration Macs come with.

Typically Macs come with the an EFI partition (disk0s1), OS X partition (disk0s2), and, now with Lion/Mountain Lion, the Recovery partition (disk0s3). The way Boot Camp works is that Apple has to emulate the MBR that allows Windows to boot. To do this, the Windows partition needs to be within the first 4 partitions on that Macs. That means if someone has 4 or more partitions it can be very tricky and too complicated to even get it working since it will involve moving partitions around.

The script checks that:

1. There are no more than 3 partitions being used up.
2. There isn’t already a FAT partition in use (which is used for Boot Camp in the initial setup).
3. There is enough space available for a Windows partition. I’ve set it to take up:
• 35% of space if more than 80GB are available
• 30GB of space if more than or equal to 30GB is available, but less than or equal to 80GB is available
• And to not run if less than 30GB is available

Fact is that Windows after updates takes up a lot of space very quickly so the user really does need at least 30GB (at least for Windows 32-bit).

Once the script runs through successfully, the imaging will begin. If the script does not run successfully, it will stop before any imaging begins.

## Troubleshooting

• The script in the workflow does not complete causing the workflow to stop.

The script in the workflow is meant to non-destructively create a partition called BOOTWIN based on 35% of available HDD if space is more than 80GB. Or if HDD is between 30GB and 80GB, it will use 30GB of space. If the script cannot create the partition for whatever reason, then you can create it manually:

1. Boot into OS X.
2. Open up Disk Utility.app located in /Applications/Utilities
3. Select main harddrive.
4. Click on Partition tab.
5. Click on ( + ) sign to add a partition.
6. Click on the partition.
7. NAME must be BOOTWIN
8. FORMAT must be MS-DOS (FAT)
9. SIZE must be at least 30GB. If there is no space then user needs bigger HDD.
10. Click Apply.
11. Proceed to Netboot into DeployStudio to restore the Boot Camp image.

If you manually create a FAT partition, you will not be able to use the script and hence the workflow earlier will not work. At that point, I would recommend you make a workflow that does not utilize the script. Just make sure to backup.

• Boot Camp image was applied, but it cannot be booted into.

This can happen if there are multiple partitions on the HDD and the Boot Camp partition is not designated as disk0s3. Generally speaking, Macs have at least 2-3 partitions. Disk0s1 for EFI, disk0s2 for OS X, and disk0s3 for Recovery Partition (the last one should only appear on Macs that have Lion or Mountain Lion). Although, the Recovery Partition is identified as disk0s3 in Lion/Mountain Lion, if you create a new partition, it will usually move that partition around so that it will not interfere with Boot Camp (i.e. Boot Camp partition becomes disk0s3, Recovery partition becomes disk0s4). If the Mac has other partitions aside from these, then the Boot Camp partition may not be disk0s3 hence why it will not boot.

There is no easy solution to this and attempting to mess around with partitions could result in the user losing data. So ultimately, the Mac has to either lose the extra partitions or forgo getting Boot Camp. Before removing a partition, confirm with the user beforehand and back up accordingly.