Vagrantfiles for building damaged CentOS 7 installation for troubleshooting purposes
System was damaged by moving bash binary
# mv /bin/bash /bin/bash-bkp
-
Boot rescue DVD of CentOS and mount system partitions to /mnt/sysimage
-
Rename file to its origin name
# mv /mnt/sysimage/bin/bash-bkp /mnt/sysimage/bin/bash
You won't be able to chroot due missing /bin/bash in chroot environment so you need to perform this action outside chroot
-
Reboot
System was damaged by changing default target the system boots to from multi-user.target to emergency.target
# systemctl set-default emergency.target
-
Boot rescue DVD of CentOS and mount system partitions to /mnt/sysimage
-
Chroot into /mnt/sysimage
# chroot /mnt/sysimage
-
Set multi-user.target as default systemd target
# systemctl set-default multi-user.target
-
Reboot system
-
Boot as normal, supply root password in prompt
-
Remount / filesystem as read-write
# mount -o remount,rw /
-
Set multi-user.target as default systemd.target
# systemctl set-default multi-user.target
-
Reboot system
-
Edit boot parameters in GRUB2 stage
Press 'e' to edit GRUB2 boot entry and add following to boot parameters:
systemd.unit=multi-user.target
-
Set multi-user.target as default boot target
# systemctl set-default multi-user.target
System was damaged by deleting initrd files
# rm -rf /boot/initramfs*
-
Boot rescue DVD of CentOS and mount system partitions to /mnt/sysimage
-
Chroot into /mnt/sysimage
# chroot /mnt/sysimage
-
Generate new initrd files for all present kernels
# dracut --regenrate-all
-
Reboot system
System was damaged by zeroing bootstrap area using dd command
# dd if=/dev/zero of=/dev/vda bs=446 count=1
-
Boot rescue DVD of CentOS and mount system partitions to /mnt/sysimage
-
Chroot into /mnt/sysimage
# chroot /mnt/sysimage
-
Install GRUB2 into MBR of /dev/vda
# grub2-install /dev/vda
-
Reboot system
System was damaged by removing files from /boot FS - kernel image, initrd and grub2 files
-
Boot rescue DVD of CentOS and mount system partitions to /mnt/sysimage
-
Chroot into /mnt/sysimage
# chroot /mnt/sysimage
-
Enable your network interface and configure networking
# ip link set eth0 up # dhclient eth0
-
Now remote repositories should be fully operational, so you can reinstall kernel and grub2 packages
# yum reinstall kernel grub2*
-
In case previous command fails issue following command:
# yum remove kernel grub2* # yum install kernel grub2
-
Reinstall GRUB2 into bootloader - it also populates /boot directory
# grub2-install /dev/vda
-
Check the content of /boot directory, in case initramfs is missing gererate it
# dracut --regenerate-all
-
All needed files should be back so generate GRUB2 configuration file
# grub2-mkconfig -o /boot/grub2/grub.cfg
-
Reboot your system
System was damaged by zeroing first 512 bytes of HDD - MBR + partition table
# dd if=/dev/zero of=/dev/vda bs=512 count=1
-
Boot rescue DVD of CentOS - you won't be able to mount /mnt/sysimage as partitions are gone
-
Download testdisk external program using curl, extract and run this program on /dev/vda
# curl -o testdisk.tar.bz2 https://www.cgsecurity.org/testdisk-7.0.linux26-x86_64.tar.bz2 # tar -xvjf testdisk.tar.bz2; cd testdisk-7.0; ./testidisk.static /dev/vda
-
Restore partition table - using testdisk is really straightforward
-
Reboot system but still use rescue DVD
-
As MBR was also zeroed you need to reinstal GRUB2 to MBR user procedure from lab4