How can I repair grub? (How to get Ubuntu back after installing Windows?)

Salahuddin

I installed Windows 7, which ate Ubuntu's boot file. When starting up the computer, it now goes straight to Windows, without giving me the option of booting Ubuntu.

How can I get Ubuntu back?

Scott Severance

When you install Windows, Windows assumes it is the only operating system (OS) on the machine, or at least it does not account for Linux. So it replaces GRUB with its own boot loader. What you have to do is replace the Windows boot loader with GRUB. I've seen various instructions for replacing GRUB by mucking around with GRUB commands or some such, but to me the easiest way is to simply chroot into your install and run update-grub. chroot is great because it allows you to work on your actual install, instead of trying to redirect things here and there. It is really clean.

Here's how:

  1. Boot from the live CD or live USB, in "Try Ubuntu" mode.
  2. Determine the partition number of your main partition. sudo fdisk -l, sudo blkid or GParted (which should already be installed, by default, on the live session) can help you here. I'm going to assume in this answer that it's /dev/sda2, but make sure you use the correct partition number for your system!

    If your main partition is in an LVM, the device will instead be located in /dev/mapper/, most likely, /dev/mapper/{volume}--{os}-root where {volume} is the LVM volume name and {os} is the operating system. Execute ls /dev/mapper for the exact name.

  3. Mount your partition:

    sudo mount /dev/sda2 /mnt  #Replace sda2 with the partition from step 2
    

    If you have a separate /boot, /var or /usr partitions, repeat steps 2 and 3 to mount these partitions to /mnt/boot, /mnt/var and /mnt/usr respectively. For example,

    sudo mount /dev/sdXW /mnt/boot
    sudo mount /dev/sdXY /mnt/var
    sudo mount /dev/sdXZ /mnt/usr
    

    replacing sdXW, sdXY, and sdXZ with the respective partition numbers.

  4. Bind mount some other necessary stuff:

    for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    
  5. If Ubuntu is installed in EFI mode (see this answer if you're unsure), use sudo fdisk -l | grep -i efi or GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdXY with the actual partition number for your system:

    sudo mount /dev/sdXY /mnt/boot/efi
    
  6. chroot into your Ubuntu install:

    sudo chroot /mnt
    
  7. At this point, you're in your install, not the live session, and running as root. Update grub:

    update-grub
    

    If you get errors or if going up to step 7 didn't fix your problem, go to step 8. (Otherwise, it is optional.)

  8. Depending on your situation, you might have to reinstall grub:

    grub-install /dev/sda
    update-grub # In order to find and add windows to grub menu.
    
  9. If Ubuntu is installed in EFI mode, and EFI partition UUID has changed, you may need to update it in /etc/fstab. Compare it:

    blkid | grep -i efi
    grep -i efi /etc/fstab
    

    If current EFI partition UUID (from blkid) differs from the one in /etc/fstab, update /etc/fstab with current UUID.

  10. If everything worked without errors, then you're all set:

    exit
    sudo reboot
    
  11. At this point, you should be able to boot normally.

If you cannot boot normally, and didn't do step 8 because there were no error messages, try again with step 8.

  • Sometimes giving GRUB2 the correct configuration for your partitions is not enough, and you must actually install it (or reinstall it) to the Master Boot Record, which step 8 does. Experience helping users in chat has shown that step 8 is sometimes necessary even when no error messages are shown.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

No GRUB after installing Ubuntu beside windows 10

분류에서Dev

How can I repair Windows 10 boot on SSD after formatting old HDD

분류에서Dev

Ubuntu Software Centre is gone! How can I get it back?

분류에서Dev

Cannot boot to Windows after installing Ubuntu and running boot-repair

분류에서Dev

How to fix windows or dell recovery on vostro after installing Ubuntu

분류에서Dev

Can I safely remove grub after installing rEFInd?

분류에서Dev

How can I repair a system with a deleted kernel?

분류에서Dev

How can I repair my PHP installation?

분류에서Dev

Ubuntu 18.04 hangs on boot. How can I get back to login screen?

분류에서Dev

How can I get the old (Win7,8) UAC dialog back in Windows 10 Anniversary Update?

분류에서Dev

How can I remove python 2.7 after installing python 3.3?

분류에서Dev

How can I access the Ubuntu filesystem in Windows?

분류에서Dev

grub is not showing ubuntu after installing redhat 6.0

분류에서Dev

How can I add the Memtest86+ options back to the Grub menu?

분류에서Dev

How to fix my Grub after Windows 10?

분류에서Dev

Recovering Grub after installing windows 8.1

분류에서Dev

How to get Windows data back

분류에서Dev

How to prevent GRUB from appearing after selecting Ubuntu from Windows' Dual Boot menu?

분류에서Dev

Can I delete the .iso file after installing ubuntu?

분류에서Dev

How can I display the grub during boot?

분류에서Dev

How can I repair my hard drive without losing files?

분류에서Dev

How can I repair an external HDD with faulty powering?

분류에서Dev

Can not boot to Ubuntu after installing it

분류에서Dev

After installing Ubuntu how do I know that all devices have their necessary drivers

분류에서Dev

How can I prevent Windows from overwriting GRUB when using a dual-boot machine

분류에서Dev

How can I get grub2 to boot a different option only on the next boot?

분류에서Dev

How can I install Ubuntu and Windows 10 as dual boot?

분류에서Dev

How can I access an Ubuntu RAID device from Windows?

분류에서Dev

How can I install Windows 7 alongside Ubuntu 16.04?

Related 관련 기사

  1. 1

    No GRUB after installing Ubuntu beside windows 10

  2. 2

    How can I repair Windows 10 boot on SSD after formatting old HDD

  3. 3

    Ubuntu Software Centre is gone! How can I get it back?

  4. 4

    Cannot boot to Windows after installing Ubuntu and running boot-repair

  5. 5

    How to fix windows or dell recovery on vostro after installing Ubuntu

  6. 6

    Can I safely remove grub after installing rEFInd?

  7. 7

    How can I repair a system with a deleted kernel?

  8. 8

    How can I repair my PHP installation?

  9. 9

    Ubuntu 18.04 hangs on boot. How can I get back to login screen?

  10. 10

    How can I get the old (Win7,8) UAC dialog back in Windows 10 Anniversary Update?

  11. 11

    How can I remove python 2.7 after installing python 3.3?

  12. 12

    How can I access the Ubuntu filesystem in Windows?

  13. 13

    grub is not showing ubuntu after installing redhat 6.0

  14. 14

    How can I add the Memtest86+ options back to the Grub menu?

  15. 15

    How to fix my Grub after Windows 10?

  16. 16

    Recovering Grub after installing windows 8.1

  17. 17

    How to get Windows data back

  18. 18

    How to prevent GRUB from appearing after selecting Ubuntu from Windows' Dual Boot menu?

  19. 19

    Can I delete the .iso file after installing ubuntu?

  20. 20

    How can I display the grub during boot?

  21. 21

    How can I repair my hard drive without losing files?

  22. 22

    How can I repair an external HDD with faulty powering?

  23. 23

    Can not boot to Ubuntu after installing it

  24. 24

    After installing Ubuntu how do I know that all devices have their necessary drivers

  25. 25

    How can I prevent Windows from overwriting GRUB when using a dual-boot machine

  26. 26

    How can I get grub2 to boot a different option only on the next boot?

  27. 27

    How can I install Ubuntu and Windows 10 as dual boot?

  28. 28

    How can I access an Ubuntu RAID device from Windows?

  29. 29

    How can I install Windows 7 alongside Ubuntu 16.04?

뜨겁다태그

보관