If you are trying to install Windows 7 on a 2012 through 2014 Mac, then you should read my answer to this question.
Here I assume your computer is configured as required by the Boot Camp Assistant. (In other words, you will be installing Windows to the 4th partition on disk 0.) Also, your firmware is up to date and you have downloaded the correct "Boot Camp Support Software" for your model Mac computer. Before starting, remove all DVD's and external devices from your Mac.
Create a MS-DOS (FAT) formatted partition on your Macs internal
drive. This is where Windows 7 will be installed. You can use the
Bootcamp Assistant, the Disk Utility, or commands (distutil
, gpt
and/or fdisk
) entered in a Terminal window. Other third party
tools, such as gdisk
, can also be used. Give the label for
this partition the name "BOOTCAMP". When finished, quit all
applications.
This procedure requires the "BOOTCAMP" partition be the 4th partition on your Macs internal drive (disk0). If you are using the
Disk Utility from OS X 10.7 or newer and your Mac has the default
drive configuration, then the new "BOOTCAMP" partition should be
created as the 4th partition automatically. However, if you are using APFS and the default drive configuration, then the new "BOOTCAMP" partition should be
created as the 3th partition automatically.
Make sure the drive is using the GPT/MBR hybrid partitioning scheme. See my answer to the question "How to convert a drive from the GPT format to the hybrid GPT/MBR format when using High Sierra (macOS 10.13.2)" for a procedure that accomplishes this task.
User Semi has noted that the Boot Camp Assistant (BCA) will correctly GPT/MBR hybrid partition the drive. So, you may be able to the the BCA to partition the drive, then use the flash drive to install Windows.
Download and install a free copy of VirtualBox. I used
VirtualBox 5.0.14 r105127, Copyright © 2016.
Do the following to transfer the "Boot Camp Support Software" to a
partition compatible with VirtualBox. Create folder named
"VirtualBox" in your Documents folder. Open the Disk Utility and
from the menu bar select File->New->Blank Disk Image. Create
this image in the "VirtualBox" folder using the following
parameters.
Using the Finder application, copy the "Boot Camp Support Software"
to this new partition. When finish, this new partition should appear
in the Finder as shown below. (For readers with older Macs, you may
only have the "BootCamp" folder.)
This step will create the file needed by VirtualBox to access the
partition containing the "Boot Camp Support Software". In a Terminal
application window, enter the following commands.
Note: I assume you are using the default Bourne-Again Shell (bash).
cd ~/documents/virtualbox
open bcss.dmg
DISK1=$(mount|awk -F s1 '/BCSS/{print$1}')
diskutil unmountDisk $DISK1
vboxmanage internalcommands createrawvmdk -filename "$PWD/bcss.vmdk" -rawdisk $DISK1
The result should be the creation of the file bcss.vmdk
in your
"VirtualBox" folder. Later, you will select this file to give a
virtual machine access to this partition.
Note: At this point, one should realize it would be easier to copy the commands from this document and paste them into the Terminal
application window.
This step will create the files needed by VirtualBox to access the
physical partition where you will install Windows. In a Terminal
application window, enter the following commands.
cd ~/documents/virtualbox
DISK0=/dev/disk0
PARTITION=4
PARTID="$DISK0"s"$PARTITION"
diskutil unmount $PARTID
sudo chmod go+rw $PARTID
sudo vboxmanage internalcommands createrawvmdk -filename "$PWD/bootcamp.vmdk" -rawdisk $DISK0 -partitions $PARTITION
sudo chown $USER bootcamp*.vmdk
Note: This access granted by the chmod
command will only last
until OS X is rebooted.
The result should be the creation of the files bootcamp.vmdk
and
bootcamp-pt.vmdk
in your "VirtualBox" folder. Later, you will
select the file bootcamp.vmdk
to give a virtual machine access to
the physical partition.
Note: OS X prefers to automount file systems. This can be disabled for a particular partition by creating or modifying the /etc/fstab
file. Instead of employing the /etc/fstab
file, the user is asked
to repeatedly enter the following commands.
diskutil unmount $PARTID;diskutil unmountDisk $DISK1
These commands unmount the physical "BOOTCAMP" partition and the disk image file bcss.dmg
containing the "BCSS" partition.
Configure the virtual machine. Open the VirtualBox application and
click on icon above the New label. Enter or select the values shown
below, then click the "Continue" button.
Use the default settings except for the hard drive. Choose the "Use
an existing virtual hard drive file" button. Navigate to your
"VirtualBox" folder. Highlight the bootcamp.vmdk
file. Before
clicking the "Open" button, enter the following commands in the same
Terminal application window.
diskutil unmount $PARTID;diskutil unmountDisk $DISK1
Open the bootcamp.vmdk
file. Your window should appear similar to
what is shown below.
Click the "Create" button.
After returning to the VirtualBox application's "Oracle VM
VirtualBox Manager" window, click on the icon above the
"Settings" label. Next, click on the icon above the "Storage" label.
In the "Storage Tree", "Controller: SATA" should be highlighted.
Right click on this highlighted area and select "Add Hard Disk".
Choose the "Use an existing virtual hard drive file" button.
Navigate to your "VirtualBox" folder. Highlight the bcss.vmdk
file. Before clicking the "Open" button, enter the following
commands in the same Terminal application window.
diskutil unmount $PARTID;diskutil unmountDisk $DISK1
Open the bcss.vmdk
file. Next, select the "Use Host I/O Cache"
option. Your window should appear similar to what is shown below.
Highlight the Empty CD/DVD and select "Choose Virtual Optical Disk
File..." to attach your Windows 7 iso file. (Hint: Look for the
CD/DVD icons)
Click OK to close the window. Your "Oracle VM VirtualBox Manager"
window should appear similar to what is shown below.
In this step, you will copy the necessary files to the physical
partition, so later you can restart your Mac and install Windows.
Enter the following commands in the same Terminal application
window.
diskutil unmount $PARTID;diskutil unmountDisk $DISK1
Next, click on the icon above the "Start" label to boot from the
Windows 7 iso file. Press the space bar, if prompted to "Press any
key to boot from CD or DVD."
Note: The mouse pointer must be over the virtual machine screen window before you press the space bar.
When the display below appears, click the "Next" button.
When the display below appears, click the "Install now" button.
The message "Setup is Starting…" should appear, followed by the display shown below.
Reaching this point causes any necessary drivers to be loaded. Next, click on the red box with the white "X". If prompted, click on "Yes". When the display below appears, select "Repair your computer".
With the button "Use recovery tools that can help fix problems
starting Windows." selected, click the Next button.
Select the "Command Prompt" option.
Insure the drive letters C
through F
are not assigned by default
to a volume by entering the following commands.
mountvol c: /d >nul
mountvol d: /d >nul
mountvol e: /d >nul
mountvol f: /d >nul
Enter the following to determine a list of the current volumes.
diskpart
list volume
The image below displays the volumes found on my Mac. You may get
different results.
Enter the following commands, to assign the drive letters D
, C
and E
to the CD-ROM volume and the volumes labeled "BOOTCAMP" and
"BCSS", respectively. In the image shown above, these are volumes 0,
3 and 4. If your volume indices are different, make the appropriate
substitutions. Also, NTFS format the "BOOTCAMP" volume.
select volume 3
assign letter=c
format quick fs=ntfs label=BOOTCAMP
select volume 0
assign letter=d
select volume 4
assign letter=e
list volume
exit
When finished, the volume letters should appear similar to what is
shown below.
Next, enter the commands givens below. The bootsect
command writes
boot code to a Volume Boot Record (VBR) of a partition and Master
Boot Record (MBR) of the corresponding drive.
bootsect /nt60 c: /mbr
bootsect /nt60 e: /mbr
The next sequence of commands creates a Virtual Hard Disk (VHD)
file. The VHD represents a virtual flash drive from which Windows
will be installed on to the physical "BOOTCAMP" partition.
Note: If you are installing Windows 10, then the parameter fs=fat32
, in the format
command shown below, should be replaced
with fs=ntfs
.
diskpart
create vdisk file=c:\flashdrive.vhd maximum=8000 type=fixed
attach vdisk
create partition primary
format quick fs=fat32 label=FLASHDRIVE
assign letter=f
exit
Finally, copy the Windows installer iso and "Boot Camp Support
Software" files first to VHD, then directly to the physical
partition where Windows is to be installed. Exit the Command Prompt
window when finished.
xcopy d:* f: /s /h
xcopy e:* f: /s /y
xcopy f:* c: /s /h
exit
Note: The files \sources\boot.wim
and \sources\install.wim
take a long time to copy. The file sizes are 168 MB and 2.95 GB,
respectively.
Select the "Shut Down" button to shutdown the virtual machine. Quit
the VirtualBox application.
This step will involve configuring Master Boot Record (MBR) of your
physical internal drive. The MBR is stored on the first 512 bytes of
this drive. This space is shared by boot code and the MBR partition
table.
This step can not be preformed under OS X 10.11 (El Capitan) with System Integrity Protection (SIP) turn on. (This is the default
setting.) If you are using OS X 10.11, you must disable SIP,
complete this step, then restore SIP. See the link: How do I
disable System Integrity Protection (SIP) AKA “rootless” on OS X
10.11, El Capitan?.
In a Terminal application window, enter the following commands. The
first fdisk
command flags the "BOOTCAMP" partition as the active
partition. The second fdisk
command changes the "BOOTCAMP"
partition id to 7. The final fdisk
command copies the boot code
from the MBR of the disk containing the "Boot Camp Support Software"
partition to the MBR of the physical disk containing the "BOOTCAMP"
partition.
cd ~/documents/virtualbox
DISK0=/dev/disk0
PARTITION=4
PARTID="$DISK0"s"$PARTITION"
open bcss.dmg
DISK1=$(mount|awk -F s1 '/BCSS/{print$1}')
INPUT=$(printf "f $PARTITION\nq\ny")
sudo fdisk -e $DISK0 <<<"$INPUT" &>/dev/null
INPUT=$(printf "s $PARTITION\n7\nq\ny")
sudo fdisk -e $DISK0 <<<"$INPUT" &>/dev/null
sudo fdisk -u -y -f $DISK1 $DISK0
diskutil mount $PARTID
Note: To display the value for the variable INPUT, use the command echo "$INPUT"
.
This is the step where you install Windows to your "BOOTCAMP"
partition. Restart your Mac and hold down the option/alt
key. Select the Windows icon to boot from the "BOOTCAMP" partition.
Open a Command Prompt window, by navigating through the displays as you did in step 8. Enter the commands below to attach the "FLASHDRIVE" partition stored in the Virtual Hard Disk (VHD) file.
diskpart
select vdisk file=c:\flashdrive.vhd
attach vdisk readonly
list volume
exit
On my Mac, the output from the list volume
command shows E
to
be the drive letter assigned to the "FLASHDRIVE" partition. If your
drive letter is different, make the correct substitution when
entering the e:\setup
command given at the end of this step. Next,
remove all the files, but one, from the "BOOTCAMP" partition.
rmdir /s /q c:\
If the above command executes correctly, you should get the error message: "c:\flashdrive.vhd - The process cannot access the file
because it is being used by another process."
Start installing Windows 7 by entering the command given below.
Select "BOOTCAMP" as your installation partition.
e:\setup
The installation files are stored in the "FLASHDRIVE" partition.
Since this partition is stored as a VHD file in the "BOOTCAMP"
partition, do not try to reformat the "BOOTCAMP" partition. You will
remove these installation files in a later step. When your Mac
restarts, it will boot to OS X. This is to be expected. From the
"System Preferences" select Windows as your startup disk and restart
the Mac. Your Windows installation will continue.
Once Windows finishes installing, the "Boot Camp Support Software"
can be applied. To access this software, the c:\flashdrive.vhd
file, containing the "FLASHDRIVE" partition, needs to be attached.
Click on the "Start" button, type in diskmgmt.msc
and hit the
return key. Once in Disk Management, click on Action
in the menu bar and select Attach VHD. Select the file location
and check "Read-only" to prevent writes to the VHD file. After you
hit "OK", the drive will show up in Disk Management with a blue
icon. Close Disk Management.
In the AutoPlay popup window, select "Open folder to view files."
(If no popup appears, use the Windows Explorer to open the drive
labeled "FLASHDRIVE".) The setup.exe
file can be found in the
folder labeled "BootCamp". Execute this application to install the
"Boot Camp Support Software". The VHD file will detach when the
computer restarts.
Finally, remove DVD and "Boot Camp Support Software" folders and
files. This can be accomplished by dragging the
c:\flashdrive.vhd
file to the Recycle Bin. If you get an error
message about the file being open, restart the computer and try
again.
The "Virtual Box" folder can be deleted. You will probably need to eject the "BCSS" partition first.
You can delete the "BootCamp" virtual machine. This can be done from the VirtualBox application. If VirtualBox does not remove all the files, you can remove them manually. Look in the ~/"VirtualBox VMs"
folder.
You can delete the Windows 7 iso file.
You can remove the VirtualBox application, but since it takes such little space, I would not bother.