grub finding wrong HD ?

Help with issues regarding installation of Debian

grub finding wrong HD ?

Postby dieselnutjob » 2019-12-28 19:13

Hi
I have an old Macbook pro (so EFI boot) which I dual boot.
More specifically it has two SSD drives in it.
The normal drive bay contains an SSD with Mac OSX installed on it, and nothing more, and the normal OSX boot loader.
I replaced the broken DVD with a an adapter that allows me to put a second SSD where the DVD used to be.
To install OSX I would unscrew the backplate and disconnect the drive cable to the DVD bay, so now Debian is safe from the OSX installer.
To install Debian I disconnect the normal drive and so OSX is safe from the Debian installer. I do this because this is a development machine and so I am always messing about with one OS or another.

I suppose that this means that there are two different efi partitions on two separate drives.

To select which OS to boot I press the power button and when the Macbook chimes I press the "option" key and the Macbook boot menu appears with a choice of the two drives.
If I select the left one Mac OSX boots.
If I select the right one grub on the Debian drive boots.
Initially I just get the grub command prompt (not the grub-rescue prompt).
If at that point I type "reboot" then the macbook reboots and if I don't press the option key then this time I will get the grub menu and can boot Debian from the menu.

The next thing I noticed is that after pressing the option key and selecting the Debian drive, from the grub prompt if I type "ls" then I can find my Debian ext partition, it comes up as (hd5,gpt2)
I also notice that after doing the reboot thing that once the menu comes up if I press "e" for edit that seems to be trying (hd1,gpt2).

So then I had a look at /boot/grub/grub.cfg
Code: Select all
insmod ext2
set root='hd1,gpt2'


is this the reason why grub is not bringing up the boot menu after pressing the "option" key? or is it a red herring?

also I cannot figure out how hd1 gets there, or how to change it to hd5

I had a look at all of the files in /etc/grub.d but it's just too complicated for me to figure out.

Can anyone tell me what's going on and how I can change my set root from hd1 to hd5 ?

All of the files in /etc/grub.d are default except that they are some extra lines under linux_gfx_mode in 10_linux to disable the GPU.
The debian drive was created from a clean install of Buster.

thanks, DNJ
dieselnutjob
 
Posts: 89
Joined: 2011-04-12 10:25

Re: grub finding wrong HD ?

Postby p.H » 2019-12-29 09:05

What happens if you simply power on the computer and let it boot ?

dieselnutjob wrote:The next thing I noticed is that after pressing the option key and selecting the Debian drive, from the grub prompt if I type "ls" then I can find my Debian ext partition, it comes up as (hd5,gpt2)
I also notice that after doing the reboot thing that once the menu comes up if I press "e" for edit that seems to be trying (hd1,gpt2).

What does "ls" report if you press "c" at the GRUB menu ?
What values does "set" report for $cmdline, $prefix and $root when booting GRUB each way ? (could be two different GRUB instances)

The drive numbers in GRUB are assigned by the computer firmware and may vary at each boot, depending on which drives are present and which drive was booted. When building grub.cfg, update-grub can only guess how /dev/sd* or /dev/nvme* drives translate into (hd*). You can define a translation map with /boot/grub/device.map. Anyway it does not matter much because normally GRUB uses UUIDs to search partitions. Check in grub.cfg.
p.H
 
Posts: 1260
Joined: 2017-09-17 07:12

Re: grub finding wrong HD ?

Postby dieselnutjob » 2019-12-29 23:16

Thank you for replying.

If I power on the computer and don't intervene then it boots the OS that booted last time.
So if last time I booted Mac OSX, then Mac OSX boots from the OSX SSD drive, grub is not involved.
If last time I booted Linux, then grub loads and the menu appears and if I do nothing then Linux boots.

The trouble comes if the last OS that I used was Mac OSX but I want to boot Linux.

In that case to override the default behaviour I press the option key and select the Linux SSD drive.
Now grub will load but I get grub prompt and no menu.
If at this point I type "reboot", then the computer reboots and because last time grub booted then this time grub will be the default, I don't need to press the option key, and now the menu loads and Linux starts.

So basically grub being invoked by default (because it was the last OS booted) works, but grub invoked by pressing the option key causes it to not load the menu.

When it is successful if I press C and then set I get these results:-
Code: Select all
cmdpath=(hd5,gpt1)/EFI/debian
prefix=(hd5,gpt2)/boot/grub
root=hd5,gpt2


When it is not successful (after pressing the option key) then I can see less because the text is in a small box in the middle of the screen and the top of the output of "set" scrolls away before I can read it.
I get these results:-
Code: Select all
prefix=(hd5,gpt1)/boot/grub
root=hd5,gpt1


I also noticed that the successful one has "have_grubenv=true" but the unsuccessful one seems to have this missing (unless it scrolled off the top)
I can also see that the unsuccessful one has gpt1 whereas the successful one has gpt2

As I have two drives each with it's own EFI partition is it possible that Debian "stuff" has somehow gotten into the EFI partition on the Mac OSX drive? Sorry I don't really understand EFI

Is there a way to run "set" from the grub command line and have a subcommand so that I can see the cmdpath before it scrolls away?
dieselnutjob
 
Posts: 89
Joined: 2011-04-12 10:25

Re: grub finding wrong HD ?

Postby p.H » 2019-12-30 07:38

It seems that these are two distinct instances of GRUB. The one which does not display a menu could be the remain of an older installation. cmdpath should contain its location.

If the output of a command does not fit in the screen, you can type the following command before to stop the output after each page (similar to "more") :
Code: Select all
set pager=1


Also, could you post the output of
Code: Select all
fdisk -l
p.H
 
Posts: 1260
Joined: 2017-09-17 07:12

Re: grub finding wrong HD ?

Postby dieselnutjob » 2019-12-30 12:53

thank you

grub loading but only command prompt:-
Code: Select all
cmdpath=(hd5,gpt1)/EFI/ubuntu
prefix=(hd5,gpt1)/boot/grub
root=hd5,gpt1
package_version=2.02+dfsg1-5ubuntu8.3


grub loading with menu and booting Linux
Code: Select all
cmdpath=(hd5,gpt1)/EFI/debian
prefix=(hd5,gpt2)/boot/grub
root=hd5,gpt2


once Debian has booted:-
Code: Select all
root@macbookpro83:/home/philip# fdisk -l
Disk /dev/sda: 111.8 GiB, 120040980480 bytes, 234455040 sectors
Disk model: SanDisk SSD PLUS
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: 1E13FCB3-387E-432D-8761-23CFFC91B50C

Device      Start       End   Sectors   Size Type
/dev/sda1      40    409639    409600   200M EFI System
/dev/sda2  409640 234454999 234045360 111.6G unknown


Disk /dev/sdb: 223.6 GiB, 240057409536 bytes, 468862128 sectors
Disk model: KINGSTON SA400S3
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: 566044E4-EAFA-45B6-850F-8788CB1CA4E4

Device         Start       End   Sectors   Size Type
/dev/sdb1       2048   1050623   1048576   512M EFI System
/dev/sdb2    1050624 452263935 451213312 215.2G Linux filesystem
/dev/sdb3  452263936 468860927  16596992   7.9G Linux swap
root@macbookpro83:/home/philip# dpkg -l |grep grub
ii  grub-common                           2.02+dfsg1-20                       amd64        GRand Unified Bootloader (common files)
ii  grub-efi-amd64                        2.02+dfsg1-20                       amd64        GRand Unified Bootloader, version 2 (EFI-AMD64 version)
ii  grub-efi-amd64-bin                    2.02+dfsg1-20                       amd64        GRand Unified Bootloader, version 2 (EFI-AMD64 modules)
ii  grub-efi-amd64-signed                 1+2.02+dfsg1+20                     amd64        GRand Unified Bootloader, version 2 (amd64 UEFI signed by Debian)
ii  grub2-common                          2.02+dfsg1-20                       amd64        GRand Unified Bootloader (common files for version 2)

/dev/sdb1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)

root@macbookpro83:/home/philip# cd /boot/efi
root@macbookpro83:/boot/efi# ls -al
total 12
drwx------ 3 root root 4096 Jan  1  1970 .
drwxr-xr-x 4 root root 4096 Dec 14 23:50 ..
drwx------ 6 root root 4096 Sep 13 23:39 EFI
root@macbookpro83:/boot/efi# cd EFI
root@macbookpro83:/boot/efi/EFI# ls
APPLE  BOOT  debian  ubuntu
root@macbookpro83:/boot/efi/EFI# ls ubuntu/
BOOTX64.CSV  grub.cfg  grubx64.efi  mmx64.efi  shimx64.efi
root@macbookpro83:/boot/efi/EFI# ls debian/
BOOTX64.CSV  fbx64.efi  grub.cfg  grubx64.efi  mmx64.efi  shimx64.efi


It looks like you correct and there is still ubuntu "stuff" in the EFI partition. I thought that I had done a clean install but it seems that I didn't clean it as well as I remember.

Should I just delect the /boot/efi/EFI/ubuntu folder?

also:-
Code: Select all
root@macbookpro83:/# mount /dev/sda1 /mnt
root@macbookpro83:/# cd mnt
root@macbookpro83:/mnt# ls
EFI
root@macbookpro83:/mnt# cd EFI
root@macbookpro83:/mnt/EFI# ls
APPLE


why does my /dev/sdb1 partition have an APPLE folder in it? how did it get there? an OSX upgrade? does it matter?

thanks
dieselnutjob
 
Posts: 89
Joined: 2011-04-12 10:25

Re: grub finding wrong HD ?

Postby dieselnutjob » 2019-12-30 21:58

Fixed

Code: Select all
mv /boot/efi/EFI/ubuntu /root/ubuntu
reboot


thanks
dieselnutjob
 
Posts: 89
Joined: 2011-04-12 10:25

Re: grub finding wrong HD ?

Postby p.H » 2019-12-31 09:41

dieselnutjob wrote:Should I just delect the /boot/efi/EFI/ubuntu folder?

IMO it would be cleaner to delete the EFI boot entry for Ubuntu with efibootmgr first.
What is the output of "efibootmgr" ?
p.H
 
Posts: 1260
Joined: 2017-09-17 07:12

Re: grub finding wrong HD ?

Postby dieselnutjob » 2019-12-31 13:26

Code: Select all
philip@macbookpro83:~$ sudo efibootmgr
[sudo] password for philip:
Timeout: 5 seconds
No BootOrder is set; firmware will attempt recovery
Boot0000* debian
Boot0001* ubuntu
Boot0002* ubuntu
Boot0081* Mac OS X
Boot0082*
dieselnutjob
 
Posts: 89
Joined: 2011-04-12 10:25

Re: grub finding wrong HD ?

Postby p.H » 2019-12-31 13:43

If Ubuntu is not present any more, you can delete the two "ubuntu" boot entries with
Code: Select all
efibootmgr -b 0001 -B
efibootmgr -b 0002 -B

Weird that no boot order is defined. Must be specific to the Mac.
p.H
 
Posts: 1260
Joined: 2017-09-17 07:12


Return to Installation

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable