-   Linux From Scratch (
-   -   Grub error 21 with LFS 6.3 Chapter 8.4 (

bines 12-18-2008 03:29 PM

Grub error 21 with LFS 6.3 Chapter 8.4
After two past failed attempts with earlier versions I've finally completed LFS 6.3 using the LiveCD - and learnt a great deal along the way! I've followed the book very carefully (I don't know enough to stray anyway!)

I'm now stuck in Chapter 8.4 'Making the LFS System Bootable'. I want to make a dual-boot system for LFS and my Windows XP system, both of which are in separate partitions.

In chapter 8.4, I run the GRUB shell then type: root (hd0,2). But I get the dreaded "Error 21: Selected disk does not exist".

LFS is built on partition sda3 which is of type ext3. Other partitions contain Windows XP (sda1), a 'User' partition for my Windows files (sda6) and a small partition for the Linux swap file (sda5).

I use just a single SATA hard drive (no RAID).

When compiling the Kernel I have ensured that Serial ATA (prod), SCSI and type ext3 have all been enabled.

Although I've found others on this forum with Error 21 problems, they seem to be doing things a bit different to me so have been of little help.
I can't find any hints that address this problem, nor does Google throw up anything useful.

I'm determined not to have to give up yet again and have to snatch defeat from the jaws of success! so any advice would be very much appreciated.


ken5an 12-19-2008 12:47 AM

Congrats! You are almost there!

If I were you I would brute force it. That is, there are only so many partitions, and likely you are only off by one or two. So I would try

root (hd0,1)


root (hd0,3)

NOTE: I didn't say to run setup (hd0)!!

Running the two root commands above, when you hit the correct drive you will see grub say that it found the the stage{1,2} files. Once you see this feedback from grub, you can setup (hd0).

The worst that happens is that grub can't boot linux, and you have to use the livecd and run grub again, trying a different root (hd?,?).

Now if you try all the combinations and don't get grub saying it found the stage files, come on back!

bines 12-19-2008 01:02 PM

Many thanks ken5an for your reply.

I tried all partition numbers from 0 to 6 in each of drive numbers 0 to 4 but always got that dreaded error 21 message. I couldn't see much future in going any further but it was definitely worth a go.

I've looked in my BIOS to see if there is anything I could conceivably change to do with the SATA drive but couldn't see anything.

I'm going to re-visit those other posts and see if there's anything I have missed. Meanwhile I hope there is someone out there who can shed some light on the problem.

Once again many thanks for your suggestion.

yancek 12-19-2008 02:26 PM

Open a terminal/konsole and login as root, run command 'fdisk -l' without quotes, Lower case Letter L, not a one (1). Post the output so we have your exact partition info as seen by LFS.

Second, again from a terminal as root, type 'grub' at the prompt to get the grub prompt (grub>), when you get this type:

find /boot/grub/stage1
find /boot/vmlinuz
geometry (hd0)

Post results of these commands.

bines 12-20-2008 01:37 PM

Many thanks Yancek for your reply. Here is the information you requested:

fdisk -l produces the following output:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 12748 102398278+ 7 HPFS/NTFS
/dev/sda2 24907 30514 45046260 f W95 Ext’d (LBA)
/dev/sda3 12749 24906 97659135 83 Linux
/dev/sda5 24907 25496 4739143+ 83 Linux
/dev/sda6 25497 30514 40307053+ 7 HPFS/NTFS

I have built my LFS system on sda3 with a small swap file on sda5.
The other partitions are for my existing Windows XP system.

In GRUB: find /boot/grub/stage1 produces: (hd0,2)
find /boot/vmlinuz produces: Error 15: File not found

geometry (hd0) produces the following:

Drive 0x80: C/H/S=30515/255/63, The number of sectors=490234752, /dev/sda
Partition num: 0, Filesystem type unknown, partition type 0x7
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type unknown, partition type 0x83
Partition num: 5, Filesystem type unknown, partition type 0x7

I hope this might give some clue to what is going on.

In my BIOS I have set the first boot device to be my DVD R/W drive (because my host is the LFS Live DVD) and the second boot device is my SATA hard drive.

Thanks again for your interest.

syg00 12-20-2008 02:05 PM

I haven't tried LFS, but are you running the grub command as root ?.

ken5an 12-21-2008 12:05 AM

This likely won't solve your problem, but my boot partition is set to bootable (has an *) along with my windows partition, compared to yours which only the windows partition has the * next to it.

Drakeo 12-21-2008 12:48 AM

you need a swap file for linux. you can also in the live cd open a terminal and and type grubconf. then tell it where to put grub grub always looks for the /boot folder. so make sure you have one in side the boot folder better be your kernel vmlinuz. ok now tell grub what hard drive to put the grub folder then tell it to put the boot loader on hda1 or sda1.
even if you boot it it will crash you need a linux file type 82 swap file.
so partition one of you drives cfdisk /dev/dev/sda choose a partition like sda5 if you got know data on it the delete it then remake it a little smaller give your self at least a gig of swap area if your hurting for space nothing under 524 mb. cfdisk /dev/sda choose sda5 or what ever resize it then with the left over free space make a linux primary swap partition type 82 any way after your throughputting grub on the go to the /boot/grub/menu.1st file and make sure it point to your /boot/vmlinuz/ root=/dev/sdXXX
keep hacking you will get it but before you do this you might want to down load super grub so if things go bad you can boot your other windows systems I see in there.

bines 12-21-2008 03:49 AM

Thanks everybody for your valued help. There is a lot to absorb - particularly from Drakeo so I need to go off now and digest it all.

I have got a bit further, syg00 asked if I was logged on as root - I am but it set me to thinking about exactly how I am starting the system from the LiveCD whilst finishing it off. I've been using the excellent hint by Joseph Dupre but realised I didn't fully understand exactly what I'm doing - particularly with regard to populating /dev. I read a line in the LFS book which goes: mount -v --bind /dev/$LFS/dev. When I used this, grub was happy and I continued on. Now I have grub appearing at start-up but it only has my Windows option! LFS is nowhere to be seen on the menu. I can boot into Windows OK.

Unfortunately for me the LFS book does not assume use of the LiveCD so it's not that straightforward for a beginner. Clearly I have more studying to do to fully understand what's required. I am using LFS as an educational project for myself to learn about Linux so that's only to be expected.

I'll post again when I've made progress but meanwhile very many thanks to you all for your most valuable suggestions. I will study them all in detail.

cyphercell 12-23-2008 09:50 PM

chapter 6.4 "Entering the chroot environment" basically covers what you need to do after a reboot. there is also a hint that covers starting over from a saved point. I put all my startup stuff in bash script that I run after mounting the root partition.

bring up the livecd environment and run [fdisk /dev/sda] type "m" for help

type "p" to view your partition scheme. type "a" to toggle the bootable flag on /dev/sda3. You're going to want to change the partition type on /dev/sda5 type "t" to do so, it's going to be on a extended partition so select "e" and pick/type in your partition (been a while since I've used extended). the type is going to be 82 for linux/solaris swap, you can hit "l" to see all available partition types. Type "w" to write your changes to the partition table.

At this point you're going to have to run [mkswap /dev/sda5] to format the swap partition (always remember fdisk doesn't format anything).

Make sure your partitions are all listed in /etc/fstab appropriately.

Go back to the chapter on making the system bootable and make sure that you have your menu.lst file configured properly. Oh, and the find /boot/vmlinuz command didn't work because the kernel is named lfskernel- so you'd use find /boot/lfskernel- (for lfs 6.3). That should get you up and running, or at least past the 21 error. have fun :)

bines 12-24-2008 03:18 PM

Thanks cyphercell for your reply. I've started over again and am currently half-way through chapter 6. I've noted carefully what you have said however and I will ensure that your advice is taken.

I'm very grateful for your input.


All times are GMT -5. The time now is 03:44 AM.