Adding UEFI boot entry for Linux Debian machine in Hyper-V

Recently, I had such a case that I created a test virtual machine on a host with Hyper-V Server 2019 installed and I wanted to transfer it to a host with production machines on Windows Server 2016. As you know, live migration, restore from backup or export / import will fail with due to the fact that in version 2019 there is a newer version of the virtual machine configuration. While importing or transferring the machine from a lower version to a higher one is not a problem, in my case a problem arose and it was possible to solve it, and I will describe the method of doing it below.

The solution to the problem is to create the machine in a lower configuration version and connect the disk to it from the source machine. This is where creating a virtual machine with PowerShell will help:

PS C:\Users\Administrator> New-VM Debian10-v8.0 -Version 8.0 -Generation 2

Name          State CPUUsage(%) MemoryAssigned(M) Uptime   Status             Version
----          ----- ----------- ----------------- ------   ------             -------
Debian10-v8.0 Off   0           0                 00:00:00 Operating normally 8.0    

Hyper-V Manager confirms that virtual machine created correctly.

Newly created virtual machine in configuration version 8.0 and source version 9.0

Next, I set the parameters of the virtual machine through Hyper-V manager and connect the one from the source machine as a disk:

VM parameters Debian10-v8.0

After setting boot from disk as the first in order, unfortunately the attempt to boot the machine ends like this:

Virtual machine Debian10-v8.0 failed start

After checking the Boot order parameters on the source machine, you can see that we have the File entry set first, which is not present in the newly created machine. File Hyper-V type added during system installation.

Boot order on the Debian10 (source) machine. I have marked the file path which will be given in the efibootmgr command

On the new machine, we need to add this entry and for this we will use, for example, starting the system from a Live CD with a Linux or booting the system in recovery mode from the installation CD and adding the entry using efibootmgr. I started the system in recovery mode and mounted the root and boot partition. Then I executed the command after which the appropriate entry appeared in Boot order:

efibootmgr --create --label Debian --disk /dev/sda1 --loader "\EFI\debian\shimx64.efi"
Boot order after above command efibootmgr

After restart Linux Debian starts correctly

Debian successfully started

Update: Running Debian in rescue mode

I decided to add some screenshots of Debian rescue mode in order to help with any problems that may occur. Please see below screenshots with complete solution that I did for the above problem that Debian cannot boot after attaching a disk from a lower version of Hyper-V virtual machine. For this purpose, I used Debian 11 ISO and as you can see the efibootmgr command doesn’t work, so I used grub-install

grub-install --force-extra-removable --target=x86_64-efi /dev/sda
5 1 vote
Article Rating
Subscribe
Notify of
guest

8 comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Cedric
Cedric
2 years ago

Thanks a lot, you helped me in restoring a vhdx file from a broken debian to an other fresh debian vm (fixing grub)

John Mint
John Mint
1 year ago

Can you pls share what commands you used for this part – “..and mounted the root and boot partition.”. Thanks a lot.

Shorty
Shorty
1 year ago

Hi Daniel,
I get this Error: Do you now what I do wrong?

Debian_rescue_Mode.jpg
Claudiu
Claudiu
1 year ago
Reply to  daniel

Having the same problem. I don’t have that command available.
I’m booting from Debian 11.5 amd64 ISO into rescue mode.
Executed the shell into /dev/sda1. Then ran efibootmgr command.

Can you share the complete steps on “mounting the root and boot partition” for those of us that have 0 linux experience?

Reading the above article did not help me unfortunatelly.

Thanks.

jho
jho
1 year ago

Thank you, it works !