LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-10-2010, 08:43 PM   #1
LenW
LQ Newbie
 
Registered: May 2007
Location: Palo Alto, CA, USA
Posts: 3

Rep: Reputation: 0
Question How does Grub2 find the grub.cfg file?


How does Grub2 find the grub.cfg file?

I have (among others) these partitions:
/dev/sda5 'newsys' - my current system partition (Ubuntu Karmic, 64-bit)
/dev/sda2 'oldsys' - the original system partition
/dev/sda1 'boot' - mounted at /boot when running 'newsys'

'boot' and 'oldsys' both have copies of Grub2.
The two copies of grub.cfg are identical except for a
menuentry title, so I can tell which one is being used.

When I boot, the grub menu shown is the one from 'oldsys'.
(Running 'fdisk -l' shows that /dev/sda1 ('boot') is the "Boot"
partition, but I understand that is not relevant for Grub.)

So my problem is that I am otherwise done with 'oldsys'
and I want to delete it, but I can't because
it seems to be used in the boot process.

Questions:
(1) How does Grub2 find the grub.cfg file?
(Is it in the MBR's bootloader code?)

(2) Can I tell which one it will find without actually booting?

(3) And, most importantly, how can I get Grub2 to use 'boot'
instead of 'oldsys' ?

Thanks,
-LenW
 
Old 03-11-2010, 01:04 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
there is a generic answer to this:

Any SW--application, utility, etc.--is programmed to specify where it is supposed to look for its files. This is often done in configuration files that are read in at the start of the program.

In the case of GRUB 0.97 (Why did they go to 2 if they couldn't finish 1??), the location of /boot/grub/menu.lst is "hard-coded" into the stage-I code when GRUB is installed. (Stage-I being what goes in the MBR.) I would assume that GRUB-2 does something similar----reading the manual would be the place to start.
 
Old 03-11-2010, 01:06 PM   #3
ronlau9
Senior Member
 
Registered: Dec 2007
Location: In front of my LINUX OR MAC BOX
Distribution: Mandriva 2009 X86_64 suse 11.3 X86_64 Centos X86_64 Debian X86_64 Linux MInt 86_64 OS X
Posts: 2,369

Rep: Reputation: Disabled
What do you mean by oldsys and newsys ?
Did you install UBUNTU Karmic twice or do you an other version of Ubuntu installed ?
Which kernels are mentioned in the boot options from oldsys or newsys or both ?
 
Old 03-11-2010, 01:15 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,036

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
I am still fighting with grub2 ( actually it is called "1.97 Beta-4" but it is certainly not "Grub legacy" ! ) but take a look here: https://help.ubuntu.com/community/Grub2

Scroll down to "Reinstalling grub2".

Remember, if you edit any of the scripts in /etc/grub.d/ grub2 will fail without any error message if there is a trailing space on any line (except comments?) in those scripts.

Make sure you have a live CD handy for system rescue in case of errors.

Good luck.

PS: And welcome to LQ!

Last edited by tredegar; 03-11-2010 at 01:18 PM.
 
Old 03-11-2010, 06:08 PM   #5
LenW
LQ Newbie
 
Registered: May 2007
Location: Palo Alto, CA, USA
Posts: 3

Original Poster
Rep: Reputation: 0
Wink

Thanks for your help. I did look back over the docs
(the online info files) and decided that I should try (as root):

grub-setup -r '(hd0,1)' /dev/sda

I was diappointed to find that the MBR hadn't changed.

But I thought I would try rebooting anyway .... and ....
IT WORKED !! - The Grub menu came from my 'boot' partition !

I then compared my entire /boot directory tree with a backup.
The ONLY change was removal of an empty file:
/boot/grub/setup_left_core_image_in_filesystem
For totally gruesome completeness, I put back the empty file
and rebooted again - STILL boots from 'boot' Hurray!!

So it is still a mystery as to what tells grub where to find
grub/grub.cfg .
I can proceed to delete the obsolete partition, but I'd sure
like to know what is going on.
Any more thoughts? Maybe I'll try the help-grub list.

I'll let you know if I find anything.

Cheers,
-LenW

PS Not sure if this thread should be marked "Solved"
- I believe my problem is solved, but I still can't answer the question in the title

BTW, the 'oldsys' partition is the same O/S . It came with the system and
included the /boot directory. I built 'newsys' and 'boot' .

Last edited by LenW; 03-11-2010 at 06:17 PM.
 
Old 03-11-2010, 10:34 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
Perhaps GRUB-2 puts some things in stage-II?

When you install a bootloader, there is code that goes in the MBR, but that usually links to more code that is beyond the MBR----in the first 63 sectors of the drive (before the first partition). I have no clue as to the details of how grub-2 works in this regard.
 
Old 03-12-2010, 01:56 AM   #7
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,686

Rep: Reputation: Disabled
In case you haven't found those:

http://ubuntuforums.org/printthread.php?t=1195275
http://www.dedoimedo.com/computers/grub-2.html
 
Old 03-12-2010, 03:40 PM   #8
LenW
LQ Newbie
 
Registered: May 2007
Location: Palo Alto, CA, USA
Posts: 3

Original Poster
Rep: Reputation: 0
Wink

BINGO!! I of course have no record of what those 63 sectors were
before I ran grub-setup, I tried to recreate the old data
by running grub-setup again again with -r '(hd0,2)'
And indeed the only change was that byte 0x414 = 1044 changed from
0x00 to 0x01. (BTW, about 50 of the 63 sectors were used.)

So I know that grub-setup does make its change in that first ("hidden")
track. BUT, I also know that I did not successfully recreate the old
data because trying to boot threw me into a "grub rescue>" prompt.
I managed to climb out of that tiger-trap, and another grub-setup fixed it.

I suspect the remaining confusion may involve the fact that on
'oldsys' the grub dir is /boot/grub while on 'boot' it's just /grub .
So I don't quite understand what's going on, but it's close enough for me,
and I'm marking this thread as "Solved" .

Thanks muchly,
-LenW
 
Old 03-15-2010, 04:28 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,686

Rep: Reputation: Disabled
Btw. GRUB does have a find command to find files...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grub2 detects Mac OSX on sdb, but doesn't install it to grub.cfg? JohnLocke Linux - Newbie 16 02-17-2010 06:10 PM
Grub2 questions: need to know grub.cfg syntax for bootable grub_eltorito iso's?? linus72 Linux - General 11 02-11-2010 07:20 PM
Creating a Grub2 boot-cd with a (grub.cfg) menu ..my solution ssenuta Linux - General 3 02-04-2010 07:16 PM
Grub2 and isolinux.cfg niravshah Linux - Newbie 10 07-23-2009 07:15 PM


All times are GMT -5. The time now is 11:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration