fix PC boot problem

Fix whatever boot failure (dual boot)

fix grub or dual boot for linux and windows

Probelms

I first install Ubuntu on the secondary SSD(sdb) with /boot on the first SSD(sda)

Then I manually format /sda and wipe out everything

Next I installed a Windows 10 and it worked fine. But I can’t get into Ubuntu. Even with grub rescue, for some reason I can’t explain (it could boot but get stuck in the middle).

When running in LiveCD

sudo grub-install

I got this error

/usr/sbin/grub-probe:error:failed to get canonical path of /cow.

Solution

So here is the trick to purge the old grub in Ubuntu from LiveCD(flash drive) by chroot.

Note: If you could get into your Ubuntu, don’t bother use LiveCD, just jump to the purge step, step 4.

Note: reinstall grub require Internet, you need to get LiveCD connected to Internet before proceed. If you don’t have access to Internet, Ref 1 gives solution to install grub without Internet, I didn’t try it though.

Note: chroot stands for change root. It pretend the path you changing to to be the toot /. So if you change root to another Ubuntu system, it allows you to get access to that Ubuntu and act as if you are running on it.


Main Idea

  1. boot into LiveCD and select Try Ubuntu without install
  2. setup the envirnment for chroot
  3. run chroot command on local Ubuntu(the one on the hard drive that you can’t boot into).
  4. purge and reinstall gurb
  5. reboot and select grub as bootable in BIOS.
  6. successfully go into grub

1. boot into LiveCD and select Try Ubuntu without install

Create a bootable usb of ubuntu.
It must be the same platform with your local one, x86 or x64

2. setup the envirnment for chroot

to see what hard drive you have lsblk

Partitions are in the form of sdXY.
X are a, b, c…, stands for different hard drive and
Y are 1, 2, 3… stands for the partitions on the hard drive.

sda3 is the thrid partiton of the first hard drive

  • mount you partition where your local Ubuntu is

      sudo mount /dev/sdb1 /mnt/chrootdir 
      # change sdb1 accordingly, where your Ubuntu root / is
    
  • (optional) mount boot partition only if you have a seprate boot partition Ref 1

    sudo mount /dev/sda1 /mnt/chrootdir/boot 
    # change sda1 accordingly, where your boot partition is
    
  • get the Internet setting to solve the domain names Ref 2

    cp -L /etc/resolv.conf /mnt/etc/resolv.conf
    
  • Bind necessary directory

    for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do
        mount --bind /$dir /mnt/chrootdir/$dir
    done
    

3. run chroot command on local Ubuntu

  • change root to /mnt/chrootdir

    chroot /mnt/chrootdir
    
  • confirm Internet connection

    apt-get update
    

    if your Internet didn’t connected DO NOT proceed, exit and use the method without Internet

4. purge and reinstall gurb

  • purge everything about grub

    apt-get purge grub grub-pc grub-common
    
  • reinstall grub

    apt-get install grub-common grub-pc
    

grub install Note

  • You will be given the opportunity to add extra kernel options to the kernel line. If you don’t know, you probably don’t need them ; TAB to highlight “OK” and press ENTER.

  • Read the installation notes. TAB to “OK” to continue. When presented with the device option, use the UP/DN keys to select the correct drive (sdX).

  • Make sure the installation drive [ ] /dev/sdX has an asterisk next to it. If it doesn’t, highlight it and press the SPACE bar to select it.

  • Do not select a partition ( example: [ ] /dev/sda5 , etc).
    TAB to “OK” and press ENTER. When it has finishing the installation, you should have Grub 2 installed.

Ref 1

5. reboot and select grub as bootable in BIOS.

  • unmount directory first

      for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do
          umount /mnt/chrootdir/$dir
      done
      umount /mnt/chrootdir
    
      reboot
    

There are strange BIOS like mine, let you select which bootalbe to go to. Go into BIOS and select hard drive boot option and select the one contain words: grub, Ubuntu.

6. successfully go into grub

grub would recognize what ever operating systems you installed.

And life is good again.

Reference

1 HOWTO: Purge and Reinstall Grub 2 from the Live CD

2 What’s the proper way to prepare chroot to recover a broken Linux installation?

3 Failed to get canonical path of /cow

ENVIRONMENT
boot grub dual boot chroot

Dialogue & Discussion