Using JAMF Software's Casper Suite to Deploy Windows within a Mac Dual-boot environment
Volume Number: 24
Issue Number: 06
Column Tag: Operating Systems
Using JAMF Software's Casper Suite to Deploy Windows within a Mac Dual-boot environment
by Criss Myers
Prelude
We have recently explored the process of using JAMF Software's Casper Suite to deploy an OS X image to a laboratory of Mac clients, however you may also wish to take advantage of the ability to dual boot by installing Windows on a second partition. This process can easily be achieved and automated using the Casper tools. To achieve this we will create a Windows NTFS image that we can either deploy during the imaging phase or allow the users to install it to a second partition using the Self Service tools in the Casper Suite. We can also create a Self Service policy to allow the user to reboot to the Windows partition on a one off basis, and therefore return the Mac to OS X at the subsequent reboot.
Before we begin we will require the following:
Windows Setup
The first thing we are going to need to do is setup the Windows install on the Mac client so that we can then create an image ready for deployment.
Step 1. Setup a Mac client machine with OS X and create a second DOS partition using either BootCamp Assistant or Disk Utility, it doesn't matter at this stage how large the partition is as we will only be making an image from the used space.
Step 2. Install XP Service Pack 2 or Vista as per normal onto the second partition formatting it as NTFS. Do not re-partition the drive under Windows as this will destroy the GPT-MBR relationship, only the Mac 'diskutil' can mirror the GPT and MBR.
Step 3. Setup Windows with whatever settings you require and install any additional software required.
Step 4. Install the Bootcamp drivers for either XP or Vista. You may wish to remove the BootCamp control panel, to prevent the user from setting the startup disc to the Windows partition.
Step 5. Prepare the system for image creation using the System Preparation Tool Sysprep. This re-seals the image so that you can deploy to multiple workstations without any conflicting settings. We also can make an automated setup file that will enable silent setup of the Windows on first boot.
XP Install
1. Insert the XP Service Pack 2 or later
2. Create a folder called Sysprep at the root of C:\
3. From the install CD copy Sysprep.exe Setupcl.exe from the \Support\Tools\ Deploy.cab to the Sysprep folder on C:\
4. Copy the contents of the Deploy.cab to a new folder on the PC
5. Launch the Setupmgr.exe to create a Sysprep.inf, this will enable automated setup of the PC image during first boot.
6. Place the newly created Sysprep.inf into the Sysprep folder
7. Launch command prompt and change to the C:\Sysprep folder
8. Type Sysprep -mini -reseal
9. Windows will then automatically shutdown the client.
For more information on the Sysprep tool for XP and creation of the Sysprep.inf file use the below link.
http://support.microsoft.com/kb/302577
After imaging when you boot into windows it will run the automated mini-setup using the settings you set in the Sysprep.inf file.
Vista
1. Launch the command line
2. Type c:\windows\system32\sysprep\sysprep.exe /quiet /generalize /shutdown /oobe
3. The client will automatically shutdown.
For more information on Sysprep for Vista use the below link
http://www.asisupport.com/vista_oem_install.htm
Creating the Windows Image
Now we need to create the Windows image that we will deploy. To do this, boot the Mac back into OS X. Install ntfsprogs.pkg on the client. This install the tools required to clone, restore and resize NTFS volumes. On the Casper Share create a folder called Extras and inside that create a folder called BootCamp, inside that create two folders, XP and Vista.
Creating the XP clone
Save the following script as "windows_clone_XP.sh" and either upload the script to Casper Admin and run via Casper Remote, or copy it to the Mac and run locally from the Terminal.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
## Windows Cloning Script ##
## This Script will create an NTFS clone of the Windows partition and save it to the Image Location Specified ##
## Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
## You may edit the following parameters ##
disk='disk0'
sector='s3'
image_loc='/'
##################################################
## Script Content, DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume being cloned
echo " Unmounting the Windows Volume"
diskutil unmount "/dev/${disk}${sector}"
#Clone the Windows partition
echo "Cloning the Windows Partition"
ntfsclone -save-image -overwrite "/private/tmp/BootCamp.ntfs" "/dev/${disk}${sector}"
#Move the Windows clone to the Image location
echo "Moving the Windows clone"
mv /private/tmp/BootCamp.ntfs "$image_loc"
#Mount the Windows Partition
echo "Mounting the Windows Partition"
diskutil mount "/dev/${disk}${sector}"
echo "Done"
##############################################
Then upload the XP BootCamp.ntfs to the CasperShare/Extras/BootCamp/XP folder
Creating the Vista Clone
Do the same with the following script to create the Vista clone by saving the script as windows_clone_Vista.sh. Then upload the BootCamp.ntfs to the CapserShare.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
## Windows Cloning Script ##
## This Script will create an NTFS clone of the Windows partition and save it to the Image Location Specified ##
## Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
## You may edit the following parameters ##
share="/Volumes/CasperShare/Extras/BootCamp/Vista/"
disk='disk0'
sector='s3'
image_loc='/'
volume="/dev/disk0s3
mbr="$share/mbr"
##################################################
## Script Content‚ DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume being cloned
echo "Unmounting the Windows Volume"
diskutil unmount "/dev/${disk}${sector}"
#Harvest the Master Boot Record from the Drive
echo "Harvesting the MBR"
dd if=/dev/disk0 of=/tmp/mbr bs=1 count=446
#Copy the MBR to the NTFS volume
echo "Copying the mbr to the NTFS volume"
dd if=/tmp/mbr of=$mbr bs=1 count=466
#Clone the Windows partition
echo "Cloning the Windows Partition"
ntfsclone -save-image -overwrite "/private/tmp/BootCamp.ntfs" "/dev/${disk}${sector}"
#Move the Windows clone to the Image location
echo "Moving the Windows clone"
mv /private/tmp/BootCamp.ntfs "$image_loc"
#Mount the Windows Partition
echo "Mounting the Windows Partition"
diskutil mount "/dev/${disk}${sector}"
echo "Done"
##############################################
The difference with this script is that for Vista we need to copy the Master Boot Record from the partition and upload it to the server for later use.
Deploying Windows
We are now ready to deploy the image to the clients. There are a few ways in which this can be achieved.
Option 1
The first method is to deploy the Windows image together with the OS X image. To do this we boot from a NetInstall image on a NetBoot server and deploy the image via a script after we have installed all the OS X packages.
We have already made a NetInstall image for our previous deployment of OS X. If you have not done so then use Casper NetInstall Creator to create a NetInstall image.
Mount the Install.dmg.sparseimage and install the ntfsprogs.pkg. This will allow us to restore the ntfs cloned image whilst being netbooted.
Next we need to create two scripts and upload them to Casper. The first one will partition the drive into 2 partitions and the second will restore the ntfs image. I prefer to keep these scripts separate, so that I can use them independently of each other. I partition all my Macs, even if I don't initially install Windows on them. Then, should I need to deploy windows at a later date, I can do so without needing to partition the drive. GPT can repartition without needing to reformat the drive, but it saves time and eliminates possible partition errors by having the partition created whilst initially imaging. It also means that space is keep free for such a time.
Save the following script as partition.sh, upload to Casper and set its Priority to 'Before'
#!/bin/sh
##Partitioning Script ##
##This script will partition the drive with 1 Volume formatted as HFS+ and 1 Volume with MS-DOS
## Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
## Change the percentage of each volume as per your requirement ##
mac=80%
windows=20%
###########################################
## Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Partitioning the drive
echo "Partitoning the Drive"
diskutil partitionDisk disk0 2 GPTFormat "jhfs+" "Macintosh HD" "$mac" "MS-DOS" "Windows" "$windows"
echo "Done"
###########################################
For XP imaging, save the following file as windows_restore_XP.sh and upload to Casper and set its Priority to After.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
##Restore NTFS Image ##
##This script will restore the NTFS image to the client ##
##Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
share="/Volumes/CasperShare/Extras/BootCamp/XP/"
ntfs_image="$share/BootCamp.ntfs"
target_disk="/dev/disk0"
sector="3"
volume="/dev/disk0s3"
tmp_dir="/Volumes/Install/var/tmp"
#############################################################
##Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume to be imaged
echo "Unmounting the Volume"
diskutil unmount $volume
#Restore the NTFS image
echo "Restoring NTFS image"
ntfsclone -restore-image -overwrite "$volume" "$ntfs_image"
#Resize the NTFS volume if it is different
echo "Resizing ntfs volume"
ntfsresize -ff "$volume"
#Gather the Windows file that contains the Master Boot Record details and copy it to the boot drive
echo "Reading the file that contains MBR"
ntfscat -f "$volume" /WINDOWS/system32/dmadmin.exe > $tmp_dir/dmadmin.exe
#Harvest the Master Boot Record from the last 446B of that file
echo "Harvesting the MB"
dd if=$tmp_dir/dmadmin.exe of=$tmp_dir/mbr skip=216616 bs=1 count=446
#Sync the GPT and BIOS partition tables and copy the MBR to the start of the disk
echo "Syncing GPT to BIOS partition table and restoring MBR"
gptrefresh -w -a $sector -f -u -m $tmp_dir/mbr $target_disk
#Update the boot.ini file and copy it back the NTFS volume
echo "Updating boot.ini with the partition number"
ntfscat -f $volume /boot.ini > $tmp_dir/boot.ini
perl -p -i -e "s/partition\(.*\)/partition\($sector\)/g" $tmp_dir/boot.ini
ntfscp -f $volume $tmp_dir/boot.ini /boot.ini
echo "Done"
##############################################################
For Vista imaging save the following script as windows_restore_vista.sh
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
##Restore NTFS Image ##
##This script will restore the NTFS image to the client ##
##Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
share="/Volumes/CasperShare/Extras/BootCamp/Vista/"
ntfs_image="$share/BootCamp.ntfs"
target_disk="/dev/disk0"
sector="3"
volume="/dev/disk0s3"
tmp_dir="/Volumes/Install/var/tmp"
mbr="$share/mbr"
#############################################################
## Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume to be imaged
echo "Unmounting the Volume"
diskutil unmount $volume
#Restore the NTFS image
echo "Restoring NTFS image"
ntfsclone -restore-image -overwrite "$volume" "$ntfs_image"
#Resize the NTFS volume if it is different
echo "Resizing ntfs volume"
ntfsresize -ff "$volume"
#Gather the Windows file that contains the Master Boot Record details and copy it to the boot drive
echo "Reading the file that contains MBR"
dd if=$mbr of=$tmp_dir/mbr bs=1 count=466
#Sync the GPT and BIOS partition tables and copy the MBR to the start of the disk
echo "Syncing GPT to BIOS partition table and restoring MBR"
gptrefresh -w -a $sector -f -u -m $tmp_dir/mbr $target_disk
echo "Done"
############################################################
Save the 2 scripts (partition.sh plus either XP or Vista script) into the Casper Admin Configuration setup that you will use to image the Macs with Windows. Then reboot the Macs to the NetInstall image.
Option 2
You may wish to install Windows on the clients at a later date after you have deployed the OS X image. If you have already partitioned the drive during imaging then you can just restore the NTFS image to that partition. If you have just 1 partition, then you will need to resize the drive first.
To resize the volume save the following script as volume_resize.sh and upload to Casper.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
##GPT Volume Resize ##
##This Script will resize the GPT Disk into 2 partitions, and format the second partition as MS-DOS for Windows ##
##Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
volume='/Volumes/Macintosh HD'
mac='80%'
windows='19%'
#########################################
## Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Resize the Volume
echo "Resizing the volume"
diskutil resizevolume "$volume" $mac MS-DOS WINDOWS $windows
echo "Done"
############################################
Then for XP save the following script to the CasperShare as windows_restore_XP_users.sh.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
##Restore NTFS Image ##
##This script will restore the NTFS image to the client ##
##Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
share="/Volumes/CasperShare/Extras/BootCamp/XP/"
ntfs_image="$share/BootCamp.ntfs"
target_disk="/dev/disk0"
sector="3"
volume="/dev/disk0s3"
#############################################################
## Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume to be imaged
echo "Unmounting the Volume"
diskutil unmount $volume
#Restore the NTFS image
echo "Restoring NTFS image"
ntfsclone -restore-image -overwrite "$volume" "$ntfs_image"
#Resize the NTFS volume if it is different
echo "Resizing ntfs volume"
ntfsresize -ff "$volume"
#Gather the Windows file that contains the Master Boot Record details and copy it to the boot drive
echo "Reading the file that contains MBR"
ntfscat -f "$volume" /WINDOWS/system32/dmadmin.exe > /Volumes/Install/var/tmp/dmadmin.exe
#Harvest the Master Boot Record from the last 446B of that file
echo "Harvesting the MB"
dd if=/Volumes/Install/var/tmp/dmadmin.exe of=/Volumes/Install/var/tmp/mbr skip=216616 bs=1 count=446
#Sync the GPT and BIOS partition tables and copy the MBR to the start of the disk
echo "Syncing GPT to BIOS partition table and restoring MBR"
gptrefresh -w -a $sector -f -u -m /Volumes/Install/var/tmp/mbr $target_disk
#Update the boot.ini file and copy it back the NTFS volume
echo "Updating boot.ini with the partition number"
ntfscat -f $volume /boot.ini > /Volumes/Install/var/tmp/boot.ini
perl -p -i -e "s/partition\(.*\)/partition\($sector\)/g" /Volumes/Install/var/tmp/boot.ini
ntfscp -f $volume /Volumes/Install/var/tmp/boot.ini /boot.ini
echo "Done"
#############################################################
And for Vista deployment save the following file as windows_restore_Vista_users.sh.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH
##Restore NTFS Image ##
##This script will restore the NTFS image to the client ##
##Copyright Criss Myers 2009 UCLan ##
## Script Parameters ##
share="/Volumes/CasperShare/Extras/BootCamp/Vista/"
ntfs_image="$share/BootCamp.ntfs"
target_disk="/dev/disk0"
sector="3"
volume="/dev/disk0s3"
mbr="$share/mbr"
#############################################################
## Script Contents, DO NOT EDIT BELOW THIS LINE ##
#Unmount the Volume to be imaged
echo "Unmounting the Volume"
diskutil unmount $volume
#Restore the NTFS image
echo "Restoring NTFS image"
ntfsclone -restore-image -overwrite "$volume" "$ntfs_image"
#Resize the NTFS volume if it is different
echo "Resizing ntfs volume"
ntfsresize -ff "$volume"
#Gather the Windows file that contains the Master Boot Record details and copy it to the boot drive
echo "Reading the file that contains MBR"
dd if=$mbr of=/tmp/mbr bs=1 count=466
#Sync the GPT and BIOS partition tables and copy the MBR to the start of the disk
echo "Syncing GPT to BIOS partition table and restoring MBR"
gptrefresh -w -a $sector -f -u -m /tmp/mbr $target_disk
echo "Done"
#############################################################
Next, we will create a Casper Self Service policy to allow users to image their client with Windows.
Step 1. Create a new policy in Casper JSS Web browser.
Step 2. Give it a name and category and then set the Trigger to "None (or Self Service only)"
Step 3. Set the Execution Frequency to ongoing, then scope it to who you wish to use this policy.
Step 4. Under Self Service, tick Allow and write a description for your users, give it a custom icon and perhaps feature it on the main page.
Step 5. Under Packages install the ntfsprogs.pkg
Step 6. Under Scripts add windows_restore_XP/Vista.user.sh and volume_resize.sh if you need to resize the volume.
Step 7. Set the restore script to After and the resize script to Before.
Step 8. Under advance, you can update the inventory if you are going to use Smart Computer Groups to identify clients that have been imaged with Windows.
Step 9. Test on a client that the policy works.
Rebooting into Windows
Next we need to allow the user to reboot the client to Windows, but return the Mac to OS X afterwards. By removing the BootCamp control panel from Windows the user cannot change the Startup Disk.
To allow the user to reboot the client to Windows, we will create a Self Service tool that will set the client to reboot to Windows on the next boot only, thus restarting to OS X on the later reboot.
Step 1. Create a new policy and call it "Reboot to Windows"
Step 2. Set to None (or self Service only) and set to ongoing.
Step 3. Scope to the required clients.
Step 4. Activate under Self Service and give it a description and icon.
Step 5. Under Advanced enter the following in the "Run Command" section /usr/sbin/bless -device /dev/disk0s3 -setBoot -legacy –nextonly
Step 6. Under Reboot set to Reboot Immediately.
Lastly we need to hide the Windows volume when the Mac is booted to OS X to prevent them from writing to it. I apply this to all my Macs, even if they have not been imaged with Windows. That hides the Windows volume I have set aside for Windows, so that the user does not know that the space has been allocated.
To do this we create a Startup Policy to unmount the volume:
Step 1. Create a new policy and give it a name.
Step 2. Set the Trigger to Startup and the Frequency to Ongoing
Step 3. Scope to All users
Step 4. Under Advanced add the following line under the "Run Command" diskutil unmount disk0s3
Troubleshooting
A flashing cursor and a blank screen indicates that the client cannot find the MBR details to boot the Windows volume.
Execute the script on the local box via the command line to see and errors and check the /tmp folder for boot.ini, mbr and dmadmin.exe, check the size of the files. They should be 4KB, 220KB, 4KB respectively.
Change the autorun data for the client in the JSS Web browser so that the client does not reboot once imaged. Then you can check on the Install drive that the mbr and boot.in files were created fully. In the finder go to the folder /Volumes/Install/var/tmp.
If the partition size on the client differs from the one you used to image from, then the ntfsresize tool will mark the volume as "dirty", this means that the first time you boot into Windows it will run a disk check for you. This is normal when you partition a drive using percentages, as the partitions size will vary depending on the size of the disk.
When you are creating an install for deployment, make sure that the partition size is smaller than or equal to the partition size that you will be deploying to. If you try to deploy an image that was created on a 30GB partition to a 20GB partition it will fail, saying that the destination is too small, even though the image may only be 5GB. NTFS resize will always increase the size of the install to fill the available partition.
If you want to triple image a Mac with OS X, Vista and XP then make sure you install Vista on the second partition and XP on the third. We can update the boot.ini file on XP to boot from the third partition but we cannot update the Vista boot file
Conclusion
It is easily possible to install XP or Vista onto a Mac using the Casper Suite. You can either deploy the image during the initial imaging of the client or you can allow your users to install the Windows image afterwards via Self Service. If you partition the drive during imaging, it makes it easier to deploy the Windows image later and allows you to reserve space on the client machine for this event. To prevent users from reading and writing the Windows partition under OS X you can unmount it at startup. You can also allow your users to boot into Windows on a one time only basis, thus ensuring that the client always returns to booting into OS X. This same method could in addition be used to deploy Linux.
Criss Myers is a Business Support Analyst (Mac Services), for Learning and Information Services, at the University of Central Lancashire, Preston, United Kingdom. He has been a Systems Server Administrator from the very first version of OS X Server. He Works with Macs as well as Linux, Unix and Windows and specializes in Image deployment and maintenance as well as client management.