{"id":12369,"date":"2019-03-26T21:47:51","date_gmt":"2019-03-26T21:47:51","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12369"},"modified":"2019-03-26T21:53:06","modified_gmt":"2019-03-26T21:53:06","slug":"how-to-recover-or-rescue-corrupted-grub-boot-loader-in-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-recover-or-rescue-corrupted-grub-boot-loader-in-centos-7\/","title":{"rendered":"How to Recover or Rescue Corrupted Grub Boot Loader in CentOS 7"},"content":{"rendered":"<p>In this tutorial we\u2019ll cover the process of rescuing a corrupted boot loader in\u00a0<strong>CentOS 7<\/strong>\u00a0or\u00a0<strong>Red Hat Enterprise Linux 7<\/strong>\u00a0and recover the a forgotten root password.<\/p>\n<p>The\u00a0<strong>GRUB<\/strong>\u00a0boot loader can sometimes be damaged, compromised or deleted in CentOS due to various issues, such as hardware or software related failures or sometimes can be replaced by other operating systems, in case of dual-booting. A corrupted Grub boot loader makes a\u00a0<strong>CentOS\/RHEL<\/strong>\u00a0system unable to boot and transfer the control further to Linux kernel.<\/p>\n<p>The Grub boot loader stage one is installed on the first\u00a0<strong>448<\/strong>\u00a0bytes at the beginning of every hard disk, in an area typically known as the\u00a0<strong>Master Boot Record<\/strong>\u00a0(<strong>MBR<\/strong>).<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/rescue-repair-and-reinstall-grub-boot-loader-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">How to Rescue, Repair and Recover Grub Boot Loader in Ubuntu<\/a><\/p>\n<p>The\u00a0<strong>MBR<\/strong>\u00a0maximum size is\u00a0<strong>512<\/strong>\u00a0byes long. If from some reason the first\u00a0<strong>448<\/strong>\u00a0bytes are overwritten, the\u00a0<strong>CentOS<\/strong>\u00a0or\u00a0<strong>Red Hat Enterprise Linux<\/strong>\u00a0cannot be loaded unless you boot the machine with a\u00a0<strong>CentOS ISO<\/strong>\u00a0image in rescue mode or using other boot loading methods and reinstall the\u00a0<strong>MBR GRUB<\/strong>\u00a0boot loader.<\/p>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"http:\/\/isoredirect.centos.org\/centos\/7\/isos\/x86_64\/\" target=\"_blank\" rel=\"nofollow noopener\">Download CentOS 7 DVD ISO Image<\/a><\/li>\n<\/ol>\n<h3>Recover GRUB Boot Loader in CentOS 7<\/h3>\n<p><strong>1.<\/strong>\u00a0On the first step, download the latest version of\u00a0<strong>CentOS 7 ISO<\/strong>\u00a0image and burn it to a DVD or create a bootable USB stick. Place the bootable image into your machine appropriate drive and reboot the machine.<\/p>\n<p>While the\u00a0<strong>BIOS<\/strong>\u00a0performs the POSTs tests, press a special key (<strong>Esc, F2, F11, F12, Del<\/strong>\u00a0depending on the motherboard instructions) in order to enter BIOS settings and modify the boot sequence so that the bootable DVD\/USB image is booted first at machine start-up, as illustrated in the below image.<\/p>\n<div id=\"attachment_27404\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/System-Boot-menu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27404\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/System-Boot-menu.png\" alt=\"System Boot Menu\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-27404\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27404\" class=\"wp-caption-text\">System Boot Menu<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0After the\u00a0<strong>CentOS 7<\/strong>\u00a0bootable media has been detected, the first screen will appear in your machine monitor output. From the first menu choose the\u00a0<strong>Troubleshooting<\/strong>\u00a0option and press\u00a0<strong>[enter]<\/strong>\u00a0key to continue.<\/p>\n<div id=\"attachment_27405\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Select-CentOS-7-Troubleshooting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27405\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Select-CentOS-7-Troubleshooting.png\" alt=\"Select CentOS 7 Troubleshooting\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-27405\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27405\" class=\"wp-caption-text\">Select CentOS 7 Troubleshooting<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0On the next screen choose\u00a0<strong>Rescue a CentOS system<\/strong>\u00a0option and press\u00a0<strong>[enter]<\/strong>\u00a0key to move further. A new screen will appear with the message \u2018<strong>Press the Enter key to begin the installation process<\/strong>\u2019. Here, just press\u00a0<strong>[enter]<\/strong>\u00a0key again to load the CentOS system to memory.<\/p>\n<div id=\"attachment_27407\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Rescue-CentOS-7-System.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27407\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Rescue-CentOS-7-System.png\" alt=\"Rescue CentOS 7 System\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-27407\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27407\" class=\"wp-caption-text\">Rescue CentOS 7 System<\/p>\n<\/div>\n<div id=\"attachment_27406\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Rescue-Process.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27406\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Rescue-Process.png\" alt=\"Rescue CentOS 7Process\" width=\"720\" height=\"400\" aria-describedby=\"caption-attachment-27406\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27406\" class=\"wp-caption-text\">Rescue CentOS 7Process<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0After the installer software loads into your machine RAM, the rescue environment prompt will appear on your screen. On this prompt type\u00a0<code>1<\/code>\u00a0in order to\u00a0<strong>Continue<\/strong>\u00a0with the system recovery process, as illustrated in the below image.<\/p>\n<div id=\"attachment_27408\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Rescue-Prompt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27408\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Rescue-Prompt.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Rescue-Prompt.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Rescue-Prompt-768x576.png 768w\" alt=\"CentOS 7 Rescue Prompt\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27408\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27408\" class=\"wp-caption-text\">CentOS 7 Rescue Prompt<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0On the next prompt the rescue program will inform you that your system has been mounted under\u00a0<code>\/mnt\/sysimage<\/code>\u00a0directory. Here, as the rescue program suggests, type\u00a0<strong>chroot \/mnt\/sysimage<\/strong>\u00a0in order to change Linux tree hierarchy from the ISO image to the mounted root partition under your disk.<\/p>\n<div id=\"attachment_27412\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Mount-CentOS-7-Image.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27412\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Mount-CentOS-7-Image.jpg\" alt=\"Mount CentOS 7 Image\" width=\"720\" height=\"540\" aria-describedby=\"caption-attachment-27412\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27412\" class=\"wp-caption-text\">Mount CentOS 7 Image<\/p>\n<\/div>\n<p><strong>6.<\/strong>\u00a0Next, identify your machine hard drive by issuing the below command in the rescue prompt.<\/p>\n<pre># ls \/dev\/sd*\r\n<\/pre>\n<p>In case your machine uses an underlying old physical RAID controller, the disks will have other names, such as\u00a0<code>\/dev\/cciss<\/code>. Also, in case your CentOS system is installed under a virtual machine, the hard disks can be named\u00a0<code>\/dev\/vda<\/code>\u00a0or\u00a0<code>\/dev\/xvda<\/code>.<\/p>\n<p>However, after you\u2019ve identified your machine hard disk, you can start installing the GRUB boot loader by issuing the below commands.<\/p>\n<pre># ls \/sbin | grep grub2  # Identify GRUB installation command\r\n# \/sbin\/grub2-install \/dev\/sda  # Install the boot loader in the boot partition of the first hard disk\r\n<\/pre>\n<div id=\"attachment_27413\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Install-Grub-Boot-Loader-in-CentOS-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27413\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Install-Grub-Boot-Loader-in-CentOS-7.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Install-Grub-Boot-Loader-in-CentOS-7.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Install-Grub-Boot-Loader-in-CentOS-7-768x576.png 768w\" alt=\"Install Grub Boot Loader in CentOS 7\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27413\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27413\" class=\"wp-caption-text\">Install Grub Boot Loader in CentOS 7<\/p>\n<\/div>\n<p><strong>7.<\/strong>\u00a0After the\u00a0<strong>GRUB2<\/strong>\u00a0boot loader is successfully installed in your hard disk MBR area, type\u00a0<strong>exit<\/strong>\u00a0to return to the CentOS boot ISO image tree and\u00a0<strong>reboot<\/strong>\u00a0the machine by typing\u00a0<strong>init 6<\/strong>\u00a0in the console, as illustrated in the below screenshot.<\/p>\n<div id=\"attachment_27414\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Exit-Grub-Prompt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27414\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Exit-Grub-Prompt.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Exit-Grub-Prompt.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Exit-Grub-Prompt-768x576.png 768w\" alt=\"Exit CentOS 7 Grub Prompt\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27414\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27414\" class=\"wp-caption-text\">Exit CentOS 7 Grub Prompt<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0After machine restart, you should, first, enter\u00a0<strong>BIOS<\/strong>\u00a0settings and change the boot order menu (place the hard disk with the installed MBR boot loader on the first position in boot menu order).<\/p>\n<p>Save BIOS settings and, again,\u00a0<strong>reboot<\/strong>\u00a0the machine to apply the new boot order. After reboot the machine should start directly into the GRUB menu, as shown in the below image.<\/p>\n<div id=\"attachment_27415\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Grub-menu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27415\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/CentOS-7-Grub-menu.png\" alt=\"CentOS 7 Grub Menu\" width=\"720\" height=\"400\" aria-describedby=\"caption-attachment-27415\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27415\" class=\"wp-caption-text\">CentOS 7 Grub Menu<\/p>\n<\/div>\n<p>Congratulations! You\u2019ve successfully repaired your CentOS 7 system damaged GRUB boot loader. Be aware that sometimes, after restoring the GRUB boot loader, the machine will restart once or twice in order to apply the new grub configuration.<\/p>\n<h3>Recover Root Password in CentOS 7<\/h3>\n<p><strong>9.<\/strong>\u00a0If you\u2019ve forgotten the root password and you cannot log in to CentOS 7 system, you can basically reset (blank) the password by booting the CentOS 7 ISO DVD image in recovery mode and follow the same steps as shown above, until you reach\u00a0<strong>step 6<\/strong>. While you\u2019re chrooted into your CentOS installation file system, issue the following command in order to edit Linux accounts password file.<\/p>\n<pre># vi \/etc\/shadow\r\n<\/pre>\n<p>In shadow file, identify the root password line (usually is the first line), enter\u00a0<strong>vi edit mode<\/strong>\u00a0by pressing the\u00a0<code>i<\/code>\u00a0key and delete the entire string in between the first colon\u00a0<code>\u201c:\u201d<\/code>\u00a0and the second colon\u00a0<code>\u201d:\u201d<\/code>, as illustrated in the below screenshot.<\/p>\n<div id=\"attachment_27416\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Root-Password-Info.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27416\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Root-Password-Info.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Root-Password-Info.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Root-Password-Info-768x576.png 768w\" alt=\"Root Encrypted Password\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27416\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27416\" class=\"wp-caption-text\">Root Encrypted Password<\/p>\n<\/div>\n<div id=\"attachment_27417\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Delete-Encrypted-Root-Password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27417\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Delete-Encrypted-Root-Password.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Delete-Encrypted-Root-Password.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Delete-Encrypted-Root-Password-768x576.png 768w\" alt=\"Delete Root Encrypted Password\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27417\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27417\" class=\"wp-caption-text\">Delete Root Encrypted Password<\/p>\n<\/div>\n<p>After you finish, save the file by pressing the following keys in this order\u00a0<code>Esc -&gt; : -&gt; wq!<\/code><\/p>\n<p><strong>10.<\/strong>\u00a0Finally,\u00a0<strong>exit<\/strong>\u00a0the chrooted console and type\u00a0<strong>init 6<\/strong>\u00a0to\u00a0<strong>reboot<\/strong>\u00a0the machine. After reboot, login to your CentOS system with the root account, which has no password configured now, and setup a new password for root user by executing the\u00a0<strong>passwd command<\/strong>, as illustrated in the below screenshot.<\/p>\n<div id=\"attachment_27418\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-New-Root-Password-in-CentOS-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27418\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-New-Root-Password-in-CentOS-7.png\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-New-Root-Password-in-CentOS-7.png 800w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-New-Root-Password-in-CentOS-7-768x576.png 768w\" alt=\"Set New Root Password in CentOS 7\" width=\"800\" height=\"600\" aria-describedby=\"caption-attachment-27418\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27418\" class=\"wp-caption-text\">Set New Root Password in CentOS 7<\/p>\n<\/div>\n<p>That\u2019s all! Booting a physical machine or a VM with a CentOS 7 DVD ISO image in recovery mode can help system administrators to perform various troubleshooting tasks for a broken system, such as recovering data or the ones described in the tutorial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we\u2019ll cover the process of rescuing a corrupted boot loader in\u00a0CentOS 7\u00a0or\u00a0Red Hat Enterprise Linux 7\u00a0and recover the a forgotten root password. The\u00a0GRUB\u00a0boot loader can sometimes be damaged, compromised or deleted in CentOS due to various issues, such as hardware or software related failures or sometimes can be replaced by other operating &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-recover-or-rescue-corrupted-grub-boot-loader-in-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Recover or Rescue Corrupted Grub Boot Loader in CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12369","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12369"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12369\/revisions"}],"predecessor-version":[{"id":12380,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12369\/revisions\/12380"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}