The symptoms you report can be caused by at least three things:
- Mixed-mode (BIOS/EFI) installations -- If Windows is installed in EFI mode and you install Linux in BIOS/CSM/legacy mode (or vice-versa), you can see something like what you report. The best solution to this problem is to install an EFI-mode boot loader for Linux. The Boot Repair tool recommended by others can do this, and there are other ways to do it, too; however, it's important that you verify that this is the problem before you try this fix. Also, Boot Repair will do nothing useful if you run it from a BIOS-mode boot, so you must disable your CSM before you attempt this repair. See my page on the CSM and its problems for more on this issue. You can tell if your Ubuntu is booting in EFI mode or in BIOS mode by looking for a directory called
/sys/firmware/efi
. If that directory is present, you've booted in EFI mode and this explanation is most likely not the issue; but if that directory is not present, you've booted in BIOS mode and this may well be the problem.
- Mis-set EFI-mode boot order -- On an EFI-based computer, the order in which the computer tries various boot loaders is stored in NVRAM. If this information is incorrect or missing, you can end up booting straight to the wrong OS. To fix it, you can adjust the boot order with
efibootmgr
, as described here; or in Windows with the EasyUEFI utility.
- Windows adjusting the boot order on every boot -- This possibility is a special case of the former one. I've seen some reports of Windows adjusting the boot order with every boot. This can result in something like the problem you're seeing, but with the caveat that the boot order remains set to Ubuntu if you shut down or reboot from Ubuntu, but it changes only when you boot to Windows. See this question and answers for more on this problem.
Because the solutions are so different, it's important that you better diagnose the problem before proceeding. Checking your Ubuntu boot mode is the most important diagnostic. Identifying whether the problem occurs with every boot or only after booting to Windows is also important.
Finally, most EFIs provide some means to enter a built-in boot manager; however, this option is sometimes disabled by a firmware "fast start" option. Try entering your firmware setup utility and looking for any option called "fast start" or something similar and disabling it. This feature causes the firmware to perform minimal USB initialization rather than full USB initialization, so the keyboard may be non-functional until an OS takes control. Sometimes it's referred to as something relating to USB initialization, so you can look for options like that, too.