I have an iMac running OSX Lion. I also installed bootcamp and Windows 7. During the install of Windows 7 I wasn't paying complete attention and deleted and formatted the EFI partition.
I didn't really realise the significance of this as the machine continued to work fine, booting both into Windows and OSX.
I did notice that the EFI firmware updates failed to install, but paid this no mind.
However now I want to install Mountain Lion and there's a whole heap of trouble. Mountain Lion won't install without a valid EFI partition.
Here's my partition table.
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: Apple_HFS EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 799.0 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
4: Microsoft Basic Data BOOTCAMP 200.3 GB disk0s4
As you can see I've had a go at fixing the EFI partition with the following command:
newfs_hfs -v EFI /dev/disk0s1
This didn't seem to create the correct type of partition, it created an Apple_HFS instead of EFI.
My question is (without formatting the disk) how do I create an EFI partition?
Thanks
Rich
Best Answer
You can recreate the EFI System Partition (ESP) using the command-line
gpt
tool. It should start at sector 40, and it should be 409600 sectors (exactly 200MiB) long. The GPT entry's type should beC12A7328-F81F-11D2-BA4B-00A0C93EC93B
, and if you have a hybrid MBR, the type there should beEE
. The format is actually a subset of FAT, not HFS+. You can read the GPT using the commandsudo gpt -r show disk0
in a Terminal window, this produces output that looks something like this:You can see the correct EFI partition at index 1. If that line doesn't match exactly, the easiest way is to delete the partition in its place and recreate it.
Make sure you know what you're doing before proceeding from here - you may lose data if you mess up.
You can't edit the partition table using
gpt
while partitions on the drive are mounted, so you'll need to boot from another drive (e.g. a USB stick with the OSX installer) or run the mac in target disk mode and do the partitioning from another mac. You may need to unmount any automatically mounted volumes usingdiskutil unmountDisk disk0
before proceeding, and in between commands.To delete your "bad" EFI partition, run this command:
Make sure disk0 is really the disk you want to change - the numbers can change between reboots. Also, this will only work if you already have a non-ESP partition in the place of the ESP - if not, deleting partition 1 could be disastrous! In this case, you'll need to move the indices along, as I think the ESP must have index 1. By the sound of it, this won't be necessary in your case.
Once deleted, re-add the partition with the correct layout and type:
This should sort out the partition itself, but as you've created an HFS partition in its place, you need to fix its format as well.
The format of the EFI System Partition is documented by Apple here. As you can see, they recommend you clone an existing ESP rather than recreating the file system with
newfs_msdos
. If you have an external drive with a GPT partition table (OSX install stick should have it), you can clone that.Make sure you have your disk and partition numbers the right way around or you may overwrite data:
If disk1 is your external drive, and it contains an ESP as the first partition (disk1s1) and disk0 is the drive whose ESP (disk0s1) you want to fix, run this command:
This will copy every single block of disk1's ESP and overwrite the corresponding block in disk0's ESP with it.
Alternatively, take a gamble with
newfs_msdos
.