|
| 1 | +--- |
| 2 | +title: Linux VM boots to GRUB rescue |
| 3 | +description: Provides troubleshooting guidance for GRUB rescue issues with Linux virtual machines. |
| 4 | +services: virtual-machines |
| 5 | +documentationcenter: '' |
| 6 | +author: divargas |
| 7 | +ms.service: azure-virtual-machines |
| 8 | +ms.collection: linux |
| 9 | +ms.workload: infrastructure-services |
| 10 | +ms.tgt_pltfrm: vm-linux |
| 11 | +ms.custom: sap:My VM is not booting, linux-related-content |
| 12 | +ms.topic: troubleshooting |
| 13 | +ms.date: 02/25/2025 |
| 14 | +ms.author: divargas |
| 15 | +ms.reviewer: ekpathak, v-leedennis, v-weizhu |
| 16 | +--- |
| 17 | + |
| 18 | +# Linux virtual machine boots to GRUB rescue |
| 19 | + |
| 20 | +**Applies to:** :heavy_check_mark: Linux VMs |
| 21 | + |
| 22 | +<!-- Commenting out these entries as this information should be selected by the user along with the corresponding subscription and region |
| 23 | +
|
| 24 | +The First step in this tutorial is to define environment variables. |
| 25 | +
|
| 26 | +```azurecli-interactive |
| 27 | +export MY_RESOURCE_GROUP_NAME="myVMResourceGroup89f292" |
| 28 | +export MY_VM_NAME="myVM89f292" |
| 29 | +``` |
| 30 | +--> |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +This article discusses multiple conditions that cause GRUB rescue issues and provides troubleshooting guidance. |
| 35 | + |
| 36 | +During the boot process, the boot loader tries to locate the Linux kernel and hand off the boot control. If this handoff can't be performed, the virtual machine (VM) enters a GRUB rescue console. The GRUB rescue console prompt isn't shown in the Azure serial console log, but it can be shown in the [Azure boot diagnostics screenshot](/azure/virtual-machines/boot-diagnostics#boot-diagnostics-view). |
| 37 | + |
| 38 | +## <a id="identify-grub-rescue-issue"></a>Identify GRUB rescue issue |
| 39 | + |
| 40 | +[View a boot diagnostics screenshot](/azure/virtual-machines/boot-diagnostics#boot-diagnostics-view) in the VM **Boot diagnostics** page of the Azure portal. This screenshot helps diagnose the GRUB rescue issue and determine if a boot error causes the issue. |
| 41 | + |
| 42 | +The following text is an example of a GRUB rescue issue: |
| 43 | + |
| 44 | +```output |
| 45 | +error: file '/boot/grub2/i386-pc/normal.mod' not found. |
| 46 | +Entering rescue mode... |
| 47 | +grub rescue> |
| 48 | +``` |
| 49 | + |
| 50 | +## <a id="offline-troubleshooting"></a>Troubleshoot GRUB rescue issue offline |
| 51 | + |
| 52 | +1. To troubleshoot a GRUB rescue issue, a rescue/repair VM is required. Use [vm repair commands](repair-linux-vm-using-azure-virtual-machine-repair-commands.md) to create a repair VM that has a copy of the affected VM's OS disk attached. Mount the copy of the OS file systems in the repair VM by using [chroot](chroot-environment-linux.md). |
| 53 | + |
| 54 | + > [!NOTE] |
| 55 | + > Alternatively, you can create a rescue VM manually by using the Azure portal. For more information, see [Troubleshoot a Linux VM by attaching the OS disk to a recovery VM using the Azure portal](troubleshoot-recovery-disks-portal-linux.md). |
| 56 | +
|
| 57 | +2. [Identify GRUB rescue issue](#identify-grub-rescue-issue). When you encounter one of the following GRUB rescue issues, go to the corresponding section to resolve it: |
| 58 | + |
| 59 | + * [Error: unknown filesystem](#unknown-filesystem) |
| 60 | + * [Error 15: File not found](#error15) |
| 61 | + * [Error: file '/boot/grub2/i386-pc/normal.mod' not found](#normal-mod-file-not-found) |
| 62 | + * [Error: no such partition](#no-such-partition) |
| 63 | + * [Error: symbol 'grub_efi_get_secure_boot' not found](#grub_efi_get_secure_boot) |
| 64 | + * [Other GRUB rescue errors](#other-grub-rescue-errors) |
| 65 | + |
| 66 | +3. After the GRUB rescue issue is resolved, perform the following actions: |
| 67 | + |
| 68 | + 1. Unmount the copy of the file systems from the rescue/repair VM. |
| 69 | + |
| 70 | + 2. Run the `az vm repair restore` command to swap the repaired OS disk with the original OS disk of the VM. For more information, see Step 5 in [Repair a Linux VM by using the Azure Virtual Machine repair commands](repair-linux-vm-using-azure-virtual-machine-repair-commands.md). |
| 71 | + |
| 72 | + 3. Check whether the VM can start by taking a look at the Azure serial console or by trying to connect to the VM. |
| 73 | + |
| 74 | +4. If the entire /boot partition or other important contents are missing and can't be recovered, we recommend restoring the VM from a backup. For more information, see [How to restore Azure VM data in Azure portal](/azure/backup/backup-azure-arm-restore-vms). |
| 75 | + |
| 76 | +See the following sections for detailed errors, possible causes, and solutions. |
| 77 | + |
| 78 | +> [!NOTE] |
| 79 | +> In the commands mentioned in the following sections, replace `/dev/sdX` with the corresponding Operating System (OS) disk device. |
| 80 | +
|
| 81 | +### <a id="offline-troubleshooting"></a> Reinstall GRUB and regenerate GRUB configuration file using Auto Repair (ALAR) |
| 82 | + |
| 83 | +Azure Linux Auto Repair (ALAR) scripts are part of the VM repair extension described in [Use Azure Linux Auto Repair (ALAR) to fix a Linux VM](./repair-linux-vm-using-alar.md). ALAR covers the automation of multiple repair scenarios, including GRUB rescue issues. |
| 84 | + |
| 85 | +The ALAR scripts use the repair extension `repair-button` to fix GRUB issues by specifying `--button-command grubfix` for Generation 1 VMs, or `--button-command efifix` for Generation 2 VMs. This parameter triggers the automated recovery. Implement the following step to automate the fix of common GRUB errors that could be fixed by reinstalling GRUB and regenerating the corresponding configuration file: |
| 86 | + |
| 87 | +```azurecli-interactive |
| 88 | +GEN=$(az vm get-instance-view --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query "instanceView.hyperVGeneration" --output tsv) |
| 89 | +if [[ "$GEN" =~ "[Vv]?2" ]]; then ALAR="efifix"; else ALAR="grubfix"; fi |
| 90 | +output=$(az extension add -n vm-repair; az extension update -n vm-repair; az vm repair repair-button --button-command $ALAR --verbose --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME) |
| 91 | +value=$(echo "$output" | jq -r '.message') |
| 92 | +extracted=$(echo $value) |
| 93 | +echo "$extracted" |
| 94 | +``` |
| 95 | + |
| 96 | +The repair VM script, in conjunction with the ALAR script, temporarily creates a resource group, a repair VM, and a copy of the affected VM's OS disk. It reinstalls GRUB and regenerates the corresponding GRUB configuration file and then it swaps the OS disk of the broken VM with the copied fixed disk. Finally, the `repair-button` script will automatically delete the resource group containing the temporary repair VM. |
| 97 | + |
| 98 | +## Next steps |
| 99 | + |
| 100 | +If the specific boot error isn't a GRUB rescue issue, refer to [Troubleshoot Azure Linux Virtual Machines boot errors](boot-error-troubleshoot-linux.md) for further troubleshooting options. |
| 101 | + |
| 102 | +[!INCLUDE [Third-party disclaimer](../../../includes/third-party-disclaimer.md)] |
| 103 | + |
| 104 | +[!INCLUDE [Third-party contact disclaimer](../../../includes/third-party-contact-disclaimer.md)] |
0 commit comments