3

For the rest of this question, you can assume anything with 'internal' refers to the internal eMMc drive of my laptop, anything with 'USB' refers to my bootable USB flash drive, 'Debian' means Debian Buster and 'Windows' means Windows 10.

I have Windows installed on the internal drive and Debian installed on a bootable USB flash drive. My boot settings are such that Grub Bootloader has priority over the default bootloader.

My problem is that whenever the bootable drive is not connected, Grub apparently doesn't find anything and starts up the command line interface. When it is connected, the graphical interface allows me to choose between Debian and Windows as standard.

I've looked around Stack Exchange for a similar enough answer for this, but believe me when I tell you that I'm not good enough to use what I have found to fix the problem. I quote:

Neither of these are relevant to my case as I can get both operating systems to run fine when the USB stick is connected and I can ESC before CLI Grub comes up and F9 to choose my boot device (Windows is the only one available).

I'm stuck. Ideally, I'd like it that when the USB stick isn't connected, that my computer automatically boots to Windows, or if that's not possible, allow me to choose my boot method without having to snipe ESC before CLI Grub starts.

Grub when the USB stick is connected: Grub when the USB stick is connected Grub when the USB stick is not connected: Grub when the USB stick is not connected My boot options when I use ESC and F9: Boot options "debian" just brings up the Grub CLI again.

2
  • What sort of laptop is this?
    – Time4Tea
    Aug 8 '20 at 16:48
  • I have a HP Stream 11-r050sa
    – Ban2u
    Aug 8 '20 at 19:16
2

You seem to have an UEFI-based system. Both GRUB and the Windows bootloader are installed in the EFI System Partition (ESP for short), which is your partition (hd1,1) as GRUB sees it.

Debian 10's default UEFI GRUB includes essentially all the GRUB modules in the main grubx64.efi executable, so a lack of filesystem drivers should not be the issue here. Your internal eMMC has standard Windows partitioning:

  • (hd1,1) is ESP, with a FAT32 filesystem, sized about 260M (the minimum supported size for FAT32 on disks with 4k block size)
  • (hd1,2) is the "Microsoft Reserved" partition, which is not formatted at all and is about 128M in size. It exists to allow easy conversion to Windows Dynamic Disk (sort of an equivalent of Linux LVM for Windows) or other conversions.
  • (hd1,3) is your main Windows system drive, with a NTFS filesystem.
  • (hd1,4) is another partition with a NTFS filesystem, possibly the Windows recovery partition.

All your Linux partitions are located on the external flash drive. And there's the problem: by default, Debian 10 installs only a very minimal GRUB configuration file into the ESP. Essentially it only identifies the filesystem that contains the Linux /boot directory by UUID, and tells GRUB to load its real configuration from there. Obviously that cannot happen when the external flash drive is disconnected. And the real configuration file contains all the boot menu definitions, including the one for Windows. Without them, GRUB can only show the command prompt.

You can fix this by booting into Linux and copying the real GRUB configuration file onto the ESP, like this:

mv /boot/efi/EFI/debian/grub.cfg /boot/efi/EFI/debian/grub.cfg.mini
cp /boot/grub/grub.cfg /boot/efi/EFI/debian/grub.cfg

However, the update-grub command (which is used by Debian's kernel update packages!) will not automatically update the new location. Fortunately, that command is just a script so it will be easy to modify.

First, create a diversion in the package management system so that any updates won't overwrite our changes:

dpkg-divert --local --rename --add /usr/sbin/update-grub

This will automatically rename the current /usr/sbin/update-grub to /usr/sbin/update-grub.distrib and will redirect any future updates of it to the new location too.

Now, you can make a copy of the script back to the original location, and then modify it using your preferred text editor.

cp -a /usr/sbin/update-grub.distrib /usr/sbin/update-grub

Originally, the script looks like this:

#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

You'll want to modify the third line like this:

#!/bin/sh
set -e
exec grub-mkconfig -o /boot/efi/EFI/debian/grub.cfg "$@"

After any major system updates (e.g. from Debian 10 "buster" to Debian 11), you should re-check /usr/sbin/update-grub.distrib and the modified /usr/sbin/update-grub to verify that the diversion is still valid and the new version has not brought any changes to the update-grub script.

Actually, you might need to copy some other files to the ESP also, like the GRUB font file (from /boot/grub/fonts/unicode.pf2 to /boot/efi/EFI/debian/fonts/unicode.pf2) and possibly a GRUB menu background image or something similar related to the GRUB theme you might be using.

4
  • Thank you for your answer. I only really understood about half of the theory but I used your commands to fix the problem. There are however two things that have happened since booting again for the first time since making the changes; just before I get to Grub, a message flashes on the screen for less than a second - error: file '/EFI/debian/fonts/unicode.pf2' not found and after that, Grub's options are surrounded by question marks in boxes, which I assume means something didn't understand the characters provided. Everything works fine, but do you know what that's about?
    – Ban2u
    Aug 9 '20 at 15:11
  • The Grub configuration is referencing a font file that is located somewhere on your removable flash drive. When it isn't plugged in, the "root" command to switch into that filesystem fails and GRUB ends up looking for the font file on the ESP. Try and find the file and copy it to /boot/efi/EFI/debian/fonts/unicode.pf2 and the font issue should get fixed.
    – telcoM
    Aug 9 '20 at 15:19
  • Actually, the font file seems to be at /boot/grub/fonts/unicode.pf2. Copy it from there to the path I mentioned in the previous comment.
    – telcoM
    Aug 9 '20 at 15:23
  • Thank you very much, that did it. Everything works now.
    – Ban2u
    Aug 10 '20 at 7:56
1

Your USB disk contains your entire Debian volume including the /boot directory. Without it, the first-stage grub bootloader embedded in your EFI system partition can't load the grub configuration file, the vfat module (hence the apparent lack of a filesystem in (hd1,2)), or your initramfs or kernel.

You can move the partition on your USB disk to the internal storage if you have space and regenerate the grub configuration so grub understands what you've done, but if you're not attached to it the far simpler thing at this point is going to be a reinstall.

2
  • This is an UEFI system, and (hd1,1) is the EFI System Partition, with a FAT(32) filesystem, as GRUB correctly recognizes. The partitions on the internal eMMC are all standard Windows partitions, and any Linux partitions are apparently on the external Flash drive. Copying things from /boot to the root filesystem doesn't help here, as both seem to be located on the external drive.
    – telcoM
    Aug 9 '20 at 6:12
  • You're right of course; I meant (hd1,2). But yes, reinstalling might the simpler option at this point. Aug 9 '20 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.