Reinstall Grub after motherboard replacement (or hdd upgrade)

Posted by:

Prepare Arch Linux Live Disc

  1. Make a bootable installation media for Arch Linux
  2. This laptop doesn’t have any CD/DVD drive so the first thing is to make a bootable USB drive.

    Boot into Windows 10. In Windows, download archlinux iso from the following website

    https://www.archlinux.org/download/

    Use the mirror which is closest to you and download the Arch iso. archlinux-2015.12.01-dual.iso

    Download Rufus from the following location https://rufus.akeo.ie/

    Plugin any usb drive/pendrive in your usb port. Make sure that you backup data from this usb drive

    rufus_en.png

  3. Attach it to your computer

Turn off Windows fast boot and secure boot, if not already [NOT needed to HDD upgrade]

  1. Shutdown Windows after disabling fast start following instruction here or here. And use the command shutdown -s -t 0 to do so.
  2. Restart windows by clicking on Power -> Restart. Make sure that when hitting restart, you are press down Shift key Windows will give you options for Troubleshoot/Adanced Options/UEFI Firmware/

    lenova-1.JPG

    lenovo-1.JPG

    lenovo-3.JPG

    1. Once you restart your machine you should be able to see the BIOS settings.

      Under Configuration you should disable Intel Fast boot, disable SecureBoot (more here). Make sure you change the settings for Graphics from Switchable to Internal. This is needed only to install, you can then modify it later. Save the changes and exit.

  3. Once the machine restarts press and hold F12 key.

    This will give you option to boot from various available devices and your USB drive would be one of them

    lenovo-4.JPG

  4. Select your USB drive to boot
  5. Select the UEFI boot mode when you see the ArchLinux boot screen.

    lenovo-5.JPG

    Once the usb has booted you will see the root prompt.

Connect to the internet (Wi-Fi), if you need to update or install some packages in chroot session


Decrypt the root partition with LUKS Link


where /dev/sdX is the disk (not a partition) where GRUB is to be installed. For example /dev/sda or /dev/nvme0n1, or /dev/mmcblk0


Find and mount the efi partition to /mnt/boot/efi


Arch and Grub Installation after chroot in.

  1. chroot into the arch installation (from live CD).


  2. Install the bootloader – grub.

    Note: This step should NOT be necessary.

    Install the packages grub and efibootmgr. GRUB is the bootloader, efibootmgr creates bootable .efi stub entries used by the GRUB installation script.


Generate the main configuration file

  1. Make sure all partitions are mounted, i.e. / /boot /boot/efi



  2. Intial Ramdisk Environment


    Note: Step 2-4 can be omitted, it does not hurt though. You can jump to step 5 configure grub.

    Add the encrypt hook to mkinitcpio.conf: link here.


  3. update /etc/default/grub


  4. install os-prober, only detect the correct Windows boot after boot into Linux, not from chroot with live CD.
  5. configure grub

    The following steps install the GRUB UEFI application to $esp/EFI/grub, install its modules to /boot/grub/x86_64-efi, and place the bootable grubx64.efi stub in $esp/EFI/grub.

    First, tell GRUB to use UEFI, set the boot directory and set the bootloader ID. Mount the ESP partition to e.g. /boot or /boot/efi and in the following change $esp to that mount point (usually /boot):


    The –bootloader-id is what appears in the boot options to identify the GRUB EFI boot option; make sure this is something you will recognize later. The install will create a directory of the same name under $esp/EFI/ where the EFI binary bootloader will be placed.


    Now, let’s add Windows to the GRUB menu. Edit /boot/grub/grub.cfg and add the following menuentry after the Arch Linux menuentries [Note: grub boot loader does not locate Windows OS, but this is necessary for grub to load Arch Linux in my case. After I boot into arch linux, I ran sudo os-prober and update grub config.] See here for details.


    and update the string with following output:

    $hints_string with the output of $ grub-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi. $fs_uuid with the output of $ grub-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi.

  6. Unmount and Reboot

  1. Reboot into Arch Linux
  2. Install os-prober. Regenerate grub configuration. Reboot.


    Done! Now you can choose between Windows and Arch Linux at the start. Yay!

0

Add a Comment