Question

Write a bash script that change the grub default boot to the highest kernel (not necessary...

Write a bash script that change the grub default boot to the highest kernel (not necessary the first entry) version. The OS is CentOS 6.x. Manual steps will not be accepted.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey, It seems like you want to change the Grand unified bootloader(GRUB) using scripting of BASH.

For simplicity purposes, I had divided the explanation into parts. So, let's start:

PART ONE: UNDERSTANDING THE REQUIREMENT AND INPUTS REQUIRED:

This part will discuss the requirements to automatically change the default boot of GRUB to the user-specific choice.

Since manual steps are not entertained, I will bring my approach solely on the basis of the scripting.

The requirement is as simple as that to change the default GRUB boot loader to a choice of the user.

PART TWO: APPROACH:

The approach will be as follows:

1. Find the path where this default boot loading path information is kept. (/etc/default/grub)

GRUB_DEFAULT=0

2. Edit the path using the root-level access and change the default grub to the choice of yours. (vim /etc/default/grub)

3. Search inside the file for GRUB_DEFAULT and change its value.

GRUB_DEFAULT=5

where 5 is the index of GRUB_MENU in which mode you would like to boot by default. The menu item starts with 0. Hence, to boot with the 6th item, you have to set the GRUB_DEFAULT = 5 and so on.

If you don't know the sequence of boot loaders, please open the /boot/grub/grub.cfg file and find the order.

In this config file, the name and other details of bootloaders will be present in an ordered manner.

In place of the index, you can also pass the name like,

GRUB_DEFAULT=Windows8

4. Update GRUB with root-level privileges.

- sudo update grub

PART THREE: FULL IMPLEMENTATION:

Considering you want to change the default GRUB to user-defined. The present value as a GRUB_DEFAULT will be 0 and you need to give a value as an input or can make constant in the script so that the bootloader will be selected.

sed -i 's/GRUB DEFAULT=0/GRUB DEFAULT=1/' /etc/default/grub

sed -i s/GRUB_DEFAULT=0/GRUB_DEFAULT=1/ /etc/default/grub

Save this file as a bash script and it will do the needful for changing the bootloader without human intervention of manual things.

In place of 1, you can give the index or name of the bootloader which you wish to change.

Make sure to run this script as a root-user only.

*****************SCRIPT**************

#!/bin/bash
sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=1/' /etc/default/grub

*****************SCRIPT***************

I hope it will help you in completing the requirement.

Please don't forget to thumbs up if it helped you.

Keep learning and keep HomeworkLibing :)

Thanks and All the best

******************************************COMPLETE************************************

Add a comment
Know the answer?
Add Answer to:
Write a bash script that change the grub default boot to the highest kernel (not necessary...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them....

    Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them. The program should print the result of the comparison. Specifically, it should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal, the program should have an exit status of zero. The exit...

  • Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment...

    Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment to tell us what you did, why and how. 3. allows a user to enter their name and a number between 1 than 100 (this must be prompted so the user knows what to do) 4. creates a random number between 1 and 100 for you to guess. The command to create a random number is shown below. (if you find a better one...use...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT