Accidentally running the mkfs.ext4 command on the /boot partition in Fedora 36 can be a nerve-wracking experience. The mkfs.ext4 command is used to create a new ext4 file system on a partition, and running it on the wrong partition can result in data loss and system instability. However, there are steps you can take to recover from this situation and restore your system to a working state.
1. Don't Panic
The first and most important step is to stay calm. Accidents happen, and with the right approach, you can recover from this situation without losing your valuable data.
2. Disconnect Power
As soon as you realize that you have accidentally run mkfs.ext4 on your /boot partition, it is crucial to disconnect the power source from your computer. This will prevent any further changes from being made to the affected partition and increase the chances of successful recovery.
3. Boot from Live USB
To begin the recovery process, you will need to boot your Fedora 36 system from a live USB. A live USB contains a complete operating system that can be run directly from the USB drive without affecting your installed system.
4. Mount the Affected Partition
Once you have booted into the live USB environment, open a terminal and identify the device name of your /boot partition using the lsblk command. It will be something like /dev/sda1.
Next, create a mount point directory using the mkdir command. For example, sudo mkdir /mnt/recovery.
Finally, mount the affected partition to the mount point using the mount command. For example, sudo mount /dev/sda1 /mnt/recovery.
5. Recover Bootloader Files
The next step is to recover the bootloader files that were overwritten by the mkfs.ext4 command. The bootloader is responsible for loading the operating system during startup.
To restore the bootloader files, you will need to reinstall the bootloader. In Fedora 36, the default bootloader is GRUB 2. Run the following command in the terminal to reinstall GRUB 2:
sudo grub2-install --boot-directory=/mnt/recovery/boot /dev/sda
Make sure to replace /dev/sda with the correct device name for your system.
6. Restore Kernel and Initramfs
After recovering the bootloader, you need to restore the kernel and initramfs files. These files are essential for the proper functioning of your system.
First, identify the kernel and initramfs files that were present before the accidental mkfs.ext4 command. These files are typically located in the /boot directory.
Next, copy the kernel and initramfs files from the live USB environment to the recovered /boot partition. You can use the cp command for this purpose. For example:
sudo cp /path/to/live/usb/boot/vmlinuz-5.15.2 /mnt/recovery/boot/vmlinuz-5.15.2
sudo cp /path/to/live/usb/boot/initramfs-5.15.2.img /mnt/recovery/boot/initramfs-5.15.2.img
Make sure to replace /path/to/live/usb with the actual path to the live USB environment and 5.15.2 with the correct version of the kernel and initramfs files.
7. Update Bootloader Configuration
Once the kernel and initramfs files are restored, you need to update the bootloader configuration to reflect the changes.
Edit the GRUB configuration file using a text editor. For example:
sudo nano /mnt/recovery/boot/grub2/grub.cfg
Locate the lines that define the kernel and initramfs files and make sure they match the filenames you restored in the previous step.
8. Reboot
After completing all the above steps, you are ready to reboot your system. Remove the live USB and connect the power source to your computer.
With a bit of luck, your system should now boot successfully from the recovered /boot partition, and you should have access to your data and installed operating system.
Remember to back up your important data regularly to prevent data loss in case of accidents or hardware failures.
| Reference | Link |
|---|---|
| Fedora Documentation | https://docs.fedoraproject.org/ |
| GRUB Documentation | https://www.gnu.org/software/grub/ |