Using grub rescue commands on CentOS

29/12/2020
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:

ls

Where:

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.

Type:

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:

boot

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.

ONET 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, ONET 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

How to Install VMware Workstation Pro 14 on Arch Linux

VMware Workstation is one of the best Virtualization Tool. It is a little bit more complicated to install on Arch Linux...
28/12/2020

How to install Sweet Home 3D 5.4 on Linux

Sweet Home 3D 5.4 latest release, is a free interior design app that helps you draw the floor plan of your house, arrange...
28/12/2020

Apache Kafka Books

Stream processing, a computer programming paradigm that deals with querying continuous data streams and detecting conditions...
29/12/2020
Bài Viết

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

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024