Manjaro Difference between revisions of "GRUB/Restore the GRUB Bootloader"

Difference between revisions of "GRUB/Restore the GRUB Bootloader"

From Manjaro
imported>Fhdk
(modified disk/partition references to non-existing to avoid copy-paste issues)
(general reformatting and proofreading)
Line 1: Line 1:
__TOC__
__TOC__
==Overview==
In order to load the operating system, 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. Installations created using Manjaro ISO is GRUB.


For various reasons - it happens the bootloader get's corrupted, erased or misconfigured resulting to a black screen with a failure message during boot, like '''No boot loaders found in /dev/...'''. To restore system operation without re-installing your OS or losing your data you will need to use your Manjaro installation media, such as, a CD/DVD or USB Flashdrive.
{{BoxSecondary|Archlinux Boot Process|More information about the boot process on Archlinux based distributions is available at [https://wiki.archlinux.org/index.php/Arch_boot_process Archwiki]}}


= Overview =
==Preparation==
Identify the type of system you are attempted to resque as the commands involved are slightly different.
* BIOS/MBR system
* BIOS/GPT system
* EFI/GPT system


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.
==Load Manjaro Installation Media==
{{tip|More information about the boot process on Archlinux based distributions is available at [https://wiki.archlinux.org/index.php/Arch_boot_process Archwiki]}}
{{BoxSecondary|System Boot Override|To override sytem boot order the vendor has a dedicated key. Most laptop keyboard has multiple use for the function keys and the primary function may be reversed. In such case a <kbd>Fn</kbd> key must be used with the function key. If you don't know consult your system documentation. Manjaro ISO default usernames and passwords
<table>
<tr><th>Default Username</th><th>Default Password</th></tr>
<tr><td>manjaro</td><td>manjaro</td></tr>
<tr><td>root</td><td>manjaro</td></tr>
</table>
}}


= Boot the Manjaro Installation Media =
==Identify partitions==
To identify your partitions and their designated use you need to run a partition manager. Depending on environment there is various tools. GTK based ISO offers GpartEd, QT based ISO offers KParted and common to all is the CLI tools.
{{UserCmd|command=lsblk -o PATH,NAME,PTTYPE,FSTYPE}}
More comprehensive information can be found using {{ic|fdisk}} (requires superuser) and you can limit the probed device e.g. ''/dev/sda'' or ''/dev/nvme0n1''
{{UserCmd|command=sudo fdisk -l /dev/sda}}
The clues to look for is ''mbr'' vs. ''gpt'' and the presence of a small partition - usually the first - formatted with the ''vfat'' filesystem followed by a larger partition formatted as ''ext4''.


'''1.''' Insert and boot your Manjaro installation media.  
{{Important|This document and the content should '''never''' be used as a copy/paste resource. The remainder of this document will use pseudo names and partition numbering. Devices will be referred as '''/dev/sdy''' and partitions referred as '''/dev/sdyA''' and you will have to subtitute those with the real values from your system.}}
==Use root context==
When you have loaded the live ISO - depending on environment - open a terminal and switch to ''root''' context. Use above mentioned root:password combination.
{{UserCmd|command=su}}
==Chroot environment==
Chroot is a method to restrict various tasks to a restricted area e.g. package installation and other system maintenance tasks.
{{BoxSecondary|More on chroot|Look here to read more about [https://wiki.archlinux.org/index.php/Change_Root chroot]}}
===Identify system partitions===
From the above we assume you have identified the relevant partitions on your system and this document will refer the partitions as follows. Partitions not needed for this kind of maintenance as intentionally beenleft out (''/home'', ''/swap'').
{|
|-
! Partition !! Usage !! Comment
|-
| {{ic|/dev/sdyA}} || EFI system || Required for EFI system and mounted on ''/boot/efi''
|-
| {{ic|/dev/sdyB}} || boot || Optional but mounted on ''/boot'' The primary use is when GRUB cannot write to ''/'' (eg. ''f2fs'')
|-
| {{ic|/dev/sdyC}} || root || Required and for the root filesystem and mounted on ''/'' - usually formatted using ''ext4''
|}
{{Important|If your system is a BIOS/MBR system there is no efi partition. If your system is a BIOS/GPT system you will find an unformatted partion size 1-32MB of the bios boot partition type.}}
===Manual chroot===
Mount the partitions using the designated temporary mountpoint and '''always''' start with ''root''
{{RootCmd|command=mount /dev/sdyC /mnt}}
Then - if applicable - mount ''boot''
{{RootCmd|command=mount /dev/sdyB /mnt/boot}}
Then - if applicable - mount ''efi''
{{RootCmd|command=mount /dev/sdyY /mnt/boot/efi}}
Create the chroot environment and use bash as shell
{{RootCmd|command=manjaro-chroot /mnt /bin/bash}}
===Use manjaro-chroot===
Manjaro deploys a script called {{ic|manjaro-chroot}} takes an optional argument which will search the visible devices - scan the partitions for signs of an operating system. If more than one Linux operating system is found you will get a choice of which system to chroot otherwise the file ''/etc/fstab'' from the system is used to mount the partitions and chroot into this system.
{{RootCmd|command=manjaro-chroot -a}}
==Reinstall GRUB==
One possible cause why you are reading this document - is an unfinished update - which in turn can be caused by several situations - situation we will not dive into. To fix what ever caused this you should run a full system update including grub to ensure everything is in place.
{{RootCmd|command=pacman -Syu grub}}
When the transaction as completed continue below using the section matching your system
===BIOS System===
On a BIOS/GPT system there is no MBR and therefore no place to store the loader. The GPT partition specification allows for an unformatted partition of the BIOS boot partition type (0xEF02). The size of this partition can be as small as 1 mebibyte. The Calamares installer uses a fixed size of 32 mebibyte. On a BIOS/MBR system a part of the bootloader is written to the Master Boot Record for the primary disk.


'''2.''' Select your '''preferred language''' (F2) and '''keyboard layout''' (F3).
The device is the '''disk''' ('''not a partition''')
{{RootCmd|command=grub-install --force --target=i386-pc --recheck --boot-directory=/boot /dev/sdy}}
Make sure the grub configuration is up-to-date
{{RootCmd|command=grub-mkconfig -o /boot/grub/grub.cfg}}


{{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.}}
===EFI System===
{{Important|You need to be in chroot for this procedure.}}
Reinstall grub
{{RootCmd|command=grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck}}
Update the grub configuration
{{RootCmd|command=grub-mkconfig -o /boot/grub/grub.cfg}}


{{BoxWarning|EFI grub install messages|EFI variables are not supported on this system.}}
Verify the existance of an EFI system partition
{{RootCmd|command=lsblk -o PATH,PTTYPE,PARTTYPE,FSTYPE,PARTTYPENAME}}
Verify the efi filesystem is loaded
{{RootCmd|command=ls /sys/firmware/efi}}
Exit chroot
{{RootCmd|command=exit}}
Try loading the efi filesystem
{{RootCmd|command=modprobe efivarfs}}
Re-enter chroot
{{RootCmd|command=manjaro-chroot /mnt /bin/bash}}
Then mount the efi filesystem
{{RootCmd|command=mount -t efivarfs efivarfs /sys/firmware/efi/efivars}}
Verify the efi filesystem is loaded
{{RootCmd|command=ls /sys/firmware/efi}}
If successfull re-run above installation commands


'''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.
==Troubleshooting==
 
'''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 [https://wiki.archlinux.org/index.php/Change_Root chroot](ing).}}
 
There are 2 different ways to chroot into your exising Manjaro installation: Using manjaro-chroot or doing it manually. Please choose one:
 
 
==Use manjaro-chroot==
 
'''1.''' Start by identifying the partition where your Manjaro installation controlling 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.''' manjaro-chroot is a tool to easily setup a functional chroot into an installed Linux installation from a live boot of a Manjaro Installation Media.
 
To setup the chroot use the command
sudo manjaro-chroot -a
 
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 ('''Example only''' modify to match your system):
 
* '''/dev/sdy1''': Boot partition
* '''/dev/sdy2''': Swap partition
* '''/dev/sdy3''': Manjaro system
* '''/dev/sdy4''': 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/'''sdy3''' /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/sdy1''-- has been used for the GRUB, and will be mounted using the following command:
 
mount /dev/'''sdy1''' /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 ('''Modify to match your system''')
 
grub-install /dev/sdy
{{Note|sdy 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/sdy
 
 
'''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 [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.
 
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 {{ic|efibootmgr}}, {{ic|dosfstools}} and {{ic|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 [[Restore_the_GRUB_Bootloader#Identify_and_Prepare_the_Installed_Partition.28s.29 | chroot]].
 
'''See also'''
 
[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:GRUB#UEFI_systems_2]
 
=== Alternative method ===
 
Mount the ext4 Manjaro root partition at {{ic|/install}}
 
Mount the vfat Manjaro efi partition at {{ic|/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 ===
=== 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.
If Arch Linux wasn't recognized after an update-grub then probably your Arch installation is missing the package lsb-release.


 
==See also==
=More=
* [http://wiki.manjaro.org/index.php?title=UEFI_-_Install_Guide UEFI Install Guide]
 
* [https://wiki.archlinux.org/index.php/GRUB GRUB on 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]]

Revision as of 16:07, 3 October 2020

Overview

In order to load the operating system, 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. Installations created using Manjaro ISO is GRUB.

For various reasons - it happens the bootloader get's corrupted, erased or misconfigured resulting to a black screen with a failure message during boot, like No boot loaders found in /dev/.... To restore system operation without re-installing your OS or losing your data you will need to use your Manjaro installation media, such as, a CD/DVD or USB Flashdrive.

Archlinux Boot Process
More information about the boot process on Archlinux based distributions is available at Archwiki

Preparation

Identify the type of system you are attempted to resque as the commands involved are slightly different.

  • BIOS/MBR system
  • BIOS/GPT system
  • EFI/GPT system

Load Manjaro Installation Media

System Boot Override
To override sytem boot order the vendor has a dedicated key. Most laptop keyboard has multiple use for the function keys and the primary function may be reversed. In such case a Fn key must be used with the function key. If you don't know consult your system documentation. Manjaro ISO default usernames and passwords
Default UsernameDefault Password
manjaromanjaro
rootmanjaro

Identify partitions

To identify your partitions and their designated use you need to run a partition manager. Depending on environment there is various tools. GTK based ISO offers GpartEd, QT based ISO offers KParted and common to all is the CLI tools.

user $ lsblk -o PATH,NAME,PTTYPE,FSTYPE COPY TO CLIPBOARD


More comprehensive information can be found using fdisk (requires superuser) and you can limit the probed device e.g. /dev/sda or /dev/nvme0n1

user $ sudo fdisk -l /dev/sda COPY TO CLIPBOARD


The clues to look for is mbr vs. gpt and the presence of a small partition - usually the first - formatted with the vfat filesystem followed by a larger partition formatted as ext4.


Info
This document and the content should never be used as a copy/paste resource. The remainder of this document will use pseudo names and partition numbering. Devices will be referred as /dev/sdy and partitions referred as /dev/sdyA and you will have to subtitute those with the real values from your system.


Use root context

When you have loaded the live ISO - depending on environment - open a terminal and switch to root' context. Use above mentioned root:password combination.

user $ su COPY TO CLIPBOARD


Chroot environment

Chroot is a method to restrict various tasks to a restricted area e.g. package installation and other system maintenance tasks.

More on chroot
Look here to read more about chroot

Identify system partitions

From the above we assume you have identified the relevant partitions on your system and this document will refer the partitions as follows. Partitions not needed for this kind of maintenance as intentionally beenleft out (/home, /swap).

Partition Usage Comment
/dev/sdyA EFI system Required for EFI system and mounted on /boot/efi
/dev/sdyB boot Optional but mounted on /boot The primary use is when GRUB cannot write to / (eg. f2fs)
/dev/sdyC root Required and for the root filesystem and mounted on / - usually formatted using ext4
Info
If your system is a BIOS/MBR system there is no efi partition. If your system is a BIOS/GPT system you will find an unformatted partion size 1-32MB of the bios boot partition type.


Manual chroot

Mount the partitions using the designated temporary mountpoint and always start with root

root # mount /dev/sdyC /mnt COPY TO CLIPBOARD


Then - if applicable - mount boot

root # mount /dev/sdyB /mnt/boot COPY TO CLIPBOARD


Then - if applicable - mount efi

root # mount /dev/sdyY /mnt/boot/efi COPY TO CLIPBOARD


Create the chroot environment and use bash as shell

root # manjaro-chroot /mnt /bin/bash COPY TO CLIPBOARD


Use manjaro-chroot

Manjaro deploys a script called manjaro-chroot takes an optional argument which will search the visible devices - scan the partitions for signs of an operating system. If more than one Linux operating system is found you will get a choice of which system to chroot otherwise the file /etc/fstab from the system is used to mount the partitions and chroot into this system.

root # manjaro-chroot -a COPY TO CLIPBOARD


Reinstall GRUB

One possible cause why you are reading this document - is an unfinished update - which in turn can be caused by several situations - situation we will not dive into. To fix what ever caused this you should run a full system update including grub to ensure everything is in place.

root # pacman -Syu grub COPY TO CLIPBOARD


When the transaction as completed continue below using the section matching your system

BIOS System

On a BIOS/GPT system there is no MBR and therefore no place to store the loader. The GPT partition specification allows for an unformatted partition of the BIOS boot partition type (0xEF02). The size of this partition can be as small as 1 mebibyte. The Calamares installer uses a fixed size of 32 mebibyte. On a BIOS/MBR system a part of the bootloader is written to the Master Boot Record for the primary disk.

The device is the disk (not a partition)

root # grub-install --force --target=i386-pc --recheck --boot-directory=/boot /dev/sdy COPY TO CLIPBOARD


Make sure the grub configuration is up-to-date

root # grub-mkconfig -o /boot/grub/grub.cfg COPY TO CLIPBOARD


EFI System

Info
You need to be in chroot for this procedure.


Reinstall grub

root # grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck COPY TO CLIPBOARD


Update the grub configuration

root # grub-mkconfig -o /boot/grub/grub.cfg COPY TO CLIPBOARD



EFI grub install messages
EFI variables are not supported on this system.

Verify the existance of an EFI system partition

root # lsblk -o PATH,PTTYPE,PARTTYPE,FSTYPE,PARTTYPENAME COPY TO CLIPBOARD


Verify the efi filesystem is loaded

root # ls /sys/firmware/efi COPY TO CLIPBOARD


Exit chroot

root # exit COPY TO CLIPBOARD


Try loading the efi filesystem

root # modprobe efivarfs COPY TO CLIPBOARD


Re-enter chroot

root # manjaro-chroot /mnt /bin/bash COPY TO CLIPBOARD


Then mount the efi filesystem

root # mount -t efivarfs efivarfs /sys/firmware/efi/efivars COPY TO CLIPBOARD


Verify the efi filesystem is loaded

root # ls /sys/firmware/efi COPY TO CLIPBOARD


If successfull re-run above installation commands

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.

See also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.