Tuesday, August 18, 2015

Setting up a Bootable EFI

In my setup I continued on my old post Multi-Boot PE using Grub4Dos. I did not re-formatted my HDD in GPT, it is still in MBR.
But before going to setup best to know what you are against.

What is EFI or Extensible Firmware Interface?
According to Wikipedia, the EFI System partition (ESP) is a partition on a data storage device (usually a hard disk drive or solid-state drive) that is used by computers adhering to the Unified Extensible Firmware Interface (UEFI).

When a computer is powered up and booted, UEFI firmware loads files stored on the ESP to start installed operating systems and various utilities. An ESP needs to be formatted with a file system whose specification is based on the FAT file system and maintained as part of the UEFI specification; therefore, the file system specification is independent from the original FAT specification.

ESP contains the boot loader programs for all installed operating systems (which are contained in other partitions on the same or other storage device), device driver files for devices present in a computer that are used by the firmware at boot time, system utility programs that are intended to be run before an operating system is booted, and data files such as error logs.


Also making the story short if you will read the Wikipedia UEFI can boot on MBR (thru CSM) and GPT. Also from my short study I found that to be able to boot on UEFI your primary partition needs the following file & folder structure...

(From rodsbooks)
The default/fallback boot loader, EFI/BOOT/bootx64.efi
The Windows boot loader, EFI/Microsoft/Boot/bootmgfw.efi
The OS X boot loader, System/Library/CoreServices/boot.efi (typically stored on the OS X system partition)
An EFI shell program, shellx64.efi, if it's stored in the root of the ESP


Also see "www.uefi.org/registry"

What is MBR?
MBR standards for Master Boot Record. It was introduced with IBM PC DOS 2.0 in 1983.
It’s called Master Boot Record because the MBR is a special boot sector located at the beginning of a drive. This sector contains a boot loader for the installed operating system and information about the drive’s logical partitions. The boot loader is a small bit of code that generally loads the larger boot loader from another partition on a drive. If you have Windows installed, the initial bits of the Windows boot loader reside here — that’s why you may have to repair your MBR if it’s overwritten and Windows won’t boot. If you have Linux installed, the GRUB boot loader will typically be located in the MBR.

MBR works with disks up to 2 TB in size, but it can’t handle disks with more than 2 TB of space. MBR also only supports up to four primary partitions — if you want more, you have to make one of your primary partitions an “extended partition” and create logical partitions inside it. This is a silly little hack and shouldn’t be necessary.

Hello GPT!
GPT stands for GUID Partition Table. It’s a new standard that’s gradually replacing MBR. It’s associated with UEFI — UEFI replaces the clunky old BIOS with something more modern, and GPT replaces the clunky old MBR partitioning system with something more modern. It’s called GUID Partition Table because every partition on your drive has a “globally unique identifier,” or GUID — a random string so long that every GPT partition on earth likely has its own unique identifier.

This system doesn’t have MBR’s limits. Drives can be much, much larger and size limits will depend on the operating system and its file systems. GPT allows for a nearly unlimited amount of partitions, and the limit here will be your operating system — Windows allows up to 128 partitions on a GPT drive, and you don’t have to create an extended partition.

On an MBR disk, the partitioning and boot data is stored in one place. If this data is overwritten or corrupted, you’re in trouble. In contrast, GPT stores multiple copies of this data across the disk, so it’s much more robust and can recover if the data is correupted. GPT also stores cyclic redundancy check (CRC) values to check that its data is intact — if the data is corrupted, GPT can notice the problem and attempt to recover the damaged data from another location on the disk. MBR had no way of knowing if its data was corrupted — you’d only see there was a problem when the boot process failed or your drive’s partitions vanished.

source: http://www.howtogeek.com/193669/whats-the-difference-between-gpt-and-mbr-when-partitioning-a-drive/

Now on to the main topic!!!
Now on my setup I used the Ubuntu 15.04 x64 LiveCD and I extracted the ISO to my HDD first partition. It uses Grub2 to boot. Note that I did not remove my Grub4DOS in the MBR and don't worry as UEFI will not use MBR if you configured BIOS to boot UEFI.

Here's the folder where UEFI will search into as said above "/EFI/BOOT/" and files bootx64.efi & grubx64.efi is present in that folder.
On folder /boot/grub/ is where the menu is located and the files it needs. If you want to modify the menu like me find the file "grub.cfg".

I modified it to my liking and here is the new content. You may compare it to the original after you downloaded your own Ubuntu 15.04 ISO.

=====
if loadfont /boot/grub/font.pf2 ; then
set gfxmode=800x600
insmod efi_gop
insmod efi_uga
insmod gfxterm
insmod vbe
insmod jpeg
terminal_output gfxterm
fi

background_image /boot/grub/BootLogo.jpg     < --- I created my own boot logo
set menu_color_normal=brown/black
set menu_color_highlight=black/light-gray

menuentry "Boot Ubuntu GNOME 15.04 X64" {
set gfxpayload=keep
linux /casper/vmlinuz.efi  file=/cdrom/preseed/ubuntu-gnome.seed boot=casper quiet splash ---
initrd /casper/initrd.lz
}

menuentry "Boot Microsoft Windows x64" {   < --- I added this for my Windows boot
    insmod part_gpt
    insmod fat
    insmod search_fs_uuid
    insmod chain
    search --fs-uuid --no-floppy --set=root CHAN-GEME    < --- set the volume serial of the second partition
    chainloader /efi/boot/bootx64.efi
}
=====

My HDD has 3 partitions actually. They are:
1. Boot partition (8GB Fat32) - Named as GrubEFI or "Grub & EFI" as it boots Grub4DOS & Grub2 EFI
2. Scratch parition (8GB Fat32) - This is my second partition where I can change to any OS I want. I just delete and copy the new OS installer here.
3. Data Parition (the rest of the space & NTFS) - as it says just "Data". Also it stores my OS backup for SCRATCH partition.

That's all! I just laid out the files on the primary partition and Ubuntu 15.04 Grub2 works out of the box. The menu entry for Windows is optional. Note that you don't need Grub2 to boot windows, I just want to have a control or a boot menu rather than just it booting directly to only 1 OS. You could copy your Windows x64 installer (note that the EFI files needs to be placed if not yet set for example Win7) starting Win8 and higher EFI is already default set so you can copy it directly to the primary partition.

No comments: