2

I did something stupid. My thinking was that /boot directory is empty and contents come to /boot each time the computer starts. My /boot drive was giving me error messages no space left so I thought there might be junk files. I deleted all the contents of /boot by rm -rf * and rebooted the computer by reboot command. Now the system is not starting. I am getting error at boot i.e.
error file /grub2/i386-pc/normal.mod not found
Entering rescue mode ... grub rescue>

Most of the search shows solving the issue by repairing the grub. In my case I know that I have deleted the contents so how could I restore the system. I am using Centos 7.

2 Answers 2

6

The /boot partition holds important Linux kernel files as well as Grub files. Without them, your system will not boot (as you already figured out). And just restoring the Grub files is not going to help. To recover from this you should be able to do the following:

  • Boot the system into rescue mode from the CentOS DVD/ISO image
  • Reinstall the kernel by running yum reinstall kernel
  • Reinstall Grub by running /sbin/grub2-install /dev/sda

In the last step, you might need to replace /dev/sda with another device name, depending on your hardware. It should be your primary hard drive from which you want to boot. On virtual machines, this is usually /dev/vda. If you are unsure, you can use the lsblk command (you may need to run yum install util-linux first) to list all your block devices and you should be able to recognize the disk by it's size.

After this, your system should boot normally again.

3
  • This sounds good. I am making a centos 7 usb to boot and do the process. I will update.
    – drmaa
    Sep 27, 2018 at 10:17
  • Till now its not going very well for me. Now I am backing up the data by using the live usb and network.
    – drmaa
    Oct 1, 2018 at 11:14
  • Okay I tried my best but failed. I tried both live and bootable centos 7 but no luck. I dont have internet in rescue mode of bootable where I can use yum. I dont get /mnt/sysimage when boot from live cd so I can install grub or kernel. Is there any application in Centos like boot-repair in Ubuntu youtube.com/watch?v=i97y5Y2nChs
    – drmaa
    Oct 2, 2018 at 11:11
1

I had a similar problem recently. I could recover by following the answer here.
I documented the steps that I followed in a new answer.

I copying my answer here for convenience:

I have a Fedora 30 PC. The boot partition is on /dev/sda3 and the root partition is on an LVLM named Fedora-root. I ran all commands with the root account.

  1. I booted from the Fedora live media (from a USB drive)

  2. Mount my root partition

    mount /dev/mapper/Fedora-root /mnt
    
  3. Mount my boot partition
    mount /dev/sda3 /mnt/boot
    
  4. Copy the kernel from the live partition to the intended boot partition
    cp /boot/vmlinuz-$(uname -r) /mnt/boot/
    
  5. Mount system partitions
    mount --bind /dev /mnt/dev
    mount --bind /sys /mnt/sys
    mount --bind /proc /mnt/proc
    
  6. Change root to /mnt
    chroot /mnt
    
  7. Generate the initramfs
    dracut /boot/initramfs-$(uname -r).img $(uname -r) -v
    
  8. Re-install grub and re-configure it
    grub2-mkconfig -o /boot/grub2/grub.cfg
    

For some reason which I don't know, generating the initramfs was very slow and couldn't finish on my system (step 6). However, the command worked normally when I didn't chroot the filesystem. So, I skipped the steps from 3 onwards. I also had to modify the dracut configuration to point to the root system.

So, the new steps are:

  1. Point to the root location in the dracut configuration
    echo "root=/dev/mapper/Fedora/root" > /etc/dracut.conf.d/kernel.conf
    
  2. Re-install the kernel and generate the initramfs
    dracut /dev/sda/initramfs-$(uname -r).img $(uname -r) -v
    
  3. I then followed steps 3-6 above, so I can rebuild the grub configuration (this step may be not needed, I was over cautious)
    mount /dev/mapper/Fedora-root /mnt`  
    mount /dev/sda3 /mnt/boot
    cp /boot/vmlinuz-$(uname -r) /mnt/boot/
    mount --bind /dev /mnt/dev
    mount --bind /sys /mnt/sys
    mount --bind /proc /mnt/proc
    chroot /mnt
    
  4. Re-install grub and re-configure it
    grub2-install /dev/sda
    grub2-mkconfig -o /boot/grub2/grub.cfg
    

Note for NVIDIA owners
I have a NVIDIA GPU, and I had the proprietary drivers installed before the incident.
The restored kernel from the live media used the Nouveau drivers (as it is the default driver in Fedora). The restored kernel was also not the latest version. When I updated the kernel afterwards using the GUI interface, it used the NVIDIA proprietary drivers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .