Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
EFI boot with GRUB2 on amd64, dual boot with Windows7 x64
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64
View previous topic :: View next topic  
Author Message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Sun Mar 18, 2012 8:08 am    Post subject: EFI boot with GRUB2 on amd64, dual boot with Windows7 x64 Reply with quote

Successfully set up UEFI booting yesterday on amd64 (MB: ASUS P8P67). It was/is sort of chicken and egg problem - to be able to setup it, one has to have the system already booted in UEFI mode; one can do so with the help of EFI boot capable usb flashdrive. Short summary is

step 1) GRUB2 compilation:

Setup efi-64 platform for grub, unmask grub2, emerge it

echo 'GRUB_PLATFORMS="efi-64"' >> /etc/make.conf
echo 'sys-boot/grub:2' >> /etc/portage/package.unmask
emerge grub


[note: grub2.00_beta2 works for me; _beta1 has a bug preventing it from booting later on]


step 2) Booting the computer in UEFI mode from flashdrive

Automated grub2-install on UEFI system (step 3) is quite adept and ready, but it relies on access to EFI variables, which basically means two things: 1) the kernel have to support them - the easy part - AND 2) the machine have to be already booted in UEFI mode - the not so straightforward part, "chicken and egg problem", that can be overcome with an EFI bootable flashdrive.

* EFI bootable USB flashdrive can be created with (assuming FAT formatted drive, mounted under /media/flashdrive)

grub2-install --target=x86_64-efi --root-directory=/media/flashdrive --removable --modules=part_gpt

* Kernel support: (re)compile kernel with CONFIG_EFI_VARS=y [menuconfig: [*] Firmware Drivers/EFI Variable Support via sysfs]. (copy kernel to /media/flashdrive/vmlinuz for convenience)
[note: support for EFI variables can be compiled as module, which is called 'efivars' BUT 'modprobe efivars' alone e.g. on a machine booted e.g. from MBR flashdrive does not make the efi vars available (or at least it did not on my asus P8P67 motherboard)].

* ls -l /dev/root to remind which partition is root -> /dev/sdaX

* Reboot machine from the flashdrive in UEFI mode - motherboard/notebook manual should contain instructions on how to do this.

* GRUB2 command line should appear - the system can be booted with something like
grub> linux /vmlinuz root=/dev/sdaX
grub> boot
[if there is no kernel on the flash, use "grub> set root=(hd1,gptX)" first to mount gptX partiton and linux /boot/vmlinuz root=/dev/sdaX ... see GRUB doc for more info]
[note: flashdrive is hd0, first disk is hd1; still, kernel booted for me with root=/dev/sdaX; also I encountered error: no video mode activated Booting in blind mode (and no messages during the boot were visible), but the system booted (to X) just fine)
[note (caveat): booting from 'classical' MBR bootable flashdrive 'laying somewhere around' will most probably not make EFI variables available, even when kernel with compiled in support is used; MBR booting - at least on my motherboard - thwarts the UEFI mode and prevent the kernel from accessing the UEFI variables]


step 3) GRUB2 installation

Look at /sys/firmware/efi/vars to see whether the EFI variables are accessible

When they are, mount EFI partition under /boot/efi - typically: mkdir /boot/efi; mount /dev/sda1 /boot/efi

and

grub2-install --target=x86_64-efi --root-directory=/boot/efi --boot-directory=/boot/efi/EFI --bootloader-id=GRUB2 --no-floppy

also, prepare grub.cfg with

grub2-mkconfig -o /boot/efi/EFI/GRUB2/grub.cfg


step 4) Selecting GRUB2 boot option

grub2-install from above should setup the option to boot GRUB2 in EFI. This does not necessarily mean that the system will boot to GRUB2 after restart. It is now possible/necessary to select that GRUB2 option "in BIOS" =in EFI vendor user interface (e.g. on an ASUS P8P67 MB press Del to enter setup ... and set it there)
[note: this can probably also be done from within linux with efibootmgr command]


step 5) Chainloading Windows7 x64

basically, add

menuentry 'Windows7' {
chainloader /efi/Microsoft/Boot/bootmgfw.efi
}

to the end of /boot/efi/EFI/GRUB2/grub.cfg (don't worry about the don't edit exclamation at the beginning of the file)


Sources
https://wiki.gentoo.org/wiki/GRUB2#UEFI_installation
https://wiki.archlinux.org/index.php/GRUB2#Chainload_Microsoft_Windows_x86_64_UEFI-GPT
man grub2-install
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Mon Mar 19, 2012 9:28 am    Post subject: Reply with quote

But I'm still booting 'blind', i.e. without any messages from kernel, and got no visible console. Would somebody know how to set up the framebuffer (on EFI machine)?

EDIT: one step further - CONFIG_FB_EFI, i.e.

Device Drivers/Graphics support/Support for framebuffer devices/EFI-based Framebuffer support

(+rebuild and install the kernel) makes console available; but the keyboard is not working.
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Sun Mar 25, 2012 7:49 pm    Post subject: Reply with quote

Hey, another masochist here....just built a new system based on the ASUS Rampage IV Extreme...and of course, Gentoo is going on it.

I knew I would need to go UEFI, but this stuff is bleeding edge (it's bled away my entire weekend). So far, I can launch the grub2 command line from the bios, but that's it! I've been trying to follow the ArchLinux docs on this.

So, you look like you are way ahead of me...so a few questions...1) where did you put your kernel images on the hdd and 2) Does your motherboard see your hdd? I'm using a SATA 6 GB port and my the UEFI can see it as a disk drive and I can get to the EFI system partition I created, but it refuses to list it as a boot device. There is no where in the BIOS I can find to tell it where to look for grub, so I don't know if this is something handled by efibootmgr or not...it must be.

Anyway, I'm on this pain train too now :-)
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Mon Mar 26, 2012 7:02 am    Post subject: Reply with quote

So you have GRUB2 already installed on your hard drive? How did you do it?

As is written above, BIOS (or, rather, what I would call EFI vendor interface) sees GRUB2 (i.e. it offers it as a choice to boot if you press F8 during boot (F8 works on my ASUS P8P67 motherboard, might be different for other boards)), but only after successful run of grub2-install on a system that is already booted in EFI mode (and to be able to boot it from hdd in efi mode, you need the option on the bios). To overcome this chicken-egg problem, I used (had to use) an EFI-bootable flashdrive [I put the kernel on it for convenience] (see above for the instructions on how to prepare it), than reboot the system, press F8, select [EFI:<flashdrive>] from the menu -- but first I would recommend you to have working system (able to boot to Xwindows) ready, since so far I've been unable to make keyboard work on console

Have you booted your system with usb flashdrive in EFI mode?

(just to be sure - you used GPT partition table?) What are the partitions you have on your hdd?

Mine are (parted; print)

Model: ATA WDC WD6400AAKS-0 (scsi)
Disk /dev/sda: 640GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 106MB 105MB fat32 EFI system partition boot
2 106MB 240MB 134MB Microsoft reserved partition msftres
3 240MB 368GB 367GB ntfs Basic data partition
4 368GB 556GB 188GB ntfs
5 556GB 566GB 10.5GB linux-swap(v1)
6 566GB 613GB 47.2GB ext3

kernel is on /dev/sda6 in /boot/ (together with gentoo)
/dev/sda5 is swap

note (possible snag): when booting with flashdrive, GRUB sees it (at least on my ASUS P8P67) as hdd0 (and the (first) internal hdd is hdd1) - without the flashdrive, the internal harddrive is hdd0
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Mon Mar 26, 2012 11:58 pm    Post subject: Reply with quote

Well, I did a grub2-install before I have an efivars system and copied that to the shell executable in the efi directory and that gave me access to the grub shell from the UEFI bios.

The directions from archlinux I was following were not quite working...so I managed for find the current gentoo wiki on UEFI and am using that. I've scratched what I was doing and am no starting from scratch. So yeah, a usb booted EFI kernel is really the only way to go. I'm working through that now.

And yes, I've been using GPT partitions, but I originally created them as MBR partitions and converted them with gdisk. I've since blown all that away and just created the partitions with GPT. I know a lot more now than I did when I started 2 days ago, that's for sure.

Anyway, I don't know if you've seen this or used it, but this is the guide I'm going by now:

http://wiki.gentoo.org/wiki/GRUB2#GPT

Seems better than what I was using before.

I'll post when I make some more progress...
Back to top
View user's profile Send private message
srs5694
Guru
Guru


Joined: 08 Mar 2004
Posts: 434
Location: Woonsocket, RI

PostPosted: Sat Apr 07, 2012 3:45 am    Post subject: Reply with quote

I realize this thread is a couple of weeks old, but you might want to look into rEFInd, which is my fork of the rEFIt EFI boot manager. When coupled with a 3.3.x kernel and its EFI stub loader, you can boot an EFI system without messing with GRUB. There is still the chicken-and-egg problem of telling the EFI about your boot loader from a BIOS boot, but you can generally use a default name or boot from a USB flash drive or optical disc, at least initially.

If you're not quite ready to jump to a 3.3.x kernel, IMHO either ELILO or GRUB Legacy is superior to GRUB 2 on EFI systems. (I've got a Web page that describes all the major boot loaders for Linux.)
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Thu Apr 12, 2012 5:30 pm    Post subject: Reply with quote

Found out recently that chainloading Windows7 prevents wakeup from hibernation (some "error 00x9" is displayed).
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Thu Apr 12, 2012 10:28 pm    Post subject: Reply with quote

I was able to get through this. Took me about a week of research...the most difficult part was figuring out how to find and boot an EFI live cd (or usb, as it turned out). After I finally got that, grub2 installed fine and I've been dual booting windows 7 and gentoo without any issues whatsoever. It's just very 'different' from the old grub and not at all well documented. Lot's of documentation out there, but it's often incomplete or out of date. Anyway, I made it.
Back to top
View user's profile Send private message
platojones
Veteran
Veteran


Joined: 23 Oct 2002
Posts: 1602
Location: Just over the horizon

PostPosted: Thu Apr 12, 2012 10:29 pm    Post subject: Reply with quote

renergy wrote:
Found out recently that chainloading Windows7 prevents wakeup from hibernation (some "error 00x9" is displayed).


Ahhh, I'm not sure on that one...I have a desktop and don't hibernate. I may give it a try though, just to see what happens.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum