Unable to boot after moving hard drive to another computer

I have an m.2 NVMe hard drive that was installed in one computer working perfectly with Ubuntu installed. I moved the drive to another computer and I am unable to boot with it. When I boot the computer, it brings me to the EFI shell.

In the BIOS, the drive is not listed under boot devices, however, in Advanced > NVMe configuration it lists my drive. I also tried booting from a live CD and I can see the drive and all the files.

I'm not 100% sure, but I may have installed the OS in legacy mode instead of UEFI mode.

How can I make it so that the BIOS sees the drive as bootable? Do I need to reinstall Grub?


After more investigation, it turns out that the OS was indeed installed in legacy BIOS mode, which is why it wasn't being found in the BIOS as a bootable device. I enabled legacy mode in the BIOS to see what would happen, and, unfortunately, I just got a black screen on boot, so something wasn't quite right there.

I wanted to give just converting it from BIOS to UEFI a try. Even though you sometimes can't transplant a drive from one computer to another as Nmath says in the comments, I've done this myself several times and never with any major issues beyond proprietary hardware drivers, which can simply be installed, so I decided to do it again. This was also much simpler than doing a fresh install.

This was my process:

  • Boot a Live USB with Ubuntu (and make sure it's in UEFI mode, which it obviously will be if the BIOS has legacy mode disabled).
  • Backup my partition table with sfdisk -d /dev/nvme0n1 > mbr-backup.txt in case something goes wrong.
  • Convert the partition from MBR to GPT with gdisk /dev/nvme0n1, then w to write the new partition table.
  • With GParted, resize the first partition to leave 550 MB before it and add a new FAT32 partition to the beginning and add the EFI and BOOT flags to it.
  • Run boot-repair and do the default repair following all prompts.

Fortunately, Ubuntu does a great job of detecting hardware changes. I took the drive from a computer with an Nvidia graphics card installed and put it into another with Intel graphics and everything just works out of the box.