Skip to content

Instantly share code, notes, and snippets.

@Denilson-Semedo
Last active June 30, 2023 10:54
Show Gist options
  • Save Denilson-Semedo/9b34e0f0775dc6d2d2759e6ce09b4767 to your computer and use it in GitHub Desktop.
Save Denilson-Semedo/9b34e0f0775dc6d2d2759e6ce09b4767 to your computer and use it in GitHub Desktop.
Recovering a Linux System in Dual Boot with Windows

Fixing the Arch Linux Bootloader using Commands

Arch Linux is a powerful and versatile operating system used by many Linux enthusiasts around the world. However, sometimes things can go wrong, and one of the common issues faced by Arch Linux users is a corrupted or broken bootloader. The bootloader is a crucial component of any operating system as it loads the kernel and initializes the system. If the bootloader is not working correctly, the system may not be able to boot. In this article, we will explain how to fix the Arch Linux bootloader using the following commands:

  1. Identify the partitions
    sudo fdisk -l

This command is used to list all the available disks and their partitions on your system. This will help you identify the correct partition where Arch Linux is installed.

  1. Mount the Arch Linux partition
    sudo mount /dev/sda4 /mnt

This command is used to mount the partition where Arch Linux is installed. In this example, /dev/sda4 is the partition where Arch Linux is installed, and /mnt is the mount point where the partition will be mounted.

  1. Mount the EFI system partition (ESP), if your system require
    sudo mount /dev/sda1 /mnt/boot/efi

This command is used to mount the EFI system partition (ESP) to /mnt/boot/efi. The ESP contains the bootloader files and is required to boot the system in UEFI mode. In this example, /dev/sda1 is the ESP, and /mnt/boot/efi is the mount point.

  1. Enter in the Chroot
    sudo arch-chroot /mnt

This command is used to change the root directory to the mounted partition, allowing you to access the files and directories as if you were in the installed Arch Linux system.

  1. Install GRUB
    sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --recheck

This command installs the GRUB bootloader in UEFI mode. The --target option specifies the architecture, --efi-directory specifies the mount point of the ESP, and --bootloader-id specifies the bootloader identifier. The --recheck option checks for any errors during the installation process.

  1. Generate the GRUB configuration file
    grub-mkconfig -o /boot/grub/grub.cfg

This command generates the GRUB configuration file, which contains the boot menu and configuration options. The configuration file is saved at /boot/grub/grub.cfg.

Its necessary to unmount partitions before rebooting your system to ensure that any changes are properly saved and that the filesystems are not left in an inconsistent state. So after done you leave the Chroot and unmount the partitions with thease commands:

    sudo umount /mnt/boot/efi
    sudo umount /mnt

After reinstalling GRUB, restart the system and verify that it is booting correctly. Ensure that GRUB is appearing during the boot process and that you can choose between Windows and Linux in the GRUB menu.

Conclusion

Fixing the Arch Linux bootloader is a straightforward process, and the commands mentioned above can help you get your system up and running quickly. It is essential to understand the purpose of each command and its options to troubleshoot any issues effectively. Always backup your important data before making any system changes to avoid data loss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment