Resolved: How to Dual boot with UEFI Windows?

Help with issues regarding installation of Debian

Resolved: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:02

Hi,

I have a shiny new Thinkpad T470p that came with windows. I'd like to keep the windows partition for now, as I need to use the mobile broadband modem and that is the one thing that may not work with Linux (we'll see...).

I installed Debian 9, to /dev/sda2 by making use of VirtualBox. I set up a RAW disk in Windows that points to /dev/sda, then created a VM on that, installing to /dev/sda2.

When Grub installation came up, I followed its default option, which was to install to the MBR on /dev/sda. I think. I'm not totally sure about that though.

I disable Secure Boot, and enabled Legacy and UEFI boot in the BIOS.

When I boot the raw disk under Virtual Box, I get grub and can only choose Debian from it, there is no Windows entry.
When I boot the bare metal laptop, it boots into Windows, and Grub gets completely bypassed.
If I disable UEFI boot and only allow legacy, it will not boot at all.

Is it possible to boot Debian and UEFI Windows side-by-side? I want to make sure I am not going to render the Windows partition un-bootable by running 'grub-install /dev/sda'.
Last edited by rupertlssmith on 2017-10-14 12:55, edited 1 time in total.
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby None1975 » 2017-10-13 14:05

Did you read Debian Wiki?
OS: Debian 9.2 / WM: Stumpwm
Debian Wiki | DontBreakDebian, Stumpwm
User avatar
None1975
 
Posts: 226
Joined: 2015-11-29 18:23
Location: Lithuania

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:13

None1975 wrote:Did you read Debian Wiki?


Thanks. That says "Windows 10 was installed first on a non-formated disk using a non-UEFI BIOS."

But my Windoze was installed using UEFI.

This one suggests reformatting the into GPT:

https://wiki.debian.org/WindowsDualBoot

Great plan if Lenovo actually provided me with the windows installation disks...
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:19

Code: Select all
# hdparm -i /dev/sda

/dev/sda:

 Model=VBOX HARDDISK, FwRev=1.0, SerialNo=VB13f90867-fe7a0da4
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=512, ECCbytes=0
 BuffType=DualPortCache, BuffSize=256kB, MaxMultSect=128, MultSect=128
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=2000409264
 IORDY=yes, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio3 pio4
 DMA modes:  mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
 AdvancedPM=no WriteCache=enabled
 Drive conforms to: unknown:  ATA/ATAPI-1,2,3,4,5,6

 * signifies the current active mode


So the raw /dev/sda that Debian sees might be some fabrication that Windows is presenting it with. Which would explain why Grub has not installed to the MBR of the physical disk.

I think I will try booting into a USB drive, backing up the MBR and windows partitions, then running grub-install from there on the actual physical /dev/sda.
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:23

Code: Select all
# grub-install /dev/sda
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
grub-install: error: will not proceed with blocklists.


Also, looks like I might already have GPT. I just need to create a "BIOS Boot Partition" in it?
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:30

Code: Select all
# fdisk -l /dev/sda
Disk /dev/sda: 953.9 GiB, 1024209543168 bytes, 2000409264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 90ED82E2-736D-40F4-B48F-C347B69203B3

Device          Start        End    Sectors   Size Type
/dev/sda1        2048     534527     532480   260M EFI System
/dev/sda2      534528     567295      32768    16M Microsoft reserved
/dev/sda3      567296  319000575  318433280 151.9G Microsoft basic data
/dev/sda4  1998360576 2000408575    2048000  1000M Windows recovery environment
/dev/sda5   319000576  319999999     999424   488M Linux filesystem
/dev/sda6   320000000 1998360575 1678360576 800.3G Linux LVM

Partition table entries are not in disk order.


So I definitely already have GPT.

There are also some helpful answers here that might lead me to enlightenment:

https://superuser.com/questions/903112/ ... -partition
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 14:42

So, I already have a bootable, esp partition:

Code: Select all
/dev/sda1        2048     534527     532480   260M EFI System


Perhaps I just have to install Grub in UEFI mode to /dev/sda1?
Presumably that will overwrite the Windows booter that is there? But UEFI mode Grub should manage to boot that?
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby p.H » 2017-10-13 19:02

rupertlssmith wrote:I installed Debian 9, to /dev/sda2 by making use of VirtualBox. I set up a RAW disk in Windows that points to /dev/sda, then created a VM on that, installing to /dev/sda2.

I cannot believe that VirtualBox is insane enough to allow a guest to use the raw physical disk where the host operating system is installed. Do you realize how insane and dangerous it is ? The guest system could write anything anywhere on the host partitions while the host operating system is running !

If you wanted to install and boot Debian directly on the hardware, why did you use VirtualBox ?

rupertlssmith wrote:So the raw /dev/sda that Debian sees might be some fabrication that Windows is presenting it with.

I hoped so, but it does not seem so.

rupertlssmith wrote:If I disable UEFI boot and only allow legacy, it will not boot at all.

Some BIOS/UEFI firmwares require that a partition in the MBR partition table has the boot flag set to allow booting the disk in BIOS/legacy mode. The flag can be set with fdisk by forcing the use of the DOS partition table with the "-t dos" option.

HOWEVER : UEFI firmwares may require that no partition has the boot flag set to boot in EFI mode, because it is against the UEFI/GPT specification. So be aware that setting this flag may prevent booting Windows.

rupertlssmith wrote:Perhaps I just have to install Grub in UEFI mode to /dev/sda1?

Yes, but if you do this in VirtualBox, GRUB won't be able to register itself in the host EFI boot entries.
GRUB for PC 64 bit UEFI is installed by grub-efi-amd64.
There are two ways to boot Debian in EFI mode on the physical hardware.

1) Boot the Debian installer (or another EFI compatible live system) in EFI mode and select "rescue" in the installer main menu. Follow the steps and run a shell on the installed system root logical volume. You'll also have to mount /boot and the EFI partition on /boot/efi, but the installer should propose to do it.

2) If the UEFI firmware is sophisticated enough, it may allow you to select which EFI boot file to boot from. Select /EFI/debian/grubx64.efi on the EFI partition.

Once booted in EFI mode, you can run grub-install (without any argument) again.

rupertlssmith wrote:Presumably that will overwrite the Windows booter that is there?

No. One of the few advantages of UEFI is that the installed systems do not overwrites each other's bootloaders. At worst they just change the boot order so that their own bootloader get higher priority. But that may be changed in the UEFI setup.
rupertlssmith wrote:But UEFI mode Grub should manage to boot that?

Yes, but you'll have to run update-grub again to add a menu entry for the EFI Windows boot loader.
p.H
 
Posts: 178
Joined: 2017-09-17 07:12

Re: How to Dual boot with UEFI Windows?

Postby pendrachken » 2017-10-13 19:11

rupertlssmith wrote:[code]# hdparm -i /dev/sda ......



So the raw /dev/sda that Debian sees might be some fabrication that Windows is presenting it with. Which would explain why Grub has not installed to the MBR of the physical disk.

I think I will try booting into a USB drive, backing up the MBR and windows partitions, then running grub-install from there on the actual physical /dev/sda.




Uhh, no? You are booted into virtualbox, sda is the partition / file you made for vbox. As far as I know you cannot install grub on the physical primary disk ( or any other physical disks outside of the partition / disk the VM is using ) when booted into a virtual machine without first escaping the VM through an exploit and running code on the host / hypervisor machine.



One option that MAY work is using the Windows bootloader to chainload grub from the partition you installed to in vbox ( if you actually used a physical partition and not a file ). Kind of the exact opposite of what normally happens - where grub chainloads the windows bootloader.
fortune -o
Your love life will be... interesting.
:twisted: How did it know?

The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches :-P
pendrachken
 
Posts: 1291
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 19:12

Ok, I'm starting to get my head round this.

The Debian installer would have taken care of EFI for me. I should have installed from a bootable USB and not tried to bootstrap via VirtualBox. It would seem that Windows is preventing VirtualBox from modifying the EFI while it is running, or at least the VBox machine crashes when I try to installer grub on it.

This blog here describes a procedure for setting up the Debian installed in an EFI boot:

https://www.logilab.org/blogentry/6546148
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 19:14

p.H wrote:If you wanted to install and boot Debian directly on the hardware, why did you use VirtualBox ?


Didn't have a USB device to hand! Its an old trick that has worked for me before, but you are right, so I'm making a bootable USB just now.
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 19:17

p.H wrote:Some BIOS/UEFI firmwares require that a partition in the MBR partition table has the boot flag set to allow booting the disk in BIOS/legacy mode. The flag can be set with fdisk by forcing the use of the DOS partition table with the "-t dos" option.

HOWEVER : UEFI firmwares may require that no partition has the boot flag set to boot in EFI mode, because it is against the UEFI/GPT specification. So be aware that setting this flag may prevent booting Windows.


Good to know. The current EFI boot partition has "boot, esp" flags set. I'l stick with that since it already seems to work.

Thanks for all your other explanations, it confirms what I have been learning this afternoon.
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby p.H » 2017-10-13 20:00

rupertlssmith wrote:The current EFI boot partition has "boot, esp" flags set.

I was not talking about the partitions in the GPT partition table. These "flags" are not really flags but the (stupid IMO) way used by parted and gparted to define and indicate partition types. With GPT, "boot" and "esp" are synonyms for the EFI system partition type.

I was talking about the legacy boot flag of the legacy DOS partition table in the MBR, which contains one single GPT protection partition (type ee). When set parted displays it as "pmbr_boot".

rupertlssmith wrote:It would seem that Windows is preventing VirtualBox from modifying the EFI

Not at all. VirtualBox emulates a virtual PC with its own BIOS/UEFI firmware which has nothing to do with the host UEFI firmware. It has no single reason to mess with the host UEFI settings.
p.H
 
Posts: 178
Joined: 2017-09-17 07:12

Re: How to Dual boot with UEFI Windows?

Postby rupertlssmith » 2017-10-13 20:27

rupertlssmith wrote:This blog here describes a procedure for setting up the Debian installed in an EFI boot:

https://www.logilab.org/blogentry/6546148


I followed the above but substituted stretch installer for the jessie one. It almost worked but hangs after the 'Loading InitRD' message. So at least I got some practice in how to install something to an EFI setup.

Can anyone recommend good set of instructions to follow to create a bootable EFI mode Debain Stretch installer on USB?
rupertlssmith
 
Posts: 101
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

Postby p.H » 2017-10-13 20:50

rupertlssmith wrote:I followed the above but substituted stretch installer for the jessie one. It almost worked but hangs after the 'Loading InitRD' message.

Sorry but I won't read that blog. What "almost worked but hangs" ?

rupertlssmith wrote:Can anyone recommend good set of instructions to follow to create a bootable EFI mode Debain Stretch installer on USB?

As mentionned in the Debian installation guide :
Code: Select all
cp debian-xxx.iso /dev/sdX

sdX being the USB drive with all partitions removed first, then unplugged and plugged again.
p.H
 
Posts: 178
Joined: 2017-09-17 07:12

Next

Return to Installation

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable