Shell script to post image a machine with a boot camp partition

This script I have tested and used in the Casper Suite in my actual enterprise work environment.  Over this last summer we imaged 6,000 Macbooks with a dual boot image.  I created the Image by building it manually from scratch with boot camp and a Windows XP SP2 CD.  I then used this shell script to create my image.  So, in the JSS, which is a server that holds policies and auto run data (amognst other things) I set a configuration for every client machine that is tied to the student smart group to run an OS X image, and then immediately run this script afterward.  This script will resize the OS X partition, and then pull down the boot camp image from the AFP share.  It is all automated and I applied this method to our 6,000 client machines.  I think our record was at 600 Macbooks imaged in one 12 hour day.  Not too shabby, and that was the day we actually worked really hard!   #!/bin/sh PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH ## DISK PARTITIONING PARAMETERS#set the size you want the windows partition by percentagevolume='/Volumes/Macintosh HD'mac='80%'windows='19%'## BOOT CAMP SOURCE IMAGE PARAMETERS#input your path to the image file and the share pointCasperShare="/Volumes/CasperShare"ntfs_image="$CasperShare/Packages/BootCamp.ntfs" # Optionally, you can set the following values explicitly root_target_disk="disk0" # e.g. "disk0" raw_target_dev="/dev/rdisk0" # e.g. "/dev/rdisk0" ntfs_slice_num="3" # e.g. "3" ntfs_dev="/dev/disk0s3" # e.g. "/dev/disk0s3" ### SCRIPT ACTION ### # Resize the disk/usr/sbin/diskutil resizeVolume "$volume" $mac MS-DOS windows $windows# Determine, based on the target path passed to the script, what is the device # number of the NTFS partition on the same drive if [ "$root_target_disk" == "" ]; then root_target_disk=`df "$1" | awk '!/Filesystem/ {print $1}' | cut -c 6-10` fi root_target_dev=/dev/$root_target_disk echo "root_target_dev: $root_target_dev" if [ "$raw_target_dev" == "" ]; then raw_target_dev=/dev/r$root_target_disk fi echo "raw_target_dev: $raw_target_dev" if [ "$ntfs_slice_num" == "" ]; then ntfs_slice_num=`diskutil list $root_target_dev | awk 'BEGIN {disk = "nodisk"} {sub("disk\.s", "")} ($NF < 5 && /Microsoft Basic Data/) {disk = $NF} END {print disk}'` if [ "$ntfs_slice_num" == "nodisk" ]; then echo "Failed to determine the NTFS device slice number -- try adding it to the $0 script explicitly \(target disk is $root_target_dev\)" exit 1 fi fi echo "ntfs_slice_num: $ntfs_slice_num" if [ "$ntfs_dev" == "" ]; then ntfs_dev=/dev/disk0s$ntfs_slice_num fi echo "ntfs_dev: $ntfs_dev" echo "" echo "Unmounting the target disk..." diskutil unmount $ntfs_dev echo "Restoring disk image to target volume..." ntfsclone --restore-image --overwrite "$ntfs_dev" "$ntfs_image" echo "Resizing target volume to partition limit..." ntfsresize -ff "$ntfs_dev" echo "Reading file that contains MBR..." ntfscat -f "$ntfs_dev" /WINDOWS/system32/dmadmin.exe > /tmp/dmadmin.exe echo "Harvesting MBR..." dd if=/tmp/dmadmin.exe of=/tmp/mbr skip=216616 count=446 bs=1 echo "Syncing GPT to BIOS partition table and restoring MBR..." gptrefresh -w -a $ntfs_slice_num -f -u -m /tmp/mbr $root_target_dev echo "Updating boot.ini partition number..." ntfscat -f $ntfs_dev /boot.ini > /tmp/boot.ini perl -p -i -e "s/partition\(.*\)/partition\($ntfs_slice_num\)/g" /tmp/boot.ini ntfscp -f $ntfs_dev /tmp/boot.ini /boot.ini echo "Mounting the target disk..." diskutil mount "$ntfs_dev"   Now you will have to edit this script if you aren't using the Casper Suite, since a lot of the data relies on what you set up in the JSS server.  You could replace it with absolute network paths if you were using say, Bombich's netrestore.  However, I have not tested it but I would assume you could get it to work. I would now like to add that this script is part of the Casper Resource Kit provided by JAMF software.  It was originally written by one of their staff.  They do not officially support it, but I used this script during our Summer 08 mass imaging project and it worked for me.
Your rating: None Average: 5 (4 votes)

Comments

This is now obsolete

Please note that while I will leave this script here, it is depreciated as Casper 7 now has better support for imaging Windows onto Macintosh client computers.