Grub freezes when naturally booting, but works when selected from EFI menu

I have an odd problem that I have never come across before. First off, the hardware:

HP x360 Spectre Kaby Lake (i7-7500u) Ubuntu 17.10 64bit

The laptop dual boots between Windows and Ubuntu. In setup, I have Ubuntu as the default so I could choose between Windows or Ubuntu from grub. However, when I turn on my laptop, or reboot, the system goes to Grub as expected, but then freezes. The countdown timer stays at 10 seconds and it takes no input.

The weird part is, if I press F9 to bring up the UEFI boot menu, and select the first entry (Ubuntu), grub loads and works fine. I can't figure out what the difference is to have setup boot the Ubuntu EFI entry without my intervention compared to me selecting it from F9 boot menu.

Update: Adding additional info

Files under /boot/efi:

root@localhost:/boot/efi# find .
.
./EFI
./EFI/Microsoft
./EFI/Microsoft/Boot
./EFI/Microsoft/Boot/bg-BG
./EFI/Microsoft/Boot/bg-BG/bootmgfw.efi.mui
./EFI/Microsoft/Boot/bg-BG/bootmgr.efi.mui
./EFI/Microsoft/Boot/boot.stl
./EFI/Microsoft/Boot/bootmgfw.efi
./EFI/Microsoft/Boot/bootmgr.efi
./EFI/Microsoft/Boot/cs-CZ
./EFI/Microsoft/Boot/cs-CZ/bootmgr.efi.mui
./EFI/Microsoft/Boot/cs-CZ/memtest.efi.mui
./EFI/Microsoft/Boot/cs-CZ/bootmgfw.efi.mui
./EFI/Microsoft/Boot/da-DK
./EFI/Microsoft/Boot/da-DK/bootmgr.efi.mui
./EFI/Microsoft/Boot/da-DK/memtest.efi.mui
./EFI/Microsoft/Boot/da-DK/bootmgfw.efi.mui
./EFI/Microsoft/Boot/de-DE
./EFI/Microsoft/Boot/de-DE/bootmgr.efi.mui
./EFI/Microsoft/Boot/de-DE/memtest.efi.mui
./EFI/Microsoft/Boot/de-DE/bootmgfw.efi.mui
./EFI/Microsoft/Boot/el-GR
./EFI/Microsoft/Boot/el-GR/bootmgr.efi.mui
./EFI/Microsoft/Boot/el-GR/memtest.efi.mui
./EFI/Microsoft/Boot/el-GR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/en-GB
./EFI/Microsoft/Boot/en-GB/bootmgfw.efi.mui
./EFI/Microsoft/Boot/en-GB/bootmgr.efi.mui
./EFI/Microsoft/Boot/en-US
./EFI/Microsoft/Boot/en-US/bootmgr.efi.mui
./EFI/Microsoft/Boot/en-US/memtest.efi.mui
./EFI/Microsoft/Boot/en-US/bootmgfw.efi.mui
./EFI/Microsoft/Boot/es-ES
./EFI/Microsoft/Boot/es-ES/bootmgr.efi.mui
./EFI/Microsoft/Boot/es-ES/memtest.efi.mui
./EFI/Microsoft/Boot/es-ES/bootmgfw.efi.mui
./EFI/Microsoft/Boot/es-MX
./EFI/Microsoft/Boot/es-MX/bootmgfw.efi.mui
./EFI/Microsoft/Boot/es-MX/bootmgr.efi.mui
./EFI/Microsoft/Boot/et-EE
./EFI/Microsoft/Boot/et-EE/bootmgfw.efi.mui
./EFI/Microsoft/Boot/et-EE/bootmgr.efi.mui
./EFI/Microsoft/Boot/fi-FI
./EFI/Microsoft/Boot/fi-FI/bootmgr.efi.mui
./EFI/Microsoft/Boot/fi-FI/memtest.efi.mui
./EFI/Microsoft/Boot/fi-FI/bootmgfw.efi.mui
./EFI/Microsoft/Boot/fr-CA
./EFI/Microsoft/Boot/fr-CA/bootmgfw.efi.mui
./EFI/Microsoft/Boot/fr-CA/bootmgr.efi.mui
./EFI/Microsoft/Boot/fr-FR
./EFI/Microsoft/Boot/fr-FR/bootmgr.efi.mui
./EFI/Microsoft/Boot/fr-FR/memtest.efi.mui
./EFI/Microsoft/Boot/fr-FR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/hr-HR
./EFI/Microsoft/Boot/hr-HR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/hr-HR/bootmgr.efi.mui
./EFI/Microsoft/Boot/hu-HU
./EFI/Microsoft/Boot/hu-HU/bootmgr.efi.mui
./EFI/Microsoft/Boot/hu-HU/memtest.efi.mui
./EFI/Microsoft/Boot/hu-HU/bootmgfw.efi.mui
./EFI/Microsoft/Boot/it-IT
./EFI/Microsoft/Boot/it-IT/bootmgr.efi.mui
./EFI/Microsoft/Boot/it-IT/memtest.efi.mui
./EFI/Microsoft/Boot/it-IT/bootmgfw.efi.mui
./EFI/Microsoft/Boot/ja-JP
./EFI/Microsoft/Boot/ja-JP/bootmgr.efi.mui
./EFI/Microsoft/Boot/ja-JP/memtest.efi.mui
./EFI/Microsoft/Boot/ja-JP/bootmgfw.efi.mui
./EFI/Microsoft/Boot/ko-KR
./EFI/Microsoft/Boot/ko-KR/bootmgr.efi.mui
./EFI/Microsoft/Boot/ko-KR/memtest.efi.mui
./EFI/Microsoft/Boot/ko-KR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/lt-LT
./EFI/Microsoft/Boot/lt-LT/bootmgfw.efi.mui
./EFI/Microsoft/Boot/lt-LT/bootmgr.efi.mui
./EFI/Microsoft/Boot/lv-LV
./EFI/Microsoft/Boot/lv-LV/bootmgfw.efi.mui
./EFI/Microsoft/Boot/lv-LV/bootmgr.efi.mui
./EFI/Microsoft/Boot/memtest.efi
./EFI/Microsoft/Boot/nb-NO
./EFI/Microsoft/Boot/nb-NO/bootmgr.efi.mui
./EFI/Microsoft/Boot/nb-NO/memtest.efi.mui
./EFI/Microsoft/Boot/nb-NO/bootmgfw.efi.mui
./EFI/Microsoft/Boot/nl-NL
./EFI/Microsoft/Boot/nl-NL/bootmgr.efi.mui
./EFI/Microsoft/Boot/nl-NL/memtest.efi.mui
./EFI/Microsoft/Boot/nl-NL/bootmgfw.efi.mui
./EFI/Microsoft/Boot/pl-PL
./EFI/Microsoft/Boot/pl-PL/bootmgr.efi.mui
./EFI/Microsoft/Boot/pl-PL/memtest.efi.mui
./EFI/Microsoft/Boot/pl-PL/bootmgfw.efi.mui
./EFI/Microsoft/Boot/pt-BR
./EFI/Microsoft/Boot/pt-BR/bootmgr.efi.mui
./EFI/Microsoft/Boot/pt-BR/memtest.efi.mui
./EFI/Microsoft/Boot/pt-BR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/pt-PT
./EFI/Microsoft/Boot/pt-PT/bootmgr.efi.mui
./EFI/Microsoft/Boot/pt-PT/memtest.efi.mui
./EFI/Microsoft/Boot/pt-PT/bootmgfw.efi.mui
./EFI/Microsoft/Boot/qps-ploc
./EFI/Microsoft/Boot/qps-ploc/memtest.efi.mui
./EFI/Microsoft/Boot/ro-RO
./EFI/Microsoft/Boot/ro-RO/bootmgfw.efi.mui
./EFI/Microsoft/Boot/ro-RO/bootmgr.efi.mui
./EFI/Microsoft/Boot/ru-RU
./EFI/Microsoft/Boot/ru-RU/bootmgr.efi.mui
./EFI/Microsoft/Boot/ru-RU/memtest.efi.mui
./EFI/Microsoft/Boot/ru-RU/bootmgfw.efi.mui
./EFI/Microsoft/Boot/sk-SK
./EFI/Microsoft/Boot/sk-SK/bootmgfw.efi.mui
./EFI/Microsoft/Boot/sk-SK/bootmgr.efi.mui
./EFI/Microsoft/Boot/sl-SI
./EFI/Microsoft/Boot/sl-SI/bootmgfw.efi.mui
./EFI/Microsoft/Boot/sl-SI/bootmgr.efi.mui
./EFI/Microsoft/Boot/sr-Latn-CS
./EFI/Microsoft/Boot/sr-Latn-CS/memtest.efi.mui
./EFI/Microsoft/Boot/sr-Latn-RS
./EFI/Microsoft/Boot/sr-Latn-RS/bootmgfw.efi.mui
./EFI/Microsoft/Boot/sr-Latn-RS/bootmgr.efi.mui
./EFI/Microsoft/Boot/sv-SE
./EFI/Microsoft/Boot/sv-SE/bootmgr.efi.mui
./EFI/Microsoft/Boot/sv-SE/memtest.efi.mui
./EFI/Microsoft/Boot/sv-SE/bootmgfw.efi.mui
./EFI/Microsoft/Boot/tr-TR
./EFI/Microsoft/Boot/tr-TR/bootmgr.efi.mui
./EFI/Microsoft/Boot/tr-TR/memtest.efi.mui
./EFI/Microsoft/Boot/tr-TR/bootmgfw.efi.mui
./EFI/Microsoft/Boot/uk-UA
./EFI/Microsoft/Boot/uk-UA/bootmgfw.efi.mui
./EFI/Microsoft/Boot/uk-UA/bootmgr.efi.mui
./EFI/Microsoft/Boot/zh-CN
./EFI/Microsoft/Boot/zh-CN/bootmgr.efi.mui
./EFI/Microsoft/Boot/zh-CN/memtest.efi.mui
./EFI/Microsoft/Boot/zh-CN/bootmgfw.efi.mui
./EFI/Microsoft/Boot/zh-HK
./EFI/Microsoft/Boot/zh-HK/bootmgr.efi.mui
./EFI/Microsoft/Boot/zh-HK/memtest.efi.mui
./EFI/Microsoft/Boot/zh-HK/bootmgfw.efi.mui
./EFI/Microsoft/Boot/zh-TW
./EFI/Microsoft/Boot/zh-TW/bootmgr.efi.mui
./EFI/Microsoft/Boot/zh-TW/memtest.efi.mui
./EFI/Microsoft/Boot/zh-TW/bootmgfw.efi.mui
./EFI/Microsoft/Boot/BOOTSTAT.DAT
./EFI/Microsoft/Boot/Fonts
./EFI/Microsoft/Boot/Fonts/chs_boot.ttf
./EFI/Microsoft/Boot/Fonts/cht_boot.ttf
./EFI/Microsoft/Boot/Fonts/jpn_boot.ttf
./EFI/Microsoft/Boot/Fonts/kor_boot.ttf
./EFI/Microsoft/Boot/Fonts/malgunn_boot.ttf
./EFI/Microsoft/Boot/Fonts/malgun_boot.ttf
./EFI/Microsoft/Boot/Fonts/meiryon_boot.ttf
./EFI/Microsoft/Boot/Fonts/meiryo_boot.ttf
./EFI/Microsoft/Boot/Fonts/msjhn_boot.ttf
./EFI/Microsoft/Boot/Fonts/msjh_boot.ttf
./EFI/Microsoft/Boot/Fonts/msyhn_boot.ttf
./EFI/Microsoft/Boot/Fonts/msyh_boot.ttf
./EFI/Microsoft/Boot/Fonts/segmono_boot.ttf
./EFI/Microsoft/Boot/Fonts/segoen_slboot.ttf
./EFI/Microsoft/Boot/Fonts/segoe_slboot.ttf
./EFI/Microsoft/Boot/Fonts/wgl4_boot.ttf
./EFI/Microsoft/Boot/Resources
./EFI/Microsoft/Boot/Resources/bootres.dll
./EFI/Microsoft/Boot/Resources/en-US
./EFI/Microsoft/Boot/Resources/en-US/bootres.dll.mui
./EFI/Microsoft/Boot/Resources/fr-FR
./EFI/Microsoft/Boot/Resources/fr-FR/bootres.dll.mui
./EFI/Microsoft/Boot/kd_02_10df.dll
./EFI/Microsoft/Boot/kd_02_10ec.dll
./EFI/Microsoft/Boot/kd_02_1137.dll
./EFI/Microsoft/Boot/kd_02_14e4.dll
./EFI/Microsoft/Boot/kd_02_15b3.dll
./EFI/Microsoft/Boot/kd_02_1969.dll
./EFI/Microsoft/Boot/kd_02_19a2.dll
./EFI/Microsoft/Boot/kd_02_8086.dll
./EFI/Microsoft/Boot/kd_07_1415.dll
./EFI/Microsoft/Boot/kd_0C_8086.dll
./EFI/Microsoft/Boot/kdstub.dll
./EFI/Microsoft/Boot/BCD
./EFI/Microsoft/Boot/BCD.LOG
./EFI/Microsoft/Boot/BCD.LOG1
./EFI/Microsoft/Boot/BCD.LOG2
./EFI/Microsoft/Recovery
./EFI/Microsoft/Recovery/BCD
./EFI/Microsoft/Recovery/BCD.LOG
./EFI/Microsoft/Recovery/BCD.LOG1
./EFI/Microsoft/Recovery/BCD.LOG2
./EFI/Boot
./EFI/Boot/bootx64.efi
./EFI/Boot/fbx64.efi
./EFI/HP
./EFI/HP/SystemDiags
./EFI/HP/SystemDiags/CryptRSA.efi
./EFI/HP/SystemDiags/CryptRSA32.efi
./EFI/HP/SystemDiags/SystemDiags.efi
./EFI/HP/SystemDiags/SystemDiags32.efi
./EFI/HP/SystemDiags/SystemDiags.sig
./EFI/HP/SystemDiags/SystemDiags32.sig
./EFI/HP/SystemDiags/SystemDiags.s09
./EFI/HP/SystemDiags/SystemDiags32.s09
./EFI/HP/SystemDiags/SystemDiags.s12
./EFI/HP/SystemDiags/SystemDiags32.s12
./EFI/HP/SystemDiags/SystemDiags.s14
./EFI/HP/SystemDiags/SystemDiags32.s14
./EFI/HP/SystemDiags/HpSysDiags.efi
./EFI/HP/SystemDiags/HpSysDiags32.efi
./EFI/HP/SystemDiags/HpSysDiags.s09
./EFI/HP/SystemDiags/HpSysDiags32.s09
./EFI/HP/SystemDiags/HpSysDiags.s12
./EFI/HP/SystemDiags/HpSysDiags32.s12
./EFI/HP/SystemDiags/HpSysDiags.s14
./EFI/HP/SystemDiags/HpSysDiags32.s14
./EFI/HP/BIOSUpdate
./EFI/HP/BIOSUpdate/CryptRSA.efi
./EFI/HP/BIOSUpdate/CryptRSA32.efi
./EFI/HP/BIOSUpdate/HpBiosUpdate.efi
./EFI/HP/BIOSUpdate/HpBiosUpdate32.efi
./EFI/HP/BIOSUpdate/HpBiosUpdate.sig
./EFI/HP/BIOSUpdate/HpBiosUpdate32.sig
./EFI/HP/BIOSUpdate/HpBiosUpdate.s09
./EFI/HP/BIOSUpdate/HpBiosUpdate32.s09
./EFI/HP/BIOSUpdate/HpBiosUpdate.s12
./EFI/HP/BIOSUpdate/HpBiosUpdate32.s12
./EFI/HP/BIOSUpdate/HpBiosUpdate.s14
./EFI/HP/BIOSUpdate/HpBiosUpdate32.s14
./EFI/HP/BIOSUpdate/HpBiosMgmt.efi
./EFI/HP/BIOSUpdate/HpBiosMgmt32.efi
./EFI/HP/BIOSUpdate/HpBiosMgmt.s09
./EFI/HP/BIOSUpdate/HpBiosMgmt32.s09
./EFI/HP/BIOSUpdate/HpBiosMgmt.s12
./EFI/HP/BIOSUpdate/HpBiosMgmt32.s12
./EFI/HP/BIOSUpdate/HpBiosMgmt.s14
./EFI/HP/BIOSUpdate/HpBiosMgmt32.s14
./EFI/HP/BIOS
./EFI/HP/BIOS/Current
./EFI/HP/BIOS/Current/0827E.sig
./EFI/HP/BIOS/Current/0827E.bin
./EFI/HP/BIOS/New
./EFI/HP/BIOS/Previous
./EFI/ubuntu
./EFI/ubuntu/fw
./EFI/ubuntu/fwupx64.efi
./EFI/ubuntu/grubx64.efi
./EFI/ubuntu/grub.cfg
./EFI/ubuntu/shimx64.efi
./EFI/ubuntu/mmx64.efi
./EFI/ubuntu/BOOTX64.CSV
./System Volume Information
./System Volume Information/IndexerVolumeGuid

For gdisk, I'm assuming this is what is requested?

root@localhost:/boot/efi# gdisk /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/nvme0n1: 1000215216 sectors, 476.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A2E05477-2E06-47DD-865C-60C3C58F9E7B
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 12909 sectors (6.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          534527   260.0 MiB   EF00  EFI system partition
   2          534528          567295   16.0 MiB    0C01  Microsoft reserved ...
   3          567296       768909311   366.4 GiB   0700  Basic data partition
   4       975620096       977627135   980.0 MiB   2700  Basic data partition
   5       977627136      1000204287   10.8 GiB    0700  Basic data partition
   6       768909312       975620095   98.6 GiB    8300  

Command (? for help): 

Output of fdisk for good measure:

root@localhost:/boot/efi# fdisk --list
Disk /dev/nvme0n1: 477 GiB, 512110190592 bytes, 1000215216 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: A2E05477-2E06-47DD-865C-60C3C58F9E7B

Device             Start        End   Sectors   Size Type
/dev/nvme0n1p1      2048     534527    532480   260M EFI System
/dev/nvme0n1p2    534528     567295     32768    16M Microsoft reserved
/dev/nvme0n1p3    567296  768909311 768342016 366.4G Microsoft basic data
/dev/nvme0n1p4 975620096  977627135   2007040   980M Windows recovery environmen
/dev/nvme0n1p5 977627136 1000204287  22577152  10.8G Microsoft basic data
/dev/nvme0n1p6 768909312  975620095 206710784  98.6G Linux filesystem

Partition table entries are not in disk order.

Solution 1:

Unfortunately, Boot Repair doesn't handle NVMe disks properly, so a bunch of important information is missing from your BootInfo report; however, it does show a single ubuntu entry in the NVRAM boot manager list, so it's unlikely that the system is booting through some other path -- EXCEPT that you have a fallback boot loader (EFI/BOOT/bootx64.efi) that, from the other file in that directory (fbx64.efi), is probably a tool to recover the boot setup in case of a firmware failure. This tool, and how to configure and use it, is described in my rEFInd documentation (although it's not part of rEFInd; that page just has the most complete and concise description of fbx64.efi that I know about):

http://www.rodsbooks.com/refind/bootcoup.html#fallback

It's possible that your computer is losing its boot order variable, booting through Shim (as EFI/BOOT/bootx64.efi) and fbx64.efi, which then kicks the boot process over to the regular ubuntu entry (which launches a second Shim and then GRUB), which then hangs; but when the ubuntu entry launches directly, it works fine. This could happen because of bugs involving two copies of Shim being launched, because fbx64.efi itself is causing problems, or for some other reason. This hypothesis is very speculative; it's based on very little evidence and quite a few assumptions. It also assumes bugs in your firmware, and likely in Shim, fbx64.efi, and/or GRUB. It is consistent with the symptoms you're seeing, though, and it's the only explanation that springs to mind. If it's what's happening, you could try, as diagnostic procedures or to fix the problem:

  • Rename the EFI/BOOT directory on the ESP -- If you rename this directory and the problem persists exactly as it has, then my hypothesis is wrong. (This is because renaming EFI/BOOT will prevent the computer from attempting to launch the Shim and fbx64.efi stored in that directory; so if it keeps booting, it must be that the boot order and boot variables are being retained and honored, contrary to my hypothesis.) If, however, the computer begins booting correctly, or booting straight to Windows, then that's evidence that it had been booting in this way, and my hypothesis becomes much more likely. You should be able to rename the directory back to EFI/BOOT to restore the (failing) boot operation, which will be necessary for the next three repairs....
  • Disable Secure Boot -- Disabling Secure Boot will alter the way Shim works, and if my hypothesis is correct, this might get things working -- or it might have no effect. Even if my hypothesis is correct, this change will work only if the failure is caused by Secure Boot, which might not be the case.
  • Copy EFI/ubuntu/grub* to EFI/BOOT -- If you copy GRUB (grubx64.efi) and its configuration file (grub.cfg) from EFI/ubuntu to EFI/BOOT, then Shim in EFI/BOOT (that is, EFI/BOOT/bootx64.efi) should launch GRUB directly from EFI/BOOT, rather than going through fbx64.efi. This should bypass the problem, if my hypothesis is correct.
  • Use rEFInd -- My rEFInd boot manager boots in an entirely different way from GRUB, so chances it won't be affected by the problem. With Secure Boot active, though, you'll need to enroll a key or two in your MOK list, as described in the rEFInd Secure Boot documentation. Also, you may need to delete or rename the EFI/ubuntu/BOOTX64.CSV file on your ESP. (Rename it to something with a filename that does not end in .CSV, or any case-altered variant of that, like .csv.) The reason is that fbx64.efi looks for .CSV files to regenerate the NVRAM-based boot entry, so if that file is present, there's a 50/50 chance it will take precedence over the BOOT.CSV file that rEFInd creates for itself, thus causing the system to boot to GRUB and continue failing in the way you describe.
  • Update your firmware -- If your manufacturer offers a newer firmware (probably called a "BIOS") than what you're using now, you can upgrade it. This is a shot in the dark, though; your problem sounds exotic enough that it's unlikely to have been addressed in a firmware update.

I recommend you try the first of these options as a diagnostic. If the boot behavior changes as I've described, you can then restore EFI/BOOT to the way it had been and try any of the next three options -- or more than one, if your first attempt fails. If, OTOH, renaming EFI/BOOT has no effect, then the next two options are unlikely to work (although disabling Secure Boot might help). Installing rEFInd becomes the option that's most likely to work in this case, but that's really a shot in the dark. Updating the firmware might work even if the first diagnostic option doesn't change the behavior, but as I said, that's a desperate option that's unlikely to work no matter what the cause is. Still, it's worth trying if you have no other options (or maybe even if you do -- firmware updates can fix all sorts of problems, add features, and improve performance).

Good luck fixing your problem!