Difference between revisions of "Restore the GRUB Bootloader"

From Manjaro Linux
Jump to: navigation, search
(For UEFI Systems)
m (Overview: reform)
 
(30 intermediate revisions by 7 users not shown)
Line 1: Line 1:
= Overview =
+
__TOC__
  
As with any Linux operating system, the GRUB ('''GR'''and '''U'''nified '''B'''ootloader) is responsible for booting up Manjaro. If for any reason your GRUB is not working - perhaps due to being corrupted, mis-configured, or even deleted - then it may not be necessary to reinstall Manjaro as a consequence. '''The GRUB can instead be fully repaired and restored, retaining your installed Manjaro system'''. To undertake this task, you will need to use your Manjaro installation media (e.g. CD/DVD or USB Flashdrive).
 
  
 +
= Overview =
 +
 +
In order to boot Manjaro, a Linux-capable boot loader such as GRUB, rEFInd or Syslinux needs to be installed to the Master Boot Record (MBR) or the GUID Partition Table (GPT) of the media containing the Operating System. The boot loader used on official Manjaro installations and generaly suggested is GRUB. Sometimes the MBR or GPT gets corrupted, erased or misconfigured for various reasons resulting to a black screen with a failure message during boot, like '''No boot loaders found in /dev/...'''. Fortunatelly, there is a way to restore GRUB without re-installing your OS or losing your data. For this, you will need to use your Manjaro installation media, such as, a CD/DVD or USB Flashdrive.
 +
{{tip|More information about the boot process on Archlinux based distributions is available at [https://wiki.archlinux.org/index.php/Arch_boot_process Archwiki]}}
  
 
= Boot the Manjaro Installation Media =
 
= Boot the Manjaro Installation Media =
Line 17: Line 20:
 
'''4.''' Open the terminal or access the command line of the live CD.  
 
'''4.''' Open the terminal or access the command line of the live CD.  
  
* '''From the desktop environment''': open the terminal from your desktop menu, or
+
* '''From the desktop environment''': open a terminal from your desktop menu, and enter ''sudo su'' in the terminal.
* '''From the command line''' (e.g. NET-Edition or having used the ''Boot in Text mode'' option): enter the default username (manjaro) and password (manjaro) to log in.
+
  
 +
or
  
= Identify and Prepare the Installed Partition(s) =
+
* '''From the command line''' of the Manjaro Architect Edition or having used option '''5. System Rescue''' : enter the default login username ''root'' and then the password "manjaro" to log in.
{{tip|'''If you had installed Manjaro using the ''assisted preparation'' method''' - whereby the installer automatically prepared and partitioned your computer's hard disk for you - then you will have the same four partitions as those listed by the author, below. This will include a separate Boot partition, named ''/dev/sda1''.}}
+
  
 +
=Chroot into your existing Manjaro Installation=
 +
 +
{{note| Look here to read more about [https://wiki.archlinux.org/index.php/Change_Root chroot](ing).}}
 +
 +
There are 2 different ways to chroot into your exising Manjaro installation: Using mhwd-chroot or doing it manually. Please choose one:
 +
 +
 +
==Use mhwd-chroot==
 +
 +
'''1.''' Start by identifying the partition where your Manjaro installation controling the active Grub menu resides and needs repairing. If you are in Graphical mode you can use an application called ''GPartEd'', which should be in Menu > System > GPartEd. This will provide a simple visual illustration of the partitions on your hard drive(s).
 +
 +
To do the same thing from terminal or TTY you can use this command
 +
 +
lsblk -f
 +
 +
 +
'''2.''' [https://github.com/manjaro/manjaro-tools mhwd-chroot] is a tool to easily chroot into an installed Linux installation from a live boot of a Manjaro Installation Media.
 +
{{tip|If it is not installed in your live media you can install it in terminal with
 +
 +
 +
sudo pacman -S mhwd-chroot }}
 +
 +
Start mhwd-chroot from your Start Menu (System -> Chroot) or in your terminal with:
 +
 +
sudo mhwd-chroot
 +
 +
You will be presented with a terminal. Wait until it shows a list with the available system partitions on your computer and choose the one you want to repair.
 +
 +
== Manually Identify and Prepare the Installed Partition(s) ==
  
 
'''1.''' Ensure that you are using the Root account, which is identified by a hash ('#') at the beginning of the command line, rather than a dollar ('$'). To switch to Root, enter the command:
 
'''1.''' Ensure that you are using the Root account, which is identified by a hash ('#') at the beginning of the command line, rather than a dollar ('$'). To switch to Root, enter the command:
Line 32: Line 63:
 
'''2.''' List your partitions. This is necessary in order to identify the partition your Manjaro system is installed on. If you have used a separate boot partition, it will be necessary to identify this as well. For a list of your paritions, enter the command:
 
'''2.''' List your partitions. This is necessary in order to identify the partition your Manjaro system is installed on. If you have used a separate boot partition, it will be necessary to identify this as well. For a list of your paritions, enter the command:
  
  sudo blkid
+
lsblk -f
 +
 
 +
  or
 +
 
 +
  sudo blkid -o list -c /dev/nul
  
  
Line 43: Line 78:
  
  
If you are still unsure, then you can also use an application called ''gparted'', which should be selectable from your desktop menu. This will provide a simple visual illustration of the partitions on your hard drive(s). If a seperate partition for the GRUB exists, it will be marked as 'bootable', and should only be about 100MB in size.
+
If you are still unsure, then you can also use an application called ''gparted'', which should be in Menu > System > GPartEd. This will provide a simple visual illustration of the partitions on your hard drive(s). If a separate partition for the GRUB exists, it will be marked as 'bootable', and should only be about 100MB in size.
  
  
Line 56: Line 91:
  
  
'''IF''' you have used a seperate partition for your GRUB bootloader, then this must also be mounted. The syntax to mount a separate partition used to boot is:
+
'''IF''' you have used a separate partition for your GRUB bootloader, then this must also be mounted. The syntax to mount a separate partition used to boot is:
  
 
  mount /dev/'''[partition used for GRUB]''' /mnt/boot
 
  mount /dev/'''[partition used for GRUB]''' /mnt/boot
  
  
In this instance, a seperate partition - ''/dev/sda1'' - has been used for the GRUB, and will be mounted using the following command:
+
In this instance, a separate partition --''/dev/sda1''-- has been used for the GRUB, and will be mounted using the following command:
  
 
  mount /dev/'''sda1''' /mnt/boot
 
  mount /dev/'''sda1''' /mnt/boot
  
{{note|Again, if you have not used a seperate boot partition, then it (obviously) does not need to be mounted!}}
+
{{note|Again, if you have not used a separate boot partition, then it (obviously) does not need to be mounted!}}
  
  
'''3.''' Change to the root directory of your mounted partitions. This is undertaken so that you are working from  - and with - your installed system, rather than the installation media. To do so, it will be necessary to enter a series of commands in the following order:
+
'''4.''' Change to the root directory of your mounted partitions.  
 +
 
 +
cd /mnt
 +
 
 +
This is undertaken so that you are working from  --and with-- your installed system, rather than the installation media. To do so, it will be necessary to enter a series of commands in the following order:
  
 
  mount -t proc proc /mnt/proc
 
  mount -t proc proc /mnt/proc
Line 77: Line 116:
  
  
'''4.''' Install the software applications ''mtools'' and ''os-prober''. mtools is a collection of tools to access Microsoft Operating Systems (i.e. MS-DOS). os-prober is a utility that detects if there are any other operating systems present. Install them with the following command:
+
= Restore GRUB =
  
pacman -S mtools os-prober
+
First, install the software applications ''mtools'' and ''os-prober''. mtools is a collection of tools to access MS-DOS disks from GNU/Linux and Unix without mounting them. os-prober is a utility that detects if there are any other operating systems present. Install them both with the following command:
  
 +
sudo pacman -S mtools os-prober
  
= Restore GRUB =
 
  
 
== For BIOS Systems ==
 
== For BIOS Systems ==
Line 89: Line 128:
  
 
  grub-install /dev/sda
 
  grub-install /dev/sda
 +
{{Note|sda is the disk device where you want to install GRUB. You can check it using ''lsblk -f'' or using GParted as explained before.}}
  
  
Line 105: Line 145:
  
 
== For UEFI Systems ==
 
== For UEFI Systems ==
 +
 +
{{Warning|You need to be [https://wiki.archlinux.org/index.php/Change_Root chrooted] for this procedure as mentioned in the [[Restore_the_GRUB_Bootloader#Identify_and_Prepare_the_Installed_Partition.28s.29 | previous step.]]}}
 +
  
 
1.) First of all check the partition for the ESP (EFI System Partition). An ESP is a fat32 partition and contains .efi files for booting.
 
1.) First of all check the partition for the ESP (EFI System Partition). An ESP is a fat32 partition and contains .efi files for booting.
Line 111: Line 154:
  
  
''If you do not have a EFI partition'', '''you will need to create it'''.
+
('''Note:'''
 +
''If you do not have a EFI partition'', you will need to create it.
 
Use Gparted for that.
 
Use Gparted for that.
  
Type- '''fat32'''
+
Type- ''fat32''
  
Size- '''512 mb to 1 gb'''
+
Size- ''512 mb to 1 gb'')
  
  
Line 133: Line 177:
 
4.) Re-install Grub.
 
4.) Re-install Grub.
 
  sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
 
  sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
 +
  
 
5.) Update Grub configuration file.
 
5.) Update Grub configuration file.
Line 143: Line 188:
 
  EFI variables are not supported on this system.
 
  EFI variables are not supported on this system.
  
Then install the following packages and try steps 4 and 5 again.
+
Then install the {{ic|efibootmgr}}, {{ic|dosfstools}} and {{ic|grub}} packages and try steps 4 and 5 again.
  
1. efibootmgr
+
If it still doesn't work, then try exiting the chroot environnment by typing '''exit''', then loading the '''efivarfs''' module:
2. dosfstools
+
  sudo modprobe efivarfs
  3. grub
+
  
 +
and in the chroot
 +
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
  
 +
 +
And if you get something like
 +
 +
grub-install: error: failed to get canonical path of `union'.
 +
 +
means that probably you forgot to [[Restore_the_GRUB_Bootloader#Identify_and_Prepare_the_Installed_Partition.28s.29 | chroot]].
  
 
'''See also'''
 
'''See also'''
 +
 
[http://wiki.manjaro.org/index.php?title=UEFI_-_Install_Guide UEFI Install Guide]
 
[http://wiki.manjaro.org/index.php?title=UEFI_-_Install_Guide UEFI Install Guide]
  
[https://wiki.archlinux.org/index.php/GRUB#UEFI_systems_2 Arch Wiki]
+
[https://wiki.archlinux.org/index.php/GRUB#UEFI_systems_2 Arch Wiki:GRUB#UEFI_systems_2]
  
=Support=
+
=== Alternative method ===
  
 +
Mount the ext4 Manjaro root partition at {{ic|/install}}
  
Post for support at the forums- [http://forum.manjaro.org/index.php?board=3.0]
+
Mount the vfat Manjaro efi partition at {{ic|/install/boot/efi}}
  
=See Also=
+
And then install Grub as:
  
 +
grub-install --target=x86_64-efi --efi-directory=/install/boot/efi --bootloader-id=manjaro --boot-directory=/install/boot --recheck --debug
  
[https://wiki.archlinux.org/index.php/GRUB The Arch Wiki]
+
After the above you could chroot and try the '''update-grub''' command as earlier.
  
 
[[Category:Contents Page]]
 
  
 
= Troubleshooting =
 
= Troubleshooting =
Line 175: Line 228:
  
  
= See also =
+
=More=
  
[https://wiki.archlinux.org/index.php/GRUB GRUB: Arch Wiki]
+
[https://forum.manjaro.org/index.php?topic=7552.0 Forum topic]
 +
 
 +
[https://wiki.archlinux.org/index.php/GRUB The Arch Wiki]
 +
 
 +
Post for support at the [http://forum.manjaro.org/index.php?board=3.0 forums]
 +
 
 +
 
 +
[[Category:Contents Page]]
  
  
 
[[Category:Contents Page]]
 
[[Category:Contents Page]]

Latest revision as of 23:32, 8 March 2018


Overview

In order to boot Manjaro, a Linux-capable boot loader such as GRUB, rEFInd or Syslinux needs to be installed to the Master Boot Record (MBR) or the GUID Partition Table (GPT) of the media containing the Operating System. The boot loader used on official Manjaro installations and generaly suggested is GRUB. Sometimes the MBR or GPT gets corrupted, erased or misconfigured for various reasons resulting to a black screen with a failure message during boot, like No boot loaders found in /dev/.... Fortunatelly, there is a way to restore GRUB without re-installing your OS or losing your data. For this, you will need to use your Manjaro installation media, such as, a CD/DVD or USB Flashdrive.

Tip: More information about the boot process on Archlinux based distributions is available at Archwiki

Boot the Manjaro Installation Media

1. Insert and boot your Manjaro installation media.

2. Select your preferred language (F2) and keyboard layout (F3).

Tip: Setting the language and keyboard layout are undertaken by pressing the Function (F) keys. As many computers have multiple functions assigned to each function key, it may be necessary to hold down another key first to use them. For example, on a HP G62 laptop, to use the function keys, the 'fn' key must first be pressed and held.


3. Boot Manjaro Linux. It does not matter which boot option you choose, as the installation media is being used solely to repair/reinstate the GRUB, and not to install a fresh system.

4. Open the terminal or access the command line of the live CD.

  • From the desktop environment: open a terminal from your desktop menu, and enter sudo su in the terminal.

or

  • From the command line of the Manjaro Architect Edition or having used option 5. System Rescue : enter the default login username root and then the password "manjaro" to log in.

Chroot into your existing Manjaro Installation

note: Look here to read more about chroot(ing).

There are 2 different ways to chroot into your exising Manjaro installation: Using mhwd-chroot or doing it manually. Please choose one:


Use mhwd-chroot

1. Start by identifying the partition where your Manjaro installation controling the active Grub menu resides and needs repairing. If you are in Graphical mode you can use an application called GPartEd, which should be in Menu > System > GPartEd. This will provide a simple visual illustration of the partitions on your hard drive(s).

To do the same thing from terminal or TTY you can use this command

lsblk -f


2. mhwd-chroot is a tool to easily chroot into an installed Linux installation from a live boot of a Manjaro Installation Media.

Tip: If it is not installed in your live media you can install it in terminal with


sudo pacman -S mhwd-chroot

Start mhwd-chroot from your Start Menu (System -> Chroot) or in your terminal with:

sudo mhwd-chroot

You will be presented with a terminal. Wait until it shows a list with the available system partitions on your computer and choose the one you want to repair.

Manually Identify and Prepare the Installed Partition(s)

1. Ensure that you are using the Root account, which is identified by a hash ('#') at the beginning of the command line, rather than a dollar ('$'). To switch to Root, enter the command:

sudo su


2. List your partitions. This is necessary in order to identify the partition your Manjaro system is installed on. If you have used a separate boot partition, it will be necessary to identify this as well. For a list of your paritions, enter the command:

lsblk -f
  or
sudo blkid -o list -c /dev/nul


In this particular instance, having used the assisted preparation method to install Manjaro earlier, the partitions for the author's Manjaro system are as follows:

  • /dev/sda1: Boot partition
  • /dev/sda2: Swap partition
  • /dev/sda3: Manjaro system
  • /dev/sda4: Space for personal files.


If you are still unsure, then you can also use an application called gparted, which should be in Menu > System > GPartEd. This will provide a simple visual illustration of the partitions on your hard drive(s). If a separate partition for the GRUB exists, it will be marked as 'bootable', and should only be about 100MB in size.


3. Mount your Manjaro system partition. The syntax to mount the Manjaro system partition is:

mount /dev/[partition used for Manjaro system] /mnt


In this instance, as the Manjaro system partition is /dev/sda3, this will be mounted using the following command:

mount /dev/sda3 /mnt


IF you have used a separate partition for your GRUB bootloader, then this must also be mounted. The syntax to mount a separate partition used to boot is:

mount /dev/[partition used for GRUB] /mnt/boot


In this instance, a separate partition --/dev/sda1-- has been used for the GRUB, and will be mounted using the following command:

mount /dev/sda1 /mnt/boot
note: Again, if you have not used a separate boot partition, then it (obviously) does not need to be mounted!


4. Change to the root directory of your mounted partitions.

cd /mnt

This is undertaken so that you are working from --and with-- your installed system, rather than the installation media. To do so, it will be necessary to enter a series of commands in the following order:

mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev
mount -t devpts pts /mnt/dev/pts/
chroot /mnt


Restore GRUB

First, install the software applications mtools and os-prober. mtools is a collection of tools to access MS-DOS disks from GNU/Linux and Unix without mounting them. os-prober is a utility that detects if there are any other operating systems present. Install them both with the following command:

sudo pacman -S mtools os-prober


For BIOS Systems

1. Install a new GRUB bootloader with the following command:

grub-install /dev/sda
note: sda is the disk device where you want to install GRUB. You can check it using lsblk -f or using GParted as explained before.


2. Recheck to ensure the that installation has completed without any errors:

grub-install --recheck /dev/sda


3. Finally, configure the freshly installed GRUB bootloader:

update-grub


All done! Now close the terminal and reboot your system to use your freshly re-installed GRUB.


For UEFI Systems

Warning: You need to be chrooted for this procedure as mentioned in the previous step.


1.) First of all check the partition for the ESP (EFI System Partition). An ESP is a fat32 partition and contains .efi files for booting.

It can be checked using Gparted or from the terminal using fdisk -l


(Note: If you do not have a EFI partition, you will need to create it. Use Gparted for that.

Type- fat32

Size- 512 mb to 1 gb)


2.) Create the /boot/efi directory

sudo mkdir /boot/efi


3.) Mount the EFI partition as /boot/efi

sudo mount /dev/sdXY /boot/efi

X = Alphabet of the drive = a,b,c ... Y = Partition number of the EFI partition = 1,2,3,4...

Example - /dev/sda4


4.) Re-install Grub.

sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck


5.) Update Grub configuration file.

sudo update-grub

Note

If you get something like

EFI variables are not supported on this system.

Then install the efibootmgr, dosfstools and grub packages and try steps 4 and 5 again.

If it still doesn't work, then try exiting the chroot environnment by typing exit, then loading the efivarfs module:

sudo modprobe efivarfs

and in the chroot

mount -t efivarfs efivarfs /sys/firmware/efi/efivars


And if you get something like

grub-install: error: failed to get canonical path of `union'.

means that probably you forgot to chroot.

See also

UEFI Install Guide

Arch Wiki:GRUB#UEFI_systems_2

Alternative method

Mount the ext4 Manjaro root partition at /install

Mount the vfat Manjaro efi partition at /install/boot/efi

And then install Grub as:

grub-install --target=x86_64-efi --efi-directory=/install/boot/efi --bootloader-id=manjaro --boot-directory=/install/boot --recheck --debug

After the above you could chroot and try the update-grub command as earlier.


Troubleshooting

Arch Linux is not recognized

If Arch Linux wasn't recognized after an update-grub then probably your Arch installation is missing the package lsb-release.


More

Forum topic

The Arch Wiki

Post for support at the forums