Novice Error in Handling Accidents Delete boot directory and more serious delete operations

Newcomers come to Sa, Bao Jiao Bao Club, increase knowledge and teach routines

Experimental Environment: VMware Virtual Machine, CentOS-6.9 Operating System

Experiment Details: Remove boot directory in partitioned case and repair to remove fstab file

Delete the boot directory by mistake, don't panic, follow the blogger step by step to rebuild it

First let's simulate deleting the boot directory

[root@centos6 ~]# rm -rf /boot/*     #Delete all files in boot directory
[root@centos6 ~]# reboot             #Reset computer

Dang: Successful destruction, computer can not start, prompt message:

Don't panic, you can build if you disassemble it, you can stand if you break it.Keep up with the pace

Repair process:

Enter Rescue Mode

Don't know how the rescue mode works?Simple, look, first make sure the disc is mounted, then it's gone (Don't hit your face, don't hit your face) There are also.. The system will enter the following interface when it starts:

Then test your speed, press the Esc key in a flash of thunder before the end of the reading strip (note: once and for a while, don't listen to the advice and take care of the consequences), and a rare interface pops up:

(Up and down key move option, Enter key determine)

Choose 3, 3, 3!Start the system from CD,

No, no, a familiar word, Rescue. Yes, it's what. Select it, select it.And then you don't understand... patience, then you know

Select Language on the Left --"English

Right Select Keyboard Format --"us (American Keyboard)

Then let's let you choose the network connection. For convenience, we won't choose it here. No, No

Winning is in front of you, reminding you that you are about to enter rescue mode, and the previous root directory will move to / mnt/sysimage (remember, remember)

Successfully entered rescue mode, select shell Start shell


You will find that you will enter a bash interface where you can tap commands, but this is not the root directory of your original system. To fix the Misdeleted bootmul, you have to go to your root directory first:

sh-4.1#chroot /mnt/sysimages         #Switch your home directory and you'll see that it's still what it used to be
sh-4.1#ls /boot/                     #ls boot directory found boot directory deleted clean

Next, boldly add files to the boot directory

sh-4.1#mount /dev/sr0 /mnt/          #Mount the disc, we need some files inside
sh-4.1#cp /mnt/isolinux/vmlinuz /boot    #Copy this file from the CD to the boot directory, which is a kernel file
sh-4.1#mkinitrd /boot/initramfs-`uname -r`.img `uname -r`     #This command generates a pseudo-root file responsible for driving the file system to mount the root directory
sh-4.1#ls /boot/                     #You can view the files that have been generated in the boot directory
sh-4.1#grub-install /dev/sda         #Re-install grub, responsible for boot-up of the system.Note that if your virtual machine has several disks installed, certain errors may be reported: Unknown partition table signature is OK, and does not affect repair
sh-4.1##########The basic file is assembled, and the last step is to edit the configuration file
sh-4.1#nano /boot/grub/grub.conf        #There is no vim edit command in my rescue mode, use nano to edit grub profile
###Type the following###
default=0         #There will be a menu at startup and 0 will be the first kernel in the default startup file
timeout=5         #Wait for 5 seconds when no selection is made
title mozart-centos        #menu title
kernel /vmlinuz root=/dev/sda2    #Start the kernel with the same file name.Mounted device that writes the original root directory after root
initrd /initramfs-xxxxx.img xxxxx    #Pseudo root system, note that the file names are the same, keeping the same name as the pseudo root file under boot

With great success, the boot directory is repaired.

Type exit to exit the original root directory, exit to bash, and reboot Reboot to restart the system

System Resuscitation (Fireworks)

In a rush...

(Eyeless pedestrian A): What if the output is more severe?Deleting the fstab file under etc puts you in rescue mode, but you can't mount the original root directory and find the boot directory. How can you break it?

Uh...this...

Simple! Now that we don't have the fstab file, we'll go into rescue mode and write one, the old way, into rescue mode.

This is a reminder of the rescue mode when deleting the fstab file:

Regardless of it, we still enter the bash interface. Because of the lack of fstab files, disks don't know where to mount, and we don't know which partition holds our root directory. It's not scary, it's easy. Just mount one partition at a time to see it (Hey hey)

sh-4.1#mkdir test       #Directory to create test partitions
sh-4.1#mount /dev/sda1 test/   
sh-4.1#ls test/         #Mount the partition, and view the partition content to determine...
######Test section omitted here###########
sh-4.1#mount /dev/sda2 test/
sh-4.1#ls test/         #Finally, we found that we could find the original root directory by mounting the / dev/sda2 partition (cheer)
######Next we'll do our own artificial intelligence (handwriting) fstab Files, if any backup copies are in the past#######
sh-4.1#nano test/etc/fstab
######Type the following based on the partition#####3
/dev/sda1    /boot    ext4    defaults    0  0
/dev/sda2    /        ext4    defaults    0  0
/dev/sda3    /app     ext4    defaults    0  0
............
sh-4.1#exit    #Exit bash, select reboot Reboot to restart the system,

Restart the system, have a good time..... How can you possibly just fix a problem (fix the fstab file), get into rescue mode, and mount the root directory on / mnt/sysyimage by default. There is also a boot directory to fix..

Pedestrian A: Isn't there a detailed tutorial to fix the boot directory above, are you silly...?

Uh.....yeah, the rest is the same as above, go into rescue mode and fix the boot directory.

But hey hey, I left one hand:

When generating kernel files and pseudo-roots, you don't have to bother with command-by-command generation. These files come from the kernels package. Just reinstall the kernels package. After switching the root directory, mount the disc

rpm -ivh /mnt/cdrom/Packages/kernel.xxx.rpm  --force        #--force, force a reload of the kernel package to generate files under boot such as a kernel file pseudo-root file

Then reinstall grub, edit the grub configuration file (note: consistency of file names within the configuration file), restart, end

It's over, it's really over, cheating is not good...



Keywords: CentOS Vmware network shell

Added by falcon1 on Wed, 22 May 2019 19:59:44 +0300