A Uh-oh moment – Things I learned after a dual-boot-system failure

Posted by:

arch-fail1.JPG

It was a late night, and I did a full system update. Either it failed during update or whatever … as I said it is late and I am tired… The system won’t boot into Linux the next morning

The reason was …

As I suspected, the kernal is corrupted.

arch-fail2.jpeg

rollback the kernal from cache:


I could’ve updated the grub config and fix the loader, but I panic; and I did not know. so, I took the hard way.

Restore the system

Back up the partition

  1. Boot from a live media.
  2. Make sure no partitions are mounted from the source hard drive.
  3. Mount the external HD
  4. Backup the drive.

Reinstall the arch with steps here.

Rsync and restore the system

  1. decrypt and read img file with info here.


  2. Restore files


    Note: Rename these files and folder in backup image: /etc/fstab , /grub/grub.cfg , /etc/mkinitcpio.d mkinitcpio.conf

  3. Unmount and clean up


  4. If needed, fix after boot and then chroot into live media.

Access the image file from Arch Linux System


Note: (from here.) Note: If it gives you the error /dev/loop0: No such file or directory, you need to first load the kernel module with modprobe loop. These days (Kernel 3.2) loop devices are created on demand. Ask for a new loop device with # losetup -f.

Reinstall Grub after motherboard replacement (or hdd upgrade)

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 section assumes you are installing GRUB for x86_64 systems. For IA32 (32-bit) UEFI systems (not to be confused with 32-bit CPUs), replace x86_64-efi with i386-efi where appropriate.

    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!

Recovery bootloader for a dual boot system of Windows 7 and Arch Linux

After rendering one of my old laptops into OS-less state by restoring the Arch Linux OS from another System without exclude the boot, following is what I did to recover the dual-boot system. I have to fix the MBR and Boot for windows first and then reinstall the grub boot loader with linux live CD.

Fix Windows 7 MBR and Boot (also works for Windows 10)

Adapted from here.

  1. Boot from the Windows 7 installation DVD. Note: The DVD with the same windows OS is needed. At the “Press any key to boot from CD or DVD…”, press any key to boot from the DVD Select a language Select a keyboard layout Click Next Select the operating system and click Next. The “Use recovery tools that can help fix problems starting Windows” must be checked when you select the operating system. At the System Recovery Options screen, click on Command Prompt

    windows-7-system-recovery-options-screen_2017-12-10_11-46-30.jpg

  2. Command Prompt successfully loads, type this command:


  3. Press Enter Type the next command:


  4. Press Enter Type the next command:


  5. Press Enter Remove the installation DVD from the disk tray and restart your computer

Reinstall grub with Arch Linux Live Disc

Decrypt the root partition with LUKS Link



Find and mount the boot partition. Note: it is a fat partition before, linux; NOT the MBR sda1.


Arch and Grub Installation after chroot in.

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


  2. Install the bootloader – grub.

    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


    Add the encrypt hook to mkinitcpio.conf: link here


  3. retrieve the UUID, it is the crypto_LUK one.


  4. update /etc/default/grub


  5. install os-prober, only detect the correct Windows boot after boot into Linux, not from chroot with live CD.
  6. 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/efi/EFI/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:

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

  7. Unmount and Reboot


  8. Reboot into Arch Linux

    Done! Hopefully you can choose between Windows and Arch Linux at the start. If not, just go back in with live CD and tweak more.

0

Add a Comment