centos7 backup restore with grub2 boot and rescue mode change root password

1.centos7 backup
    1.su -
    2.cd /
    3.tar -zpPcvf backup.tgz --exclude=/sys --exclude=/mnt --exclude=/proc --exclude=/lost+found --exclude= backup.tgz /
2.centos7 restore (solution if the original system hangs up, the system can be restored directly with tar)
    1. The centos7 installation disk enters rescue mode
    2. Partition the disk (sda1 is used as the root directory, and sda2 is used as the swap partition )
fdisk /dev/sda
    p prints the partition of the hard disk to the screen
    d deletes the partition
    n creates a new partition
    w saves the changes and exits
    q exits without saving the previous operation
    3. Format the partition
mke2fs -t ext3 /dev/sda1 Format /dev/sda1 Convert to ext3 file system
mkswap /dev/sda2 Format /dev/sda2 as swap partition
    4. Mount /dev/sda1 to /mnt directory of centos boot disk rescue system
mount /dev/sda1 /mnt
    5. Restore system Backup to the directory /mnt mounted by /dev/sda1
tar -zpxvf backup.tgz -C /mnt

3. Install grub and write the boot information to mbr
    1. Change the directory /mnt mounted by /dev/sda1 to the root directory
chroot /mnt
    2. Mount proc and sysfs
mount -t proc proc /proc
mount sysfs /sys - t sysfs
    3. mbr to install grub2 to /dev/sda
grub2-install /dev/sda1
    4. update the information of /boot/grub2/grub.cfg and /etc/grub2.cfg
grub2-mkconfig -o /boot/grub2/ grub.cfg
grub2-mkconfig -o /etc/grub2.cfg
    {/**
      * @extended command
      * View the default boot kernel grub2-editenv list
      * Modify the title of the default boot grub2-set-default "title"
      * Not chrooted When using (assuming /mnt is the root directory hanging in the location) grub2-install --directory-root=/mnt /dev/sda
      */
    }
    5. Change the uuid identifier in the /etc/fstab file to the hard disk device partition
      such as :
Change the UUID=03feda9-c221-4375-a6bf-0b80bd875323 at the beginning of the line to /dev/sda1
      UUID=f4e3d0dc-df2f-446f-9403-0e51835ca4b3 to /dev/sda2
4. Change the root password (I don’t know why, there is no such operation Can not enter the system)
    1. Press e in the boot selection interface
    2. Then add rw single init=/bin/bash after the line of the penultimate kernel vmlinuz, then Ctrl+X to enter but user mode
    3. passwd to change the root password
    4. touch /.autorelabel
    5.exec /sbin/init (must be started in this way), then enter the root password just changed and press Enter, after the automatic restart, you can enter the restored system
   

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326644513&siteId=291194637