Grub 2 Menu Edit

Asked by srikumar

1. Can the Grub 2 menu be edited in the grub.cfg file.? It starts off with "Do not Edit this File".
2. Is it safe to do this ?
3. Will any such change be effective only upto the next system upgrade ?
4. Is there any fix coming up for Grub 2 ?

I am using WinXP/Ub9.10 Dual Boot with the latest upgrades. I have to edit the WinXP Grub boot menu each time as follows:-

root (hd0,1)
chainloader +1

This way I am able to boot into WinXP. However this has to be done each time WinXP is to be booted, which is several times a day. I need to find a more permanent solution to this problem.

I do not mind editing the grub.cfg file each time the system is upgraded - at least this is a better solution than the present one.

Any suggestion
thank you
srikumar

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
srikumar
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Xiao Shi Zi (lionel-bogaert) said :
#1

check https://wiki.ubuntu.com/Grub2

Grub2 cfg is splitted into multiple files under the directory /etc/grub.d/
There you can add a new entry:

file name: 41_windows

containing:

#! /bin/sh -e
echo "Adding Windows" >&2
cat << EOF
menuentry "Windows XP" {
#set root=(hd1,1)
drivemap hd1 hd0
set root=(hd1,1)
chainloader --force +1
}

sudo chmod u+x /etc/grub.d/41_windows

To take effect you need to use command :

update-grub

Enjoy,

Xiao Shi Zi.

Revision history for this message
srikumar (ssrikumar) said :
#2

Hi Xiao

Thank you for the info.

How to create the file "41_windows". The file does not have an extension so I cannot create it in Word. I tried to copy an existing file in grub.d so as tro rename it and add the above entries but the files in grib.d could not be copied.

Please explain how to do this.

thank you
srikumar

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

You can edit grub.cfg but its pointless, grub.cfg is generated using the scripts and files outlined in the grub2 link which Xiao gave. If you edit it it will work fine but next time you install a new kernel the changes will be lost as the file will be regenerated.

If you want permanent changes you need to edit the config files appropriately then run:

sudo update-grub

which will then commit your changes to the file, the changes will then also survive kernel installations as they will be applied each time.

Linux does not use file extensions and they mean nearly nothing, linux looks at the structure of the file to tell what it is rather than old slow windows who refuses to divorce itself from the 8.3 file naming convention (very restrictive)

If you run:

gksudo gedit /etc/grub.d/41_windows

You will make the file when you save the file, why the hell are you using Word!!? Word will add a tonne of extra formatting data which will make the file not work, use gedit or some other basic file editor so the extra data is not added.

Revision history for this message
srikumar (ssrikumar) said :
#4

Hi Xiao

I've tried to create 41_windows in ...etc/grub.d using gediit but it would not let me save the file - "no permissions". How to proceed ?

Thanks
srikumar

Hi actionparsnip

It may be easier to edit grub.cfg, although I will need to repaet it after each upgrade, and put in the line "root (hd0,1)" but here again - "no permissions" for editing the file. How to proceed?

Thanks
srikumar

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

Run:
gksudo gedit

Then open the file. You don't have write access as the program runs as you (a user). You use gksudo for graphical apps just like you use sudo in terminal etc.

You will also need to run:
sudo chmod +w /boot/grub/grub.cfg

As the file is marked as not writable by default (this should further disuade you from hand editting the file

As with all Linuxes, things can be done (like this) even if they are really not advised. I suggest you look into grub2 a little more and configure it the correct way.

Revision history for this message
Xiao Shi Zi (lionel-bogaert) said :
#6

Statup under ubuntu
then start a terminal and type

gksudo gedit /etc/grub.d/41_window

enter your password

copy paste the text

#! /bin/sh -e
echo "Adding Windows" >&2
cat << EOF
menuentry "Windows XP" {
#set root=(hd0,1)
chainloader --force +1
}

Save and exit the gedit.

back in the terminal type

sudo chmod +x /etc/grub.d/41_windows

update-grub

exit

after this do a reboot and test the window boot.
If this is ok let us know. If till a problem inform us.

Kind greetings,

Xiao Shi Zi.

Revision history for this message
srikumar (ssrikumar) said :
#7

Hi Xiao

The first part went off well and I find that the 41_windows file has been created with the correct entrie into the correct sub-directory.

However the command "sudo chmod +x /etc/grub.d/41_windows" returns the response
"no such file or directory" - see below

srikumar@srikumar-desktop:~$ sudo chmod +x /etc/grub.d/41_windows
[sudo] password for srikumar:
chmod: cannot access `/etc/grub.d/41_windows': No such file or directory
srikumar@srikumar-desktop:~$

How to proceed ?

thanks
srikumar

Revision history for this message
srikumar (ssrikumar) said :
#8

Thanks actionparsnip

Have edited the grub.cfg file and saved it.
Now WinXP boots from the Grub Menu without any problem.
Have noted to re-perform this process every time after an upgrade.

In the meantime I am hoping to install Virtual Box on my home computer to see how it works.

thank you
srikumar

Revision history for this message
Xiao Shi Zi (lionel-bogaert) said :
#9

Hi srikumar,

First make a copy of your modified grub.cfg
open a terminal and type

sudo cp /boot/grub/grub.cfg /boot/grub/grub.old

sorry I mistyped that command about chmod.
41_windows should be without the s => 41_window

so the right command is:

sudo chmod +x /etc/grub.d/41_window

then proceed with

update-grub

exit

and reboot to test the window entry.

Revision history for this message
srikumar (ssrikumar) said :
#10

Hi Ziao

The update-grub command result is:-

srikumar@srikumar-desktop:~$ sudo chmod +x /etc/grub.d/41_window
srikumar@srikumar-desktop:~$ update-grub
/usr/sbin/grub-mkconfig: You must run this as root
srikumar@srikumar-desktop:~$

How to proceed ?

kind regards
srikumar

Revision history for this message
Xiao Shi Zi (lionel-bogaert) said :
#11

hello srikumar,

sudo update-grub

this makes the command to run as superuser = root.

greetings Xiao Shi Zi.

Revision history for this message
srikumar (ssrikumar) said :
#12

Hi Xiao

This was done and a new Grub Menu entry titled "Windows XP" has appeared. However when this is clicked the computer re-boots back to the Grub Menu.

The Grub.cfg file was edited as suggested by actionparsnip and I am able to boot into WinXP.

In the circumstances we will close this thread.

Thanks for all the assistance.
srikumar