Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Resolved: How to Dual boot with UEFI Windows?

Ask for help with issues regarding the Installations of the Debian O/S.
Message
Author
rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Resolved: How to Dual boot with UEFI Windows?

#1 Post by rupertlssmith »

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.

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1389
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 66 times

Re: How to Dual boot with UEFI Windows?

#2 Post by None1975 »

Did you read Debian Wiki?
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#3 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#4 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#5 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#6 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#7 Post by rupertlssmith »

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?

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: How to Dual boot with UEFI Windows?

#8 Post by p.H »

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.

pendrachken
Posts: 1394
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: How to Dual boot with UEFI Windows?

#9 Post by pendrachken »

[quote="rupertlssmith"]

Code: Select all

# hdparm -i /dev/sda ......



[b][i]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][/b]

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.[/quote]



Uhh, no? You are booted into virtualbox, sda is the partition / file you made for vbox. As far as I know you [b] cannot [/b] 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

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#10 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#11 Post by rupertlssmith »

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: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#12 Post by rupertlssmith »

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.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: How to Dual boot with UEFI Windows?

#13 Post by p.H »

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.

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#14 Post by rupertlssmith »

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?

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: How to Dual boot with UEFI Windows?

#15 Post by p.H »

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.

User avatar
alan stone
Posts: 269
Joined: 2011-10-22 14:08
Location: In my body.

Re: How to Dual boot with UEFI Windows?

#16 Post by alan stone »

rupertlssmith wrote:Great plan if Lenovo actually provided me with the windows installation disks...
Create installation media for Windows

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#17 Post by rupertlssmith »

p.H wrote: 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.
So I did the above:

Code: Select all

cp debian-9.2.0-amd64-netinst.iso /dev/sdc
This gave me a bootable installer - however I then run into the perennial "cannot find the CD-ROM" problem.

netinst.iso is looking for a CD-ROM device, but fails to find one. I tried opening a shell and "mount /dev/sda1 /cdrom" but that says it cannot find the /cdrom directory despite the file system showing it is there..?

I am using a USB HDD device rather than a USB memory stick. I wonder if that affects things? AFAIK, the netinst installer is supposed to be dual purpose in that it can work from a CD-ROM or a USB device.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: How to Dual boot with UEFI Windows?

#18 Post by p.H »

The error message may be misleading. IIRC the mount command from busybox included in the Debian installer requires to specify the filesystem type (iso9660) with -t.
rupertlssmith wrote:I am using a USB HDD device rather than a USB memory stick. I wonder if that affects things?
It should not. Check which /dev/sdX device name the USB drive gets.

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#19 Post by rupertlssmith »

p.H wrote:The error message may be misleading. IIRC the mount command from busybox included in the Debian installer requires to specify the filesystem type (iso9660) with -t.
rupertlssmith wrote:I am using a USB HDD device rather than a USB memory stick. I wonder if that affects things?
It should not. Check which /dev/sdX device name the USB drive gets.
Thanks. That works:

Code: Select all

mount -t iso9660 /dev/sda /cdrom
There were 2 partitions on the file system /dev/sda1 and /dev/sda2. However it seems to be the root device /dev/sda that needs to be mounted. After that the installer finds its components.

rupertlssmith
Posts: 109
Joined: 2009-08-11 10:41

Re: How to Dual boot with UEFI Windows?

#20 Post by rupertlssmith »

So now I get the installer running.

When I come to the step 'Install Base System' it fails with the message 'Failed to determine the codename for the release.' Any suggestions?

I think I now understand why Linus Torvalds says he is not technical enough to install Debian...

Post Reply