Jump to content

CLI guide for UEFI + GPT dual boot

command line terminal command prompt dual boot uefi gpt guid

  • Please log in to reply
3 replies to this topic

#1
slemblod

slemblod

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Not Telling

Preface:

After a long time trying different methods, this is the one that finally worked. Credits to ctugt for the inspiration. This is a CLI guide for an UEFI motherboard with a GUID partitioned disk. On this configuration, both OS X and Windows require an EFI partition, and it can host all files necessary to boot both OS's, with a little tinkering. The only conflict is with the two files in [EFI partition]/EFI/BOOT/. This will be explained further in step 4. You will require the use of the Clover boot loader.

 

Step 1:

Create bootable USB's for both OS X and Windows. I used OS X 10.9.4 and Windows Server 2012 R2, though you can perform the exact same steps on most recent OS X versions and Windows 8 or 8.1 as they are practically the same.

 

Step 2: OS X installation

Boot your OS X USB. Select from the menu bar: Utilities -> Terminal.

We begin by clearing the partition table (delete all data) on the disk we are going to dual boot from. In most cases this is disk0. In the gpt add commands, replace the size of the partition with your own sizes. Note that the actual size of the partition is roughly half the size shown here (my drive in the example is 256 GB, with 1 200MB partition and 2 128GB partitions). Use the gpt show command if you are uncertain. After creating the GPT, we verify it using gpt show and notice the similarities with the output of diskutil list. Following this, we initialise the partitions with FAT32, JHFSX, and exFAT, respectively. The last two commands mounts the JHFSX partition and installs OS X onto it.

diskutil unmountDisk disk0
gpt destroy disk0
diskutil unmountDisk disk0
gpt create -f disk0
diskutil unmountDisk disk0
gpt add -b 34 -s 409600 -t windows disk0
gpt add -b 409634 -s 249854262 -t hfs disk0
gpt add -b 250263896 -s 249854263 -t windows disk0
gpt show disk0
diskutil list disk0
newfs_msdos -F 32 -v EFI disk0s1
newfs_hfs -s -J -v OS\ X disk0s2
newfs_exfat -v Windows disk0s3
diskutil mount disk0s2
installer -pkg /System/Installation/Packages/OSInstall.mpkg -target /Volumes/OS\ X/ -lang en

Step 3: Windows installation

Boot your Windows USB. Press Shift + F12 at any part of the installation to open a command prompt.

The first 4 commands mount the EFI partition for later use. The next 3 commands format the Windows partition as NTFS, which is required for installing Windows onto it. The next 2 commands just verify what we previously did. exit exits from diskpart mode. I am unsure if the c: command really is necessary, but I have not tried without it. Adventure at your own risk. The next command installs Windows onto the disk. If you are installing Windows 8 or 8.1, replace /index:2 with /index:1. The final command creates files necessary for booting Windows.

diskpart
sel disk 0
sel part 1
assign letter=e
sel part 3
format fs=ntfs quick label=Windows
assign letter=c
list part
list vol
exit
c:
dism /apply-image /imagefile:d:\sources\install.wim /index:2 /applydir:c:\
bcdboot c:\windows /s e:

Step 4: Configuring the EFI partition for dual boot

Boot your OS X USB again. Select from the menu bar: Utilities -> Terminal.

These commands remove two conflicting files created by the Windows installer with the bcdboot command we entered earlier. Removing these and replacing them with Clover allows you to boot both OS's. You should be able to boot Windows either from your UEFI boot menu (usually accessed by pressing F12 at startup) or by selecting "Windows EFI Boot" from Clover.

diskutil mount disk0s1
diskutil mount disk1s1
cp -rfX /Volumes/EFI\ 1/ /Volumes/EFI/

Step 5: Reinstallation

If you ever need to reinstall your OS's, the procedure is much shorter as the disk is already partitioned with the correct EFI files in place, but uses some of the same commands from earlier.

For OS X:

newfs_hfs -s -J -v OS\ X disk0s2
installer -pkg /System/Installation/Packages/OSInstall.mpkg -target /Volumes/OS\ X/ -lang en

For Windows:

diskpart
sel disk 0
sel part 3
format fs=ntfs quick label=Windows
assign letter=c
exit
dism /apply-image /imagefile:d:\sources\install.wim /index:2 /applydir:c:\

Thanks for taking the time to read my guide. If anything is unclear, or you have a question regarding something related, please do not be afraid to ask. Good luck!

 

Helpful links:

diskutil gpt newfs_msdos newfs_hfs newfs_exfat installer cp

diskpart dism bcdboot

 

Example outputs:

gpt show disk0:

bash-3.2$ gpt show disk0
      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409634  249854262      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  250263896  249854263      3  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  500118159         32         Sec GPT table
  500118191          1         Sec GPT header

diskutil list disk0:

bash-3.2$ diskutil list disk0
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *256.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS OS X                    127.9 GB   disk0s2
   3:       Microsoft Basic Data Windows                 127.9 GB   disk0s3


#2
frankiee

frankiee

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 212 posts
  • Gender:Male
  • Location:Earth
  • Interests:Everything

nice, compact guide!

 

One question: why did you not create any recovery partitions, neither for OS X nor for windows?

 

For comparison, I have both - here is what it looks like then:

   0:      GUID_partition_scheme                        *1.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS OS X                    700.0 GB   disk1s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk1s3
   4:         Microsoft Reserved                         134.2 MB   disk1s4
   5:       Microsoft Basic Data Windows                 298.8 GB   disk1s5
   6: DE94BBA4-06D1-4D40-A16A-BFD50179D6AC               367.0 MB   disk1s6


#3
vinnychase

vinnychase

    InsanelyMac Protégé

  • Members
  • Pip
  • 3 posts

are there any changes for this guide with 2 ssd's instead of 1 drive? 



#4
slemblod

slemblod

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Not Telling


nice, compact guide!

One question: why did you not create any recovery partitions, neither for OS X nor for windows?

For comparison, I have both - here is what it looks like then:

0:	  GUID_partition_scheme					    *1.0 TB	 disk1   1:					    EFI EFI					 209.7 MB   disk1s1   2:				  Apple_HFS OS X				    700.0 GB   disk1s2   3:				 Apple_Boot Recovery HD			 650.0 MB   disk1s3   4:		 Microsoft Reserved						 134.2 MB   disk1s4   5:	   Microsoft Basic Data Windows				 298.8 GB   disk1s5   6: DE94BBA4-06D1-4D40-A16A-BFD50179D6AC			   367.0 MB   disk1s6
I personally don't use recovery partitions as the installer USB's have most of the same functionality. Thanks for letting me know it works, though!

are there any changes for this guide with 2 ssd's instead of 1 drive?

I don't think so. I guess you could create 1 EFI partition on each drive and place the corresponding OS's EFI files there. Though I really think it's fine to partition them something like this:
disk 1:
• EFI part
• OS X partition
disk 2:
• Windows partition





Also tagged with one or more of these keywords: command line, terminal, command prompt, dual boot, uefi, gpt, guid


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy