2017-12-13 11:45:40 +00:00
|
|
|
[[restoring-bootloader-using-live-disk]]
|
2018-01-20 17:59:12 +00:00
|
|
|
= Restoring the bootloader using the Live disk.
|
2017-12-13 11:45:40 +00:00
|
|
|
|
2021-01-09 11:33:12 +00:00
|
|
|
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.
|
2017-12-13 11:45:40 +00:00
|
|
|
|
2021-01-09 11:33:12 +00:00
|
|
|
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*.
|
2017-12-13 11:45:40 +00:00
|
|
|
|
|
|
|
.Before you start
|
|
|
|
|
2018-01-20 17:59:12 +00:00
|
|
|
* Get the Fedora Live ISO from link:https://download.fedoraproject.org/pub/fedora/linux/releases/[getfedora.org].
|
|
|
|
|
2017-12-13 11:45:40 +00:00
|
|
|
* 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.
|
|
|
|
|
2023-01-14 10:35:47 +00:00
|
|
|
. Examine the partition layout and identify the `/boot` and the `/root` partition.
|
2022-12-23 16:18:11 +00:00
|
|
|
+
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# fdisk -l
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2021-01-09 11:33:12 +00:00
|
|
|
|
2023-01-14 10:35:47 +00:00
|
|
|
. Follow the <<btrfs-steps, BTRFS steps>> (Fedora 33 or newer) or <<lvm-steps, LVM steps>> (older than Fedora 33) to recover your system.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-14 10:35:47 +00:00
|
|
|
[[btrfs-steps]]
|
|
|
|
== BTRFS steps
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. If your `/root` partition is encrypted by LUKS, it must be decrypted.
|
2017-12-13 11:45:40 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Make sure the crypt module is in use.
|
2017-12-13 11:45:40 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# modprobe dm-crypt
|
2021-01-09 11:33:12 +00:00
|
|
|
----
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Decrypt the `/root` partition (e.g. `/dev/sda3`).
|
2017-12-13 11:45:40 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# cryptsetup luksOpen /dev/sda3 myvolume
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2022-12-23 16:18:11 +00:00
|
|
|
+
|
|
|
|
The decrypted device (i.e. `myvolume`) will be accessible under `/dev/mapper/`.
|
2017-12-13 11:45:40 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. Mount the `/root` partition.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
* For LUKS.
|
2022-04-14 17:19:42 +00:00
|
|
|
+
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount /dev/mapper/myvolume /mnt -o subvol=root
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
* For non-LUKS.
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount /dev/sda3 /mnt -o subvol=root
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. Mount the `/boot` partition (e.g. `/dev/sda2)`.
|
|
|
|
+
|
2022-04-14 17:19:42 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount /dev/sda2 /mnt/boot
|
2022-04-14 17:19:42 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. Mount system processes and devices into the `/root` filesystem.
|
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount -o bind /dev /mnt/dev
|
|
|
|
# mount -o bind /proc /mnt/proc
|
|
|
|
# mount -o bind /sys /mnt/sys
|
|
|
|
# mount -o bind /run /mnt/run
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. On UEFI systems, bind the `efivars` directory and mount the EFI system partition (e.g. `/dev/sda1`).
|
|
|
|
+
|
2021-01-09 11:33:12 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount -o bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
|
|
|
|
# mount /dev/sda1 /mnt/boot/efi
|
2021-01-09 11:33:12 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Change your filesystem to the one mounted under `/mnt/`.
|
|
|
|
+
|
2021-01-09 11:33:12 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# chroot /mnt/
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Re-install *GRUB2*.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
* On UEFI systems, several packages are required.
|
2022-12-23 16:18:11 +00:00
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# dnf reinstall shim-* grub2-efi-* grub2-common
|
2021-11-21 11:43:49 +00:00
|
|
|
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
* On BIOS systems, specify the disk (e.g. `/dev/sda`) where *GRUB2* should be installed.
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# grub2-install /dev/sda
|
2021-01-09 11:33:12 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Re-generate the *GRUB2* configuration file.
|
|
|
|
+
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# grub2-mkconfig -o /boot/grub2/grub.cfg
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Sync and exit the chroot.
|
|
|
|
+
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# sync && exit
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Reboot the system.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-14 10:35:47 +00:00
|
|
|
[[lvm-steps]]
|
|
|
|
== LVM steps
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. If your `/root` partition is encrypted by LUKS, it must be decrypted.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Make sure the crypt module is in use.
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# modprobe dm-crypt
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Decrypt the `/root` partition (e.g. `/dev/sda3`).
|
2017-12-13 11:45:40 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# cryptsetup luksOpen /dev/sda3 myvolume
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Scan the LVM volumes for the volume group corresponding to the `/root` partition.
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# vgscan
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Activate the volume group (e.g. `fedora_localhost-live`).
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# vgchange -ay fedora_localhost-live
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
.. Find the logical volume corresponding to `/root`.
|
2021-11-21 11:43:49 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# lvs
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
|
|
|
+
|
2023-01-14 10:35:47 +00:00
|
|
|
The logical volume will be accessible under `/dev/mapper/`.
|
2022-12-23 16:18:11 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
. Create a `root` directory under `/mnt`.
|
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mkdir -p /mnt/root
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Mount the logical volume (e.g. `/dev/mapper/fedora_localhost--live-root`) corresponding to the `/root` partition.
|
|
|
|
+
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount /dev/mapper/fedora_localhost--live-root /mnt/root
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Mount the `/boot` partition (e.g. `/dev/sda2`).
|
|
|
|
+
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount /dev/sda2 /mnt/root/boot
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Mount system processes and devices into the `/root` filesystem.
|
|
|
|
+
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# 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
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. On UEFI systems, bind the `efivars` directory and mount the EFI system partition (e.g. `/dev/sda1`).
|
|
|
|
+
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# mount -o bind /sys/firmware/efi/efivars /mnt/root/sys/firmware/efi/efivars
|
|
|
|
# mount /dev/sda1 /mnt/root/boot/efi
|
2021-11-21 11:43:49 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Change your filesystem to the one mounted under `/mnt/root`.
|
|
|
|
+
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
# chroot /mnt/root/
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Re-install *GRUB2* and re-generate the *GRUB2* configuration file.
|
2021-11-21 11:43:49 +00:00
|
|
|
|
2023-01-30 12:36:20 +00:00
|
|
|
* On UEFI systems, several packages are required.
|
2017-12-13 11:45:40 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# dnf reinstall shim-* grub2-efi-* grub2-common
|
|
|
|
/]# grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
|
2022-12-23 16:18:11 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
* On BIOS systems, specify the disk (e.g. `/dev/sda`) where *GRUB2* should be installed.
|
2022-12-23 16:18:11 +00:00
|
|
|
+
|
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# grub2-install /dev/sda
|
|
|
|
/]# grub2-mkconfig -o /boot/grub2/grub.cfg
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Sync and exit the chroot.
|
|
|
|
+
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-14 10:35:47 +00:00
|
|
|
/]# sync && exit
|
2017-12-13 11:45:40 +00:00
|
|
|
----
|
2023-01-30 12:36:20 +00:00
|
|
|
+
|
|
|
|
. Reboot the system.
|