Using grub rescue commands on CentOS

Chưa phân loại
GRUB (Grand Unified Bootloader)  is the most widely used bootloader among Linux operating systems (OS) but it can boot any OS.

GRUB main functionality is to allow users to select between different operating systems to boot. As bootloader GRUB is installed on the MBR (Master Boot Record) and additionally to allow us to select different OS it also allows us to select between different kernel or kernel parameters and to boot in rescue mode if our kernel was damaged or if we lost our root password as explained in a previous article in which on how to restore CentOS root password editing GRUB’s booting parameters.

This tutorial explains how to access rescue mode through GRUB in CentOS Linux distributions and the basic commands we can use.

There may be different scenarios encouraging you to go through GRUB rescue mode. The first scenario assumes GRUB doesn’t show up at all, not even a command prompt like grub> or #. The second scenario assumes the computer boots but the OS doesn’t and  you are directed to a command prompt.

Scenario 1: GRUB doesn’t show up, reinstalling GRUB from the CentOS installation disk.

Before such scenario you need to boot from the disk/usb, select the last option Troubleshooting

In the second screen select the second option “Rescue a CentOS system”.

When you are asked to select between 4 options, type 1 for the rescue mode to find your Linux installation and press ENTER.

The rescue mode will mount the system image in /mnt/sysimage, change the image’s root location as recommended by the system by typing:

chroot /mnt/sysimage

To find your disks type:

ls /dev/sd*

For very old IDE disks type:

ls /dev/hd*

We confirm there is a sda disk, to install grub on that disk run:

grub2-install /dev/sda

Now you can reboot and GRUB should prompt at boot

Using GRUB rescue mode commands on CentOS

The following image shows Grub’s main screen on CentOS Linux, before going to the command prompt you can check the current configuration by pressing e. If you are going through booting problems and you see a command prompt go to the next step.

After pressing e we’ll see the current configuration,kernel, etc. If we lose our root access as explained in the tutorial mentioned at the beginning we need to edit this file as first step.

As the options at the screen bottom say you can get back with Escape but press c to access the command prompt.

Type “ls” to see the available devices and partitions:



Hd0: first hard disk device.

msdos = partition table type

There are msdos1 and msdos2 for each partition.In GRUB2 partition counting starts from 1 in contrast to GRUB’s previous version which started from 0. Extended partitions counting starts from 5.

Note: MBR only supports up to 4 primary partitions in contrast to GPT.

To show the disk and partitions you can also type “set root=(“ and press the TAB key twice:

set root=(


Now type:

ls (hd0,msdos1)/

As you see the first directories belong to GRUB and GRUB2.


ls (hd0,msdos1)/grub2

The file grub.cfg is grub’s file configuration generated when we run grub2-mkconfig. If you don’t find the file grub.cfg create it running  grub2-mkconfig

Now type

set root=(hd0,msdos1)
linux /boot/vmlinuz root=/dev/sda1

With set root we define the main device, hd0,msdos1, with linux we define the kernel,we can see the kernel with the command mentioned previously:  ls (hd0,msdos1)/

Now lets define Grub’s path by typing:

set prefix=(hd0,msdos1)/grub2

To end type:

initrd (hd0,msdos1)/initramfs-3.10.0-957.el7.x86_64.img


Reboot typing:


Now you should be able to boot into your system.

I hope this tutorial helped you to troubleshoot GRUB. Keep following LinuxHint for more tutorials and updates on Linux.

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

[Checkmk 1.6] Cấu hình cảnh báo qua slack

Trong bài viết trước bạn đã có thể cấu hình gửi cảnh báo qua email và telegram. Bài viết này sẽ...

Running PostgreSQL using Docker Compose

Docker-compose can be used to easily automate multi-container deployments. One of the most challenging tasks while running...

How to download and Play Sid Meier’s Civilization VI on Linux

Introduction to the game Civilization 6 is a modern take on the classic concept introduced in the series of the Age of...
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019

How to Update Ubuntu Linux

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu

Hướng dẫn cài đặt Apache CloudStack

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader