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

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

From Manjaro
imported>Verityproductions
m (hit shift)
 
(69 intermediate revisions by 17 users not shown)
Line 1: Line 1:
= Overview =
<languages/>
__TOC__
<translate>
==Overview== <!--T:1-->
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 defaults to GRUB.


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).
<!--T:2-->
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]}}


==Preparation== <!--T:3-->
Identify the type of system you are attempted to resque as the commands involved are slightly different.
* BIOS/MBR/GPT system
* EFI/GPT system


= Boot the Manjaro Installation Media =
==Load Manjaro Installation Media== <!--T:4-->
{{BoxSecondary|System Boot Override|To override system 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>
}}


'''1.''' Insert and boot your Manjaro installation media.  
==Identify partitions== <!--T:5-->
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,PTTYPE,PARTTYPE,FSTYPE,PARTTYPENAME}}
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''.


'''2.''' Select your '''preferred language''' (F2) and '''keyboard layout''' (F3).
<!--T:6-->
{{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.}}


{{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.}}
==Use root context== <!--T:7-->
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== <!--T:8-->
Chroot is a method to restrict various tasks to a restricted area e.g. package installation and other system maintenance tasks. Follow the [https://wiki.archlinux.org/index.php/Change_Root link] to read more about chroot on the Arch wiki.
===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 has intentionally been left out (e.g. ''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.}}


'''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.
===Use manjaro-chroot=== <!--T:10-->
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.This script is only available in live iso by default but you can get it in an installed system by installing {{Ic|manjaro-tools-base}} package.
{{RootCmd|command=pamac install manjaro-tools-base}}
{{RootCmd|command=manjaro-chroot -a}}


'''4.''' Open the terminal or access the command line of the live CD.
===Manual chroot=== <!--T:9-->
(Unnecessary if you have used {{ic|manjaro-chroot}})
Mount the partitions using the designated temporary mountpoint and '''always''' start with ''root''


* '''From the desktop environment''': open the terminal from your desktop menu, or
<!--T:17-->
* '''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.
{{RootCmd|command=mount /dev/sdyC /mnt}}
{{Important|With a [[Btrfs|BTRFS filesystem]], you should note that the subvolumes must be mounted. That would be in such a case:{{RootCmd|command=mount -o subvol=@ /dev/sdyC /mnt}}}}
Then - if applicable - mount ''boot''
{{RootCmd|command=mount /dev/sdyB /mnt/boot}}
Then - if applicable - mount ''efi''
{{RootCmd|command=mount /dev/sdyA /mnt/boot/efi}}
Create the chroot environment and use bash as shell
{{RootCmd|command=manjaro-chroot /mnt /bin/bash}}




= Identify and Prepare the Installed Partition(s) =
==Reinstall GRUB== <!--T:11-->
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.


'''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:
<!--T:12-->
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}}


sudo su
===EFI System=== <!--T:13-->
{{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}}


{{tip|The password - if requested - will be ''manjaro''}}
<!--T:14-->
{{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


==Updating grub==
Sometimes there is an update for the GRUB package itself. So far, the grub package is updated, but the new GRUB Version is not automatically installed in the boot area.


'''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:
You can do this manually following the instructions above. Or you can install the Grub Maintainer Script ''install-grub''. It should work flawless for the majority of people, but SecureBoot, ZFS and fancy encryptions are not supported yet.
{{RootCmd|command=pacman -Syu install-grub}}
Then once run
{{RootCmd|command=install-grub}}
The package includes a hook that will reinstall the bootloader when needed from now on at every update of grub.


sudo blkid
===Additional Information===
Some things around grub can be confusing.
====package version of grub====
Its the version of the grub-package present in your filesystem. But this version changing does ''not'' update the installed grub-bootloader.
====grub-bootloader version====
This can only been shown while you are in the Grub menu (that won’t show up while booting by default, you need to hit [shift] during boot). Hit the key [E] and your will see the Grub version on top.


====update-grub====
Does ''not'' update the installed bootloader. The ‘update’ is more about updating configuration. Think of this more as ‘applying settings’.
(~ equal to grub-mkconfig -o /boot/grub/grub.cfg)
===install-grub===
is the script (background maintainer) that does update the installed bootloader when you download a Stable Release/Unstable Release Version, which included a new Grub Version.


In this particular instance, the partitions for the author's Manjaro system are as follows:
==Troubleshooting== <!--T:15-->
=== Manjaro is not recognized ===
If Manjaro wasn't recognized after an update-grub then probably your Manjaro installation is missing the package lsb-release.


* '''/dev/sda1''': Boot partition
==See also== <!--T:16-->
* '''/dev/sda2''': Swap partition
* [http://wiki.manjaro.org/index.php?title=UEFI_-_Install_Guide UEFI Install Guide]
* '''/dev/sda3''': Manjaro system
* [https://wiki.archlinux.org/index.php/GRUB GRUB on Arch wiki]
* '''/dev/sda4''': Space for personal files.
</translate>
 
[[Category:Contents Page{{#translation:}}]]
{{tip|You can also use an application called '''gparted''' from the desktop menu to look at your partitions. This can help you identify what they are, if you are unsure. For example, if a seperate partition for the GRUB exists, it 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 seperate 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 seperate 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 seperate 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:
 
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
 
 
'''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:
 
pacman -S mtools os-prober
 
 
= Restore the GRUB =
 
'''1.''' Install a new GRUB bootloader with the following command:
 
grub-install /dev/sda
 
 
'''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.
 
 
= 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.
 
[[Category:Troubleshooting]]
[[Category:Contents Page]]

Latest revision as of 07:07, 11 January 2024

Other languages:
Deutsch • ‎English • ‎Türkçe • ‎français • ‎русский

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 defaults to 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/GPT system
  • EFI/GPT system

Load Manjaro Installation Media

System Boot Override
To override system 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,PTTYPE,PARTTYPE,FSTYPE,PARTTYPENAME 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. Follow the link to read more about chroot on the Arch wiki.

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 has intentionally been left out (e.g. 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.


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.This script is only available in live iso by default but you can get it in an installed system by installing manjaro-tools-base package.

root # pamac install manjaro-tools-base COPY TO CLIPBOARD


root # manjaro-chroot -a COPY TO CLIPBOARD


Manual chroot

(Unnecessary if you have used manjaro-chroot) Mount the partitions using the designated temporary mountpoint and always start with root

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


Info
With a BTRFS filesystem, you should note that the subvolumes must be mounted. That would be in such a case:
root # mount -o subvol=@ /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/sdyA /mnt/boot/efi COPY TO CLIPBOARD


Create the chroot environment and use bash as shell

root # manjaro-chroot /mnt /bin/bash 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

Updating grub

Sometimes there is an update for the GRUB package itself. So far, the grub package is updated, but the new GRUB Version is not automatically installed in the boot area.

You can do this manually following the instructions above. Or you can install the Grub Maintainer Script install-grub. It should work flawless for the majority of people, but SecureBoot, ZFS and fancy encryptions are not supported yet.

root # pacman -Syu install-grub COPY TO CLIPBOARD


Then once run

root # install-grub COPY TO CLIPBOARD


The package includes a hook that will reinstall the bootloader when needed from now on at every update of grub.

Additional Information

Some things around grub can be confusing.

package version of grub

Its the version of the grub-package present in your filesystem. But this version changing does not update the installed grub-bootloader.

grub-bootloader version

This can only been shown while you are in the Grub menu (that won’t show up while booting by default, you need to hit [shift] during boot). Hit the key [E] and your will see the Grub version on top.

update-grub

Does not update the installed bootloader. The ‘update’ is more about updating configuration. Think of this more as ‘applying settings’. (~ equal to grub-mkconfig -o /boot/grub/grub.cfg)

install-grub

is the script (background maintainer) that does update the installed bootloader when you download a Stable Release/Unstable Release Version, which included a new Grub Version.

Troubleshooting

Manjaro is not recognized

If Manjaro wasn't recognized after an update-grub then probably your Manjaro 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.