quick-docs/modules/ROOT/pages/_partials/proc_restoring-bootloader-using-live-disk.adoc
2022-12-23 16:18:11 +00:00

221 lines
No EOL
4.3 KiB
Text

[[restoring-bootloader-using-live-disk]]
= Restoring the bootloader using the Live disk.
Sometimes, especially after a secondary operating systems has been installed,
the master boot record gets damaged which then prevents the original Linux system
from booting.
If this happens, it is necessary to reinstall *GRUB2* to recreate the original
settings. The process not only discovers all installed operating systems, but
usually adds them to the *GRUB2* configuration files, so they will all become
bootable by *GRUB2*.
.Before you start
* Get the Fedora Live ISO from link:https://download.fedoraproject.org/pub/fedora/linux/releases/[getfedora.org].
* Prepare a bootable device using the downloaded ISO, either a CD or a USB.
.Procedure
. Boot the Fedora live system from the bootable device you have created.
. Open the terminal.
. Examine the partition layout and identify the `boot` and the `root` partition.
+
----
sudo fdisk -l
----
== BTRFS filesystem
If your `root` partition is encrypted by LUKS, it must be decrypted:
. Make sure the crypt module is in use:
+
----
sudo modprobe dm-crypt
----
. Decrypt the `root` partition:
+
----
sudo cryptsetup luksOpen <root_partition> myvolume
----
+
The decrypted device (i.e. `myvolume`) will be accessible under `/dev/mapper/`.
Mount the `root` partition:
* For LUKS:
+
----
mount <decrypted_device> /mnt -o subvol=root
----
* For non-LUKS:
+
----
mount <root_partition> /mnt -o subvol=root
----
Mount the `boot` partition:
----
mount <boot_partition> /mnt/boot
----
Mount system processes and devices into the `root` filesystem:
----
mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
mount -o bind /run /mnt/run
----
On UEFI systems, bind the efivars directory and mount the EFI system partition:
----
mount -o bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
mount <efi_system_partition> /mnt/boot/efi
----
Change your filesystem to the one mounted under `/mnt/`:
----
chroot /mnt/
----
Re-install GRUB:
* On UEFI systems, several packages are required:
+
----
dnf reinstall shim-* grub2-efi-* grub2-common
----
* On BIOS systems, specify the disk where GRUB should be installed:
+
----
grub2-install <disk>
----
Re-generate the GRUB configuration file:
----
grub2-mkconfig -o /boot/grub2/grub.cfg
----
Sync and exit the chroot:
----
sync && exit
----
Reboot the system.
== LVM filesystem
If your `root` partition is encrypted by LUKS, it must be decrypted:
. Make sure the crypt module is in use:
+
----
sudo modprobe dm-crypt
----
. Decrypt the `root` partition:
+
----
sudo cryptsetup luksOpen <root_partition> myvolume
----
. Scan the LVM volumes for the volume group corresponding to the `root` partition:
+
----
sudo vgscan
----
. Activate the volume group:
+
----
sudo vgchange -ay <volume_group>
----
. Find the root volume:
+
----
sudo lvs
----
+
The root volume will be accessible under `/dev/`.
Create a `root` directory under `/mnt`:
----
mkdir -p /mnt/root
----
Mount the logical volume of the `root` partition:
* For LUKS, substitute the root volume from above:
+
----
mount <root_volume> /mnt/root
----
* For non-LUKS, use `lsblk` to find the `lvm` that corresponds to the `root` partition (the `lvm` should be under `/dev/mapper/`):
+
----
mount <lvm> /mnt/root
----
Mount the `boot` partition:
----
mount <boot_partition> /mnt/root/boot
----
Mount system processes and devices into the `root` filesystem:
----
mount -o bind /dev /mnt/root/dev
mount -o bind /proc /mnt/root/proc
mount -o bind /sys /mnt/root/sys
mount -o bind /run /mnt/root/run
----
On UEFI systems, bind the efivars directory and mount the EFI system partition:
----
mount -o bind /sys/firmware/efi/efivars /mnt/root/sys/firmware/efi/efivars
mount <efi_system_partition> /mnt/root/boot/efi
----
Change your filesystem to the one mounted under `/mnt/root`:
----
chroot /mnt/root/
----
Re-install GRUB and re-generate the GRUB configuration file:
* On UEFI systems, several packages are required:
+
----
dnf reinstall shim-* grub2-efi-* grub2-common
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
----
* On BIOS systems, specify the disk where GRUB should be installed:
+
----
grub2-install <disk>
grub2-mkconfig -o /boot/grub2/grub.cfg
----
Sync and exit the chroot:
----
sync && exit
----
Reboot the system.