LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   LFS 7.1 First Boot, grub error (https://www.linuxquestions.org/questions/linux-from-scratch-13/lfs-7-1-first-boot-grub-error-4175444890/)

engineer 01-09-2013 08:02 PM

LFS 7.1 First Boot, grub error
 
I just tried booting my LFS system for the first time, and encountered an error when booting. GRUB loads the OS name, but when it comes time to boot, it says "error: file not found".

Below is the grub.cfg file that I created right before I rebooted (my root partition is mounted on /dev/sda3, so I used that, like the book suggested.

Code:

cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod ext2
set root=(hd0,2)
menuentry "GNU/Linux, Linux 3.5.2-lfs-7.1" {
        linux  /boot/vmlinuz-3.5.2-lfs-7.1 root=/dev/sda3 ro
}
EOF

What have I missed?

stoat 01-09-2013 08:17 PM

If you have a separate boot partition as the set root command suggests, then you should not include "/boot" in the path of that linux command. On the other hand, if you do not have a separate boot partition, then the set root command should specify (hd0,3).

engineer 01-09-2013 09:07 PM

Is there a way to change the configuration file now that I am not able to boot? What is the meaning of the (hd0,3) option? Why not use the "sda" nomenclature?

stoat 01-09-2013 09:29 PM

Quote:

Originally Posted by engineer

Is there a way to change the configuration file now that I am not able to boot?

In the same terminal you have been working in, open the file /boot/grub/grub.cfg that you just created and fix it one way or the other for the situation. Then save it and move on.

Quote:

Originally Posted by engineer

What is the meaning of the (hd0,3) option?

GRUB uses and understands that (hdX,X) syntax. In GRUB 2, (hd0,3) would indicate the first drive and its third partition (the device name equivalent of /dev/sda3, usually). The set root=(hd0,3) command line indicates to GRUB the location of the boot files. The paths in the subsequent commands, such as the linux command, are relative to it.

Quote:

Originally Posted by engineer

Why not use the "sda" nomenclature?

That /dev/sda3 thing is a device name used by the operating system. GRUB is not using it. The root=/dev/sda3 in the linux command is merely a parameter being passed to the kernel which needs it. As for the pure question of why it is that way, who knows. It's been that way since the beginning of legacy GRUB when we all were throwing rocks and sticks at each other and howling at the moon.

engineer 01-09-2013 09:51 PM

Quote:

Originally Posted by stoat (Post 4866647)
In the same terminal you have been working in, open the file /boot/grub/grub.cfg that you just created and fix it one way or the other for the situation. Then save it and move on.

GRUB uses and understands that (hdX,X) syntax. In GRUB 2, (hd0,3) would indicate the first drive and its third partition (the device name equivalent of /dev/sda3, usually).

That /dev/sda3 thing is a device name used by the operating system. GRUB is not using it. In the grub.cfg file, the root=/dev/sda3 in the linux command is not serving the same purpose as the set root=(hd0,3) command line which GRUB uses to find the boot files. In the linux command, root=/dev/sda3 is merely a parameter being passed to the kernel which needs it. As for the pure question of why it is that way, who knows. It's been like then since the beginning of legacy GRUB when we all were throwing rocks and sticks at each other and howling at the moon.

I would just modify the file, but I'm not able to get to a command prompt, other than the basic grub one. I can't get into the system at the moment. I also think I tried hd0,3 as well as removing the /boot parameter, to no avail. I was able to do that by modifying the line within the basic grub edit window where you select the OS you want to boot.

stoat 01-09-2013 10:20 PM

Quote:

Originally Posted by engineer

I would just modify the file, but I'm not able to get to a command prompt, other than the basic grub one.

If it's still stopping with that "file not found" message, then try having GRUB search for the boot partition with the search command at the boot menu's grub> prompt. Like this...
Code:

grub> search -f /boot/grub/grub.cfg
grub> search -f /grub/grub.cfg

Try both. One should give results that can be used to settle what to put in the set root command (and the root= kernel parameter if they're the same partition). Anyway, edit the lines as you did before, boot, hope. If it boots, then fix the grub.cfg file.

P.S.: The search command that gives results also will be the clue as to whether or not to use "/boot" in the path of the linux command.

stoat 01-09-2013 10:51 PM

Another thing I forgot about is if you find out some partition numbers in the grub.cfg were wrong and fix them, it may boot farther along and stop again if your /etc/fstab also contains partition errors. Anyway, it happens all the time. Be prepared to fix that, too.

Keith Hedger 01-10-2013 09:49 AM

Quote:

Originally Posted by stoat (Post 4866647)
...As for the pure question of why it is that way, who knows. It's been that way since the beginning of legacy GRUB when we all were throwing rocks and sticks at each other and howling at the moon.

LOL! I still use Grub legacy ( I find it easier to set up and reinstall when I inevitably fubar my system )!

spiky0011 01-10-2013 02:16 PM

Hi

What file system did you use to build lfs, did you make it ext3 or ext4?

engineer 01-10-2013 05:42 PM

So I tried this:

Code:

grub> search -f /boot/grub/grub.cfg
And the output was

Code:

grub> hd0 msdos6
I'm having trouble remembering exactly how I setup the partitions, I had originally wrote it down, but then I started over, and changed one or two things... From what I remember, I used the /boot partition that already existed, and created a new Swap partition, / partition, and the lfs partition itself. If memory serves, all (but the swap) were ext3 FS type.

I've tried:

Code:

set root=(hd0,3)
and:

Code:

set root=(hd0,2)
And then tried to boot, but neither of these worked. I also tried modifying the lines with the 'e' for edit command at the GRUB menu, and removing the /boot prefix on the /vmlinuz line. I think I'm not understanding something here when it comes to modifying this file. Thank you for all the help so far.

engineer 01-10-2013 05:50 PM

Quote:

Originally Posted by stoat (Post 4866647)
. As for the pure question of why it is that way, who knows. It's been that way since the beginning of legacy GRUB when we all were throwing rocks and sticks at each other and howling at the moon.

Now, THAT, is funny!

stoat 01-10-2013 09:05 PM

Quote:

Originally Posted by engineer

I'm having trouble remembering exactly how I setup the partitions

Uh, I think that right there is the problem. Anyway the search commands found a single grub.cfg file in the second logical partition of an extended partition. And since the command that produced that result had "/boot" in its path, that is not a separate boot partition but a partition with a directory named "boot" in its filesystem (such as in a root partition). So a reasonable thing to try at the grub> prompt is this...
Code:

grub> linux (hd0,6)/boot/vmlinuz-3.5.2-lfs-7.1 root=/dev/sda6 ro
grub> boot

And see what happens.

If that doesn't at least attempt to boot the LFS system, then boot with a live CD and post some more information to show the partition layout better such as the fdisk output for /dev/sda. I'm wondering where is or what happened to the host system, for example.

P.S.: Some other grub> searches that might help untangle this might be searching specifically for the LFS kernel and the lfs-release file (if you created it)...
Code:

grub> search -f /vmlinuz-3.5.2-lfs-7.1
grub> search -f /boot/vmlinuz-3.5.2-lfs-7.1
grub> search -f /etc/lfs-release

If you find those, then all that is necessary to boot the system will be known with certainty.

engineer 01-12-2013 11:00 AM

Quote:

Originally Posted by stoat (Post 4867456)
Uh, I think that right there is the problem. Anyway the search commands found a single grub.cfg file in the second logical partition of an extended partition. And since the command that produced that result had "/boot" in its path, that is not a separate boot partition but a partition with a directory named "boot" in its filesystem (such as in a root partition). So a reasonable thing to try at the grub> prompt is this...
Code:

grub> linux (hd0,6)/boot/vmlinuz-3.5.2-lfs-7.1 root=/dev/sda6 ro
grub> boot

And see what happens.

If that doesn't at least attempt to boot the LFS system, then boot with a live CD and post some more information to show the partition layout better such as the fdisk output for /dev/sda. I'm wondering where is or what happened to the host system, for example.

P.S.: Some other grub> searches that might help untangle this might be searching specifically for the LFS kernel and the lfs-release file (if you created it)...
Code:

grub> search -f /vmlinuz-3.5.2-lfs-7.1
grub> search -f /boot/vmlinuz-3.5.2-lfs-7.1
grub> search -f /etc/lfs-release

If you find those, then all that is necessary to boot the system will be known with certainty.

Ok, I've tried several permutations of the search command, with no luck beyond the previous output. None of the last three commands you posted yielded any results. Also, in my infinite wisdom, the version is 3.2.6, not 3.5.2 as I erroneously posted above--I did try the searches with the correct information.

Now, this begs the question, where is the original boot file that the base system uses? How can I roll back to that? Also, what does it actually mean when we search for:

Code:

grub> search -f /boot/grub/grub.cfg
and get output:

Code:

grub> hd0 msdos6
??

I'm sorry for my ignorance, but I've never spent any time messing around with GRUB, so I'm really in the dark here.

spiky0011 01-12-2013 11:57 AM

Hi

Can you boot a live cd and post the output of fdisk -l, to see partition layout

engineer 01-12-2013 02:40 PM

Code:

fdisk -l
Code:

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *        2048    1026047      512000  83  Linux
/dev/sda2        1026048  154626047    76800000  83  Linux
/dev/sda3      154626048  175106047    10240000  83  Linux
/dev/sda4      175106048  976773119  400833536    5  Extended
/dev/sda5      175110144  185350143    5120000  82  Linux swap / Solaris
/dev/sda6      185352192  292968447    53808128  83  Linux

The LFS system is on /dev/sda6, and the FS type is ext3.

spiky0011 01-12-2013 02:46 PM

So am i correct you cant find boot or grub for lfs?

engineer 01-12-2013 05:15 PM

Using the search function of grub, the only thing I've been able to find is the grub.cfg file, on hd0 msdos6. Outside of that, I've tried searching for several different locations, and apparently it's just nowhere to be found...

spiky0011 01-12-2013 05:19 PM

Hi

If you mount the lfs partition usin live cd you can look through the whole partition,
You could use host system to mount the partition

engineer 01-12-2013 06:01 PM

Quote:

Originally Posted by spiky0011 (Post 4868606)
Hi

If you mount the lfs partition usin live cd you can look through the whole partition,
You could use host system to mount the partition

Yup, I'm cruising around in there right now. Thank you for the help. I'm sure I'll be back.

stoat 01-12-2013 06:02 PM

Quote:

Originally Posted by engineer

...the only thing I've been able to find is the grub.cfg file, on hd0 msdos6.

Possible explanation: the host system was using legacy GRUB. At this point, fixing the host system's boot loader is a good idea (IMO). After all, you don't know if the LFS system is even capable of booting yet. Consider booting the host system with a Super Grub 2 Disk. Then repair its boot loader with grub-install /dev/sda in a terminal. Then you can use the host again and use its boot loader to boot LFS while you continue working on it. You also can use the Super Grub 2 Disk to boot the LFS system until it is finished.

engineer 01-12-2013 08:42 PM

The plot thickens. Thanks for the link to the software, stoat. I tried to boot with the SG2 program, and here are the results:

- First option: Detect any OS. Selecting this option brings up just two listings; LFS, and LFS single user mode. I tried picking both of them, and neither of them will boot. GRUB acts like it is doing something (data running across the screen) then just stops after a few seconds, with some text on the screen saying something about kernel panic (most of the text doesn't mean anything to me, if you want me to post more details, let me know).
- Second option: Detect any GRUB2 configuration file (grub.cfg). This results in one listing, grub.cfg, listed on hd0,6, and when selecting this I get the same error as before: file not found, and no booting action.
- Third option: Detect any GRUB2 installation (even if MBR is overwritten). This has the same result as option 2, it lists the LFS system, and when I pick it, still no boot.

I also chose the list devices/partitions option, which resulted in a listed of the partition table, which included hd0,6 as a type ext2 FS, and hd0,3, as an ext2 FS, for my Fedora install.

For what it's worth, I don't have any data on this system, just the base system, which I installed for the sole purpose of building LFS, and the LFS build that I am working on. So, no major loss other than time if I have to start over. At this point, I'm just curious where I went wrong so I don't do it again next time. I'm going to try looking at the config files I made just before rebooting via mounting the lfs partition within the Fedora live CD environment to try and glean some more answers.

PS. I don't think the host was using legacy grub. The host is/was (Taps playing in background) Fedora 17. Also, just to be clear, when Grub loads, it says Grub 1.99 at the top of the screen.

stoat 01-12-2013 09:26 PM

Use that live CD to mount and examine the filesystem of /dev/sda1. Its size makes it look like the Fedora boot partition. If so, the Fedora kernel, initial ram filesystem, and GRUB folder should be there. But in post #10 you mentioned using the existing boot partition. I'm wondering if it got formatted or if the Fedora boot files are still there or what. And if you find the LFS boot files in the /boot folder of /dev/sda6, maybe you could post the grub.cfg that we know is there since the one in post #1 is not it. Perhaps someone will see what is causing the file not found error and offer something to fix it. Who knows, the LFS system might miraculously boot to a login prompt. If so, it at least would be possible to tweak and finalize if for BLFS without the further need of the host system. If it doesn't boot own its own now, that would be trouble without the host system available.

spiky0011 01-13-2013 03:02 AM

Posting the output of lfs /boot might help as well

engineer 01-13-2013 09:03 AM

Quote:

Originally Posted by stoat (Post 4868708)
Use that live CD to mount and examine the filesystem of /dev/sda1. Its size makes it look like the Fedora boot partition. If so, the Fedora kernel, initial ram filesystem, and GRUB folder should be there. But in post #10 you mentioned using the existing boot partition. I'm wondering if it got formatted or if the Fedora boot files are still there or what. And if you find the LFS boot files in the /boot folder of /dev/sda6, maybe you could post the grub.cfg that we know is there since the one in post #1 is not it. Perhaps someone will see what is causing the file not found error and offer something to fix it. Who knows, the LFS system might miraculously boot to a login prompt. If so, it at least would be possible to tweak and finalize if for BLFS without the further need of the host system. If it doesn't boot own its own now, that would be trouble without the host system available.

Ok, I mounted the /dev/sda1 partition, the below is the output.

Code:

[root@localhost /]# mkdir /mnt/exboot
[root@localhost /]# mount -t ext4 /dev/sda1 /mnt/exboot
[root@localhost /]# cd /mnt/exboot
[root@localhost exboot]# ls
config-3.3.4-5.fc17.i686        initramfs-3.6.9-2.fc17.i686.img
config-3.6.9-2.fc17.i686        lost+found
efi                              memtest86+-4.20
elf-memtest86+-4.20              System.map-3.3.4-5.fc17.i686
grub                            System.map-3.6.9-2.fc17.i686
grub2                            vmlinuz-3.3.4-5.fc17.i686
initramfs-3.3.4-5.fc17.i686.img  vmlinuz-3.6.9-2.fc17.i686

Also, I mounted the /mnt/lfs system (from /dev/sda6) and here is the output of the /boot directory in there:

Code:

[root@localhost grub]# cd /mnt/lfs
[root@localhost lfs]# ls
bin  dev  home  lost+found  mnt  proc  run  sources  sys  tools  var
boot  etc  lib  media      opt  root  sbin  srv      tmp  usr
[root@localhost lfs]# cd /boot
[root@localhost boot]# ls
config-3.3.4-5.fc17.i686  grub            System.map-3.3.4-5.fc17.i686
efi                      grub2            vmlinuz-3.3.4-5.fc17.i686
elf-memtest86+-4.20      memtest86+-4.20

When I go into the /boot/grub directory within the lfs system (supposedly where the grub.cfg file went that I created in Chapter 8.4.4, here is the output (note that there is no grub.cfg file) I'm not sure if it is supposed to be in here, or on the /boot directory of /dev/sda1...

Code:

[root@localhost lfs]# cd /boot
[root@localhost boot]# ls
config-3.3.4-5.fc17.i686  grub            System.map-3.3.4-5.fc17.i686
efi                      grub2            vmlinuz-3.3.4-5.fc17.i686
elf-memtest86+-4.20      memtest86+-4.20
[root@localhost boot]# cd grub
[root@localhost grub]# ls
splash.xpm.gz


spiky0011 01-13-2013 09:25 AM

Hi

The boot dir dose not look right for lfs. It looks like the boot dir of fedora
The files which should have been copied when building the kernel chapter 8.3

vmlinuz-3.5.2-lfs-7.2
System.map-3.5.2
config-3.5.2

I see what you have done cd /mnt/lfs/boot
dont do /mnt/lfs
then cd /boot That will put you in host boot dir
You should of cd /mnt/lfs Then cd boot

engineer 01-13-2013 09:56 AM

You're right. My mistake. See below.

Code:

[root@localhost grub]# cd /mnt/lfs
[root@localhost lfs]# cd boot
[root@localhost boot]# ls
config-3.2.6  grub  System.map-3.2.6  vmlinuz-3.2.6-lfs.7.1


spiky0011 01-13-2013 10:04 AM

Ok

Your 1st post you were looking for vmlinuz-3.5.2-lfs-7.1
You should of had vmlinuz-3.2.6-lfs.7.1
your grub.cfg should look like this

Code:

Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod ext2
set root=(hd0,6)
menuentry "GNU/Linux, Linux 3.2.6-lfs-7.1" {
        linux  /boot/vmlinuz-3.2.6-lfs-7.1 root=/dev/sda6 ro
}

Now did you install grub as per chapter 8.4
installing grub to
Code:

grub-install /dev/sda
?
or what did you do?

engineer 01-13-2013 04:19 PM

Since the book said that this chapter was optional, all I did was create the new /mnt/lfs/boot/grub/grub.cfg file as shown above.

I'm at a real loss as to how Grub is working here. I've tried updating the grub.cfg file as you showed above. I've also checked that the files were copied in Section 8.3 (vmlinuz-3.2.6-lfs-7.1, System.map-3.2.6, and config-3.2.6) were all placed in the /boot directory of the /mnt/lfs partition for the LFS system.

Where does grub look for the information to choose which kernels (or OS) to display for selection on booting? Is this the information in the grub.cfg file? If so, it is correctly reading that file, since the kernel listed in Grub's boot menu is the 3.2.6 lfs kernel. Once I choose a kernel to boot, where does Grub look for the image (or what tells grub where to look for the image)?

It seems like no matter what I do, I get the error: file not found error on trying to boot the 3.2.6 image. What file is grub referring to when it says it is not found?

spiky0011 01-13-2013 04:29 PM

I,m not sure where the problem is but at the moment you now know that you are on sda6 which kernel to use vmlinuz-3.2.6-lfs-7.1.

I hope you now get a grub prompt when you boot the machine?
There could be problems in the kernel config.

When you built the kernel did you check and build in devtmpfs as mention on kernel page
Code:

Device Drivers  --->
  Generic Driver Options  --->
    Maintain a devtmpfs filesystem to mount at /dev


engineer 01-13-2013 06:09 PM

Yes, I do get a grub terminal when I boot.

Also, I did make the change in the kernel configuration for the devtmpfs as required.

stoat 01-13-2013 06:15 PM

Maybe it's just a typo. These are different...
Quote:

Originally Posted by engineer in post #26
Code:

[root@localhost boot]# ls
config-3.2.6  grub  System.map-3.2.6  vmlinuz-3.2.6-lfs.7.1


Quote:

Originally Posted by engineer in post #28

I've also checked that the files were copied in Section 8.3 (vmlinuz-3.2.6-lfs-7.1, System.map-3.2.6, and config-3.2.6) were all placed in the /boot directory of the /mnt/lfs partition for the LFS system.


stoat 01-14-2013 03:41 PM

Quote:

Originally Posted by engineer in post #28

Where does grub look for the information to choose which kernels (or OS) to display for selection on booting? Is this the information in the grub.cfg file? If so, it is correctly reading that file, since the kernel listed in Grub's boot menu is the 3.2.6 lfs kernel. Once I choose a kernel to boot, where does Grub look for the image (or what tells grub where to look for the image)?

GRUB 2 is more complicated, does more things, and has components with new names, but it still works basically a lot like legacy GRUB did. In a traditional BIOS-MBR setup like yours (I think), a small program (boot.img) is embedded in the master boot record of the first hard drive and is executed at boot time. That little program loads and executes a bigger one (a copy of core.img) that usually and traditionally is embedded in the normally unused sectors between the master boot record and the first partition (nowadays, this copy of core.img goes in other places for GPT drives and EFI computers). The core.img program includes modules to access the file system where it finds the grub.cfg file and other needed modules. It creates the menu screen using the information in grub.cfg. You select something from the menu and core.img uses the information in the grub.cfg file to find the boot files to load and execute, to load other modules that may be needed, and to pass parameters to the kernel.

If you are using the boot loader of another system (such as Fedora's) to boot LFS, then its boot.img and core.img were embedded and its grub.cfg is being used, so that menuentry stuff you have been agonizing over needs to be in Fedora's grub.cfg. In that case, a grub.cfg in the LFS /boot partition would not be needed nor used. But if you installed LFS's GRUB in the master boot record (with the grub-install /dev/sda command), then LFS's core.img was embedded and its grub.cfg is being used and where your menuentry stuff has to go and be accurate.

engineer 01-14-2013 07:04 PM

Quote:

Originally Posted by stoat (Post 4869301)
Maybe it's just a typo. These are different...

Well, I owe you a cold beverage.

After I fixed the typo, it booted. Facepalm.

engineer 01-14-2013 07:27 PM

Quote:

Originally Posted by engineer (Post 4870102)
Well, I owe you a cold beverage.

After I fixed the typo, it booted. Facepalm.

I've been trying to not be lazy and type the commands so that I could learn them. Turns out this isn't the first time that plan backfired.


All times are GMT -5. The time now is 12:57 AM.