UEFI Dual boot with Windows 7/8

Prerequisites:
A UEFI computer with Windows 7 x64 or Windows 8 x64 installed on a gpt partitioned hard drive and booting in uefi mode. Secure Boot disabled in BIOS.

WINDOWS 7:
Type "disk management" in the search window

Select "Create and format hard disk partitions" from the top of the list

Right click on the target partition and choose “shrink volume”

Provide the size of the shrink

WINDOWS 8:
Press Windows-x (windows key and x key simultaneously).

Choose “Disk Management”

Right click on the target partition and choose “shrink volume”

Provide the size of the shrink

Download and install rEFInd in Windows
Get rEFInd

Extract refind-bin-0.6.12.zip to a handy location.

Get directions; then install rEFInd from Windows to the Windows EFI System partition (ESP)

Obtain UEFI bootable linux media
Get a System Rescue Cd iso

Create a System Rescue Cd or System Rescue USB flash drive

Mount the sysresccd or sysrescusb and restart the computer. The CD or USB should appear as a choice in the rEFInd menu.

Install Gentoo.
Exceptions/additions to the Gentoo Handbook:

Use gdisk instead of fdisk or parted to create gentoo partitions.
START OF GDISK EXAMPLE:

gdisk /dev/sda

GPT fdisk (gdisk) version 0.8.6

Partition table scan:

MBR: protective

BSD: not present

APM: not present

GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p

Disk /dev/sda: 500118192 sectors, 238.5 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): C72786B7-C1FB-4A60-8F5F-216FA9097A98

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 500118158

Partitions will be aligned on 2048-sector boundaries

Total free space is 123357805 sectors (58.8 GiB)

Number Start (sector)    End (sector)  Size       Code  Name 1           2048          616447   300.0 MiB   2700  Basic data partition

2         616448          821247   100.0 MiB   EF00  EFI system partition

3         821248         1083391   128.0 MiB   0C01  Microsoft reserved part

4        1083392       376762367   179.1 GiB   0700  Basic data partition

Command (? for help): n

Partition number (5-128, default 5):

First sector (34-500118158, default = 376762368) or {+-}size{KMGTP}:

Last sector (376762368-500118158, default = 500118158) or {+-}size{KMGTP}: +100M

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300):

Changed type of partition to 'Linux filesystem'

Entering GPTPart::SetName(const UnicodeString...)

Command (? for help): n

Partition number (6-128, default 6):

First sector (34-500118158, default = 376967168) or {+-}size{KMGTP}:

Last sector (376967168-500118158, default = 500118158) or {+-}size{KMGTP}: +1G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): 8200

Changed type of partition to 'Linux swap'

Entering GPTPart::SetName(const UnicodeString...)

Command (? for help): n

Partition number (7-128, default 7):

First sector (34-500118158, default = 379064320) or {+-}size{KMGTP}:

Last sector (379064320-500118158, default = 500118158) or {+-}size{KMGTP}:

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300):

Changed type of partition to 'Linux filesystem'

Entering GPTPart::SetName(const UnicodeString...)

Command (? for help): p

Disk /dev/sda: 500118192 sectors, 238.5 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): C72786B7-C1FB-4A60-8F5F-216FA9097A98

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 500118158

Partitions will be aligned on 2048-sector boundaries

Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector)    End (sector)  Size       Code  Name

1           2048          616447   300.0 MiB   2700  Basic data partition

2         616448          821247   100.0 MiB   EF00  EFI system partition

3         821248         1083391   128.0 MiB   0C01  Microsoft reserved part

4        1083392       376762367   179.1 GiB   0700  Basic data partition

5      376762368       376967167   100.0 MiB   8300  Linux filesystem

6      376967168       379064319   1024.0 MiB  8200  Linux swap

7      379064320       500118158   57.7 GiB    8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING

PARTITIONS!!

Do you want to proceed? (Y/N): y

OK; writing new GUID partition table (GPT) to /dev/sda.

The operation has completed successfully.

END OF GDISK EXAMPLE

Make file systems:

mkfs.ext2 /dev/sda5

mkfs.ext4 /dev/sda7

mkswap /dev/sda6

swapon /dev/sda6

As long as the EFI stub kernel is in an ext2, ext3, ext4, reiser, or fat32 file system rEFInd will find it and add it to the menu.

Run blkid:

EXAMPLE RETURN: /dev/sda7: UUID="1f43e373-f923-4ec2-a62e-6a0d98927583" TYPE="swap" PARTLABEL="Linux filesystem" PARTUUID="92d3d504-9e7e-4c3d-9e56-15e3bd43511b"

The / partition PARTUUID will be used in the kernel configuration in the form root=PARTUUID=92d3d504-9e7e-4c3d-9e56-15e3bd43511b. Keep it handy.

Continue with the handbook through "7. Configuring the Kernel".

Kernel configuration:
Use either "7.b. Default: Manual Configuration" or "7.c. Alternative: Using genkernel" but start genkernel with 'genkernel --menuconfig all' vice just 'genkernel all'. In addition to the items specified in the handbook or set by genkernel, enable the following:

In menuconfig:

-*- Enable the block layer --->

Partition Types --->

[*]  PC BIOS (MSDOS partition tables) support

[*]  EFI GUID Partition support

Processor type and features --->

[*] Built-in kernel command line

(root=PARTUUID=92d3d504-9e7e-4c3d-9e56-15e3bd43511b) Built-in kernel command string EXAMPLE USE CORRECT PARTUUID FOUND WITH BLKID

[*]  Built-in command line overrides boot loader arguments

Firmware Drivers --->

<*> EFI Variable Support via sysfs

Device Drivers --->

Graphics support --->

<*> Support for frame buffer devices --->

[*]  EFI-based Framebuffer Support

File systems --->

Pseudo filesystems --->

-*- /proc file system support

[*]  /proc/kcore support

[*] Tmpfs virtual memory file system support (former shm fs)

[*]  Tmpfs POSIX Access Control Lists

-*-  Tmpfs extended attributes

[*] HugeTLB file system support

<*> Userspace-driven configuration filesystem

UEFI does not support loading a separate initramfs for your kernel. So if you need an initramfs, it has to be built into the kernel via CONFIG_INITRAMFS_SOURCE. It must be an uncompressed CPIO archive with .cpio filename extension.

Example of converting a genkernel built initramfs: xzcat /boot/initramfs-genkernel-x86_64-3.9.6-gentoo > /boot/initramfs.cpio

If an initramfs is used, enable these additional kernel configuration items:

General setup --->

[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support

(initramfs.cpio) Initramfs source file(s)

(0)    User ID to map to 0 (user root) (NEW)

(0)    Group ID to map to 0 (group root) (NEW)

Built-in initramfs compression mode (None) --->

Use make && make modules_install && make install to build a manual kernel. Finish the handbook. No need to emerge or install grub or lilo or grub2. REFInd will act as boot manager.