Grub2 EFI with Windows 7 dual boot

If none of the more specific forums is the right place to ask
Post Reply
Message
Author
Alexqw
Posts: 3
Joined: 2011-03-23 18:31

Grub2 EFI with Windows 7 dual boot

#1 Post by Alexqw »

I was hoping for a little help with this one, as I am pretty new to EFI.

I have a laptop with Windows 7 on it which I intend to add Wheezy to for dual-booting. The BIOS is set to use EFI, and Windows 7 was installed using EFI.

When I installed Debian, I chose "Guided, using largest freely available space." The installed got confused about the EFI (no EFI boot partition). The partition is already there, from Windows, so I re-assigned the EFI partition as an EFI boot partition, and the installer merrily went on its way.

Installation success, except I can't seem to boot into Debian. I've used the Debian Live dvd to poke around. The Debian partition is there and in post-install condition. /etc/fstab for the Debian partition correctly lists sda1 for /boot/efi/. The EFI partition itself does contain the Debian folder and its *.efi file (and the Boot and microsoft folders). I chrooted into the Debian partition, and found that grub-efi was installed properly. I ran grub-install /dev/sda and update-grub. Upon reboot, I still went straight into Windows. :-/

In a last-ditch effort, I (after making a backup of the EFI partition) copied Debian's .efi image over the Boot/bootx64.efi file, assuming that the Boot/bootx64.efi was executed by default. This, apparently, is not the case, as I still ended up in Windows. Argh!

Does anyone have any suggestions about where I should go from here?

---Alex

User avatar
kiyop
Posts: 3984
Joined: 2011-05-05 15:16
Location: Where persons without desire to improve themselves fear to tread, in Japan

Re: Grub2 EFI with Windows 7 dual boot

#2 Post by kiyop »

I am not familiar with EFI. So, I may be wrong.

Grub4dos may solve your problem. Place grldr and/or grldr.mbr on Windows system partition directly and configure /menu.lst so that it can correctly boot the installed debian.
Copying the kernel (vmlinuz-2.6.32-...) and the initramfs file (initrd.img-2.6.32-...) onto the windows system partition may help also.

Boot repair may upload the problematic situation on the boot of your debian. Read https://help.ubuntu.com/community/Boot-Repair and report the URL where the information on your PC is uploaded.

ADDED AT Mon Mar 25 19:47:50 JST 2013;

Thanks smutbert.
Last edited by kiyop on 2013-03-25 10:49, edited 1 time in total.
Openbox, JWM: Jessie, Sid, Arch / Win XP (on VirtualBox), 10
http://kiyoandkei.bbs.fc2.com/

User avatar
smutbert
Posts: 68
Joined: 2011-07-24 10:00
Location: Austria

Re: Grub2 EFI with Windows 7 dual boot

#3 Post by smutbert »

You might experience a chicken and egg problem. The grub.efi or bootx64.efi needs to be setup as boot entry in the EFI boot manager. Usually this is done with efibootmgr, but efibootmgr only works if the kernel module efivars is loaded, which is only possible if the computer is booted in EFI mode :(
Alexqw wrote:I[…] copied Debian's .efi image over the Boot/bootx64.efi file, assuming that the Boot/bootx64.efi was executed by default. This, apparently, is not the case, as I still ended up in Windows. Argh![…]
That's what I would have tried too. It works on Macs, but for me it didn't work an a different computer either.

Does the BIOS/Firmware provide a boot menu to boot from bootx64.efi (eg when pressing <ESC> at boot)?
Or can you perhaps create a EFI boot entry using the EFI/BIOS Setup (though it might be difficult to figure out the correct device/path string)?


One last option would be to rename the Windows 7 EFI boot file
(EFI system or windows partition?)/EFI/Microsoft/Boot/BCD
and replace it with a copy of grub.efi, but you might end up without the possibility to boot either Linux or Windows. If this worked you could restore the Windows 7 bcd and reinstall grub, which should also run efibootmgr and setup the correct EFI boot entry.

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#4 Post by Soapm »

Here's your problem, Grub and EFI are two different boot loaders. When your BIOS is in EFI it will boot the EFI loader which will take you into 7. When in legacy it should see Grub except you moved the boot partition so I don't know what happens in your case.

Unfortunately Linux didn't modify the EFI boot loader because it added Grub thinking that would suffice. It would in legacy mode but it doesn't come into play in EFI mode.

Here is a site that will give you a little insight.

https://wiki.archlinux.org/index.php/UEFI_Bootloaders

Now, windows 7 won't work in legacy mode with your drive formated as it is because your manufacturer probably put restore and other partitions on the drive. MBR doesn't acknowledge more then 4 primary partitions so Win7 will choke in legacy mode.

User avatar
smutbert
Posts: 68
Joined: 2011-07-24 10:00
Location: Austria

Re: Grub2 EFI with Windows 7 dual boot

#5 Post by smutbert »

grub supports more than just the traditional PC/BIOS way of booting and Alexqw stated that he installed the EFI version grub-efi, which is also listed in the link you provided.

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#6 Post by Soapm »

smutbert wrote:grub supports more than just the traditional PC/BIOS way of booting and Alexqw stated that he installed the EFI version grub-efi, which is also listed in the link you provided.
Now you're teaching me, I will install grub-efi and see where that gets me.

I have to admit that link is over my head but I was thinking a script or howto would be forthcoming once enough of the techy types move to this new partition set while wanting to dual boot with windows.

Thanks

Edited to say...

Wow, look at all that was removed when I installed grub-efi-amd64
The following packages will be REMOVED:
bridge-utils{u} cryptsetup{u} fatresize{u} grub-pc{a} gtkdialog{u} ipxe-qemu{u} libaio1{u}
libcrypt-passwdmd5-perl{u} libfdt1{u} libiscsi1{u} libspice-server1{u} libusbredirparser0{u}
libvde0{u} libvdeplug2{u} libxdo2{u} libxen-4.1{u} libxenstore3.0{u} multisystem{a} openbios-ppc{u}
openbios-sparc{u} openhackware{u} qemu{u} qemu-keymaps{u} qemu-kvm{u} qemu-system{u} qemu-user{u}
qemu-utils{u} seabios{u} squashfs-tools{u} syslinux{u} syslinux-common{u} vde2{u} vgabios{u}
wmctrl{u} xdotool{u}
This also looks promising, I'll reboot and see what happens...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-3.2.0-4-amd64
Found initrd image: /boot/initrd.img-3.2.0-4-amd64
Found memtest86 image: /boot/memtest86.bin
Found Windows Recovery Environment (loader) on /dev/sda2
Found Windows 8 (loader) on /dev/sda3

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#7 Post by Soapm »

No difference...

When BIOS is in EFI mode I boot strait into Windows 8 with no option menu ever appearing...

With BIOS in legacy I boot to grub and if I chose Windows 8 from that menu it fails.

I am back in Debian now from the Grub menu so that part still works.

The trick has got to be modifying that EFI boot loader to that it recognizes either grub or the debian install. If that loader would give me an option I think this will be all set.

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#8 Post by Soapm »

i got a theory, check me out and see if I'm close...

Code: Select all

Number  Start   End     Size    File system     Name                          Flags
 1      1049kB  274MB   273MB   fat32           EFI system partition          hidden
 2      274MB   1819MB  1546MB  ntfs            Basic data partition          hidden, diag
 3      1819MB  2092MB  273MB   fat32           EFI system partition          boot
 4      2092MB  2226MB  134MB                   Microsoft reserved partition  msftres
 5      2226MB  160GB   157GB   ntfs            Basic data partition
 6      160GB   212GB   52.4GB  ntfs            Basic data partition          hidden, diag
 7      212GB   292GB   80.0GB  ext3            Root                          boot
 8      292GB   392GB   100GB   ext4            Home
 9      392GB   432GB   40.0GB  linux-swap(v1)  Swap
This is my partition table. I believe linus is booting from my root partition 7 vs Windows 8 in EFI mode is booting from partition 3. I wonder if during my debian install if I had of not marked Root as boot and instead chosen parititon 3 as the boot would grub had of worked within that partition and everything would now be happy.

The short version of my theory is...

BIOS in EFI mode = boot partition 3
BIOS in Legacy mode = boot partition 7.

User avatar
smutbert
Posts: 68
Joined: 2011-07-24 10:00
Location: Austria

AW: Grub2 EFI with Windows 7 dual boot

#9 Post by smutbert »

Soapm wrote:No difference...
...
That is to be expected. Installing the grub-efi-... package alone luckily will not yet replace the files belonging to grub-pc in /boot.

For this to happen you'd also have to mount the efi system partition in /boot/efi and then run grub-install, which creates the grub.efi image in the efi system partition and update-grub to create/Update the grub configuration file.
But be warned you might end up facing the same problem as the op (#3)

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#10 Post by Soapm »

In case anyone is interested this works http://www.rodsbooks.com/efi-bootloader ... ation.html

It's the same as what smutbert just posted except this one command

Code: Select all

# efibootmgr -c -d /dev/sda -p 1 -l \\EFI\\newloader\\loadername.efi -L NewLoader

User avatar
smutbert
Posts: 68
Joined: 2011-07-24 10:00
Location: Austria

Re: Grub2 EFI with Windows 7 dual boot

#11 Post by smutbert »

How did you boot linux in EFI mode in the first place? (Otherwise you couldn't have run efibootmgr?)

Once you have booted in EFI mode, it's quite easy. If you mount the ESP in /boot/efi grub-install does everything that's necessary:
- copy the boot loader files to /boot/grub/
- generate the grub EFI image: boot.efi and grubia32.efi or grubx64.efi in /boot/efi/EFI/DEBIAN/
- run efibootmgr to tell the EFI about grub :wink:

User avatar
Soapm
Posts: 582
Joined: 2012-05-22 04:23

Re: Grub2 EFI with Windows 7 dual boot

#12 Post by Soapm »

smutbert wrote:How did you boot linux in EFI mode in the first place? (Otherwise you couldn't have run efibootmgr?)

Once you have booted in EFI mode, it's quite easy. If you mount the ESP in /boot/efi grub-install does everything that's necessary:
- copy the boot loader files to /boot/grub/
- generate the grub EFI image: boot.efi and grubia32.efi or grubx64.efi in /boot/efi/EFI/DEBIAN/
- run efibootmgr to tell the EFI about grub :wink:
I use the super grub disk to get it going. When I enable EFI I just stop it during boot then tell it to boot from CD. But you're right, I don't think I was in that mode when I ran the command.

Post Reply