LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (http://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   Compiling the kernel (http://www.linuxquestions.org/questions/linux-from-scratch-13/compiling-the-kernel-913127/)

devilboy09 11-12-2011 03:43 AM

Compiling the kernel
 
i've compiled the kernel for several times and i know how to do it.
this what i do, usually:
copy linux-3.1.tg.bz2 to /usr/src
tar jxvf linux-3.1.tg.bz2
cd linux-3.1
make menuconfig-->choose afew modules
make
make bzImage
make modules
make modules_install
make install
mkinitramfs -k -o /boot/initrd-3.1 3.1
update-grub

but in the book the compiling is very short!!!
is it safe to follow the book?
is it gonna compile correctly?

Roken 11-12-2011 04:47 AM

The book method works just fine, but you will have to setup grub yourself (all part of the fun).

devilboy09 11-12-2011 05:06 AM

i did what the book says.but i didn't install grub.when i compile the kernel i logout from chroot and issued update-grub and grub recognized my lfs on disk 2.but in boot time i got this error:
kernel panic-not syncing:VFS:Unable to mount root fs on unknown-block(2,0)

and here is the grub configuration:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi

function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}

function recordfail {
set recordfail=1
if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}

function load_video {
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
}

insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=auto
load_video
insmod gfxterm
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
set locale_dir=($root)/boot/grub/locale
set lang=en_US
insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
set timeout=-1
else
set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30; then
clear
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
if [ ${recordfail} != 1 ]; then
if [ -e ${prefix}/gfxblacklist.txt ]; then
if hwmatch ${prefix}/gfxblacklist.txt 3; then
if [ ${match} = 0 ]; then
set linux_gfx_mode=keep
else
set linux_gfx_mode=text
fi
else
set linux_gfx_mode=text
fi
else
set linux_gfx_mode=keep
fi
else
set linux_gfx_mode=text
fi
export linux_gfx_mode
if [ "$linux_gfx_mode" != "text" ]; then load_video; fi
menuentry 'Ubuntu, with Linux 3.0.0-12-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
linux /boot/vmlinuz-3.0.0-12-generic root=UUID=9d23a708-c101-428e-9443-77455bd0e1de ro quiet splash vt.handoff=7
initrd /boot/initrd.img-3.0.0-12-generic
}
menuentry 'Ubuntu, with Linux 3.0.0-12-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
echo 'Loading Linux 3.0.0-12-generic ...'
linux /boot/vmlinuz-3.0.0-12-generic root=UUID=9d23a708-c101-428e-9443-77455bd0e1de ro recovery nomodeset
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-3.0.0-12-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 9d23a708-c101-428e-9443-77455bd0e1de
linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Linux From Scratch (7.0) (on /dev/sdb1)" --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root='(hd1,msdos1)'
search --no-floppy --fs-uuid --set=root b63652fc-a69d-462b-9fbf-637514180bb6
linux /boot/vmlinuz-3.1-lfs-7.0 root=/dev/sdb1
}
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

and here is the content of fstab on my host system:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=9d23a708-c101-428e-9443-77455bd0e1de / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=f85bafa5-e848-47a3-8422-e5f2a790699c none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
/dev/sdb1 /mnt/lfs ext4 auto,rw 0 0
/dev/sdb2 swap swap 0 0

and on lfs(chroot envirement):
# Begin /etc/fstab
# file system mount-point type options dump fsck
/dev/sdb1 / ext4 defaults 1 1
/dev/sdb2 swap swap 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devpts /dev/pts devpts gid=4,mode=620 0 0
tmpfs /run tmpfs defaults 0 0
#

# End /etc/fstab

devilboy09 11-12-2011 07:30 AM

guys come on.this is the last section of lfs and i'm very unhappy with this problem!!!

devilboy09 11-12-2011 07:49 AM

one question.shouldn't be a initiam ram disk in /boot directory.the book says nothing about making initrd!!!

Roken 11-12-2011 07:59 AM

add this to /etc/grub.d/40_custom

Code:

menuentry "GNU/Linux, Linux 3.1-lfs-7.0" {
        insmod ext2
        set root=(hd1,3)
        linux  /boot/vmlinuz-3.1-rokenln root=/dev/sdb3 ro
}

Make the necessary change to vmlinuz name, set root and root=

Save and sudo update-grub. This should give you an additional working entry in grub.

devilboy09 11-12-2011 08:14 AM

i did what you say i got the same error.but i create initrd from my host for lfs : mkinitramfs -k -o /mnt/lfs/initrd-3.1 3.1 (i issued this from host os while i'm in /mnt/lfs/usr/src/linux-3.1 directory)
now i got a new error:
could not load:/lib/modules/3.1.0/Modules.dep:no such a file or directory
ALERT /dev/sdb1 does not exist Dropping to a shell
and this error puts me in busybox

Roken 11-12-2011 09:25 AM

I haven't used mkinitramfs but a couple of things that you could try:

In the 40_custom replace root=/dev/sdbx with root=uuid=<uuid of drive>

You can get the uuid from blkid on the host system. Then update-grub

If that fails, try running mkinitramsfs from within the chroot.

One other thing - you need to mount /boot within lfs to point to your usual /boot folder which I'm guessing is /boot within your host filesystem. I had less of a problem with this because I have a separate /boot partition, but it should be easy enough to add an fstab entry for this.

devilboy09 11-12-2011 11:35 AM

none of them worked!!!
one question.is it even possible to boot a linux without the initial ram disk(initrd)?
i'm pretty sure that's the problem.but the books says nothing about it

Roken 11-12-2011 11:41 AM

I booted no problems without initrd. As I said, it may be helped here by maintaining a separate /boot partition, though I can see no reason why the approach outlined shouldn't work.

Something worth checking (and an error I made first time around) is that your vmlinuz file is actually vmlinuz-xxxxxxx. It's very easy to mistype it and call it vnlinux-xxxxxxxx instead.

druuna 11-13-2011 04:12 AM

Hi devilboy09,

You really need to trust the steps in the LFS book, they are correct and work. Mixing what is in the book with methods used by other distro's _will_ get you into trouble and you'll end up with a none working/bootable LFS.

About the kernel compilation steps, these are all you need:
Code:

# from within the chrooted environment, as root user:
# the next 2 steps only need to be done once:

copy linux-3.1.tg.bz2 to /usr/src
tar jxvf linux-3.1.tg.bz2

# these 7 steps need to be done when (re)compiling the kernel:
cd /usr/src/linux-3.1
make mrproper
make menuconfig
make modules_install
cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.1-lfs-7.0
cp -v System.map /boot/System.map-3.1
cp -v .config /boot/config-3.1

# these 2 steps only need to be done once:
install -d /usr/share/doc/linux-3.1
cp -r Documentation/* /usr/share/doc/linux-3.1

About the make menuconfig step: You do have to make sure that the correct options are activated, either as static or module, failing to do so can result in a none-working system.


About initrd: LFS does _not_ use it and it is not needed to boot LFS. There is an LFS hint (initrd for LFS) that describes all the steps needed to use initrd with LFS. But I would not do this unless you have a very good reason for it!!


If you need to update your grub configuration you need to do so from your host (_not_ from within the chrooted environment). The grub entry for LFS you posted looks OK, but can probably be simplified to this for the LFS entry (assuming /dev/sdb1):
Code:

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Linux From Scratch (7.0) (on /dev/sdb1)" --class gnu-linux --class gnu --class os {
insmod ext2
set root=(hd1,1)
menuentry "GNU/Linux, Linux 3.1-lfs-7.0" {
        linux  /boot/vmlinuz-3.1-lfs-7.0 root=/dev/sdb1 ro
}

BTW: You don't need to run update-grub every time you re-build the kernel, as long as the image name stays the same (this part: /boot/vmlinuz-3.1-lfs-7.0).


If I look at your /etc/fstab files I do see some stuff that you might not need:
Code:

# on your host

# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=9d23a708-c101-428e-9443-77455bd0e1de / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=f85bafa5-e848-47a3-8422-e5f2a790699c none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
/dev/sdb1 /mnt/lfs ext4 auto,rw 0 0
/dev/sdb2 swap swap 0 0

Both blue and red entries can be removed.
- Do you really need 2 activated swap partitions (the red and green part) when booting into your host?
- The blue part might be handy if you need to access/edit your LFS system from your host, but you do need to remember that these are 2 separate systems.
As I already mentioned, I would remove the blue and red entries. If you do need access to the LFS system from your hosts system, mount it manually.

The /etc/fstab file you created for LFS looks fine.

As stated by Roken: A separate /boot partition would be a good idea, but is not actually needed to get a working system (it might even complicate things a bit).

Do take Roken's advice and check to see if you didn't make a typo/copy mistake somewhere.

Hope this gets you going again.

devilboy09 11-13-2011 04:24 AM

thank you for your answer
if i want to re-compile the kernel is there any particular file that i need to delete?
i want to do the whole process again
by the way, the sdb1 has ext4 filesystem type.and in make menuconfig step i did choose it as built-in.should i choose it as module?

druuna 11-13-2011 05:01 AM

Hi,
Quote:

Originally Posted by devilboy09 (Post 4522724)
thank you for your answer

You're welcome :)

Quote:

if i want to re-compile the kernel is there any particular file that i need to delete?
i want to do the whole process again
No, you don't. There is one thing you should remember: After running the make mrproper step the .config file is removed. If you want to edit the kernel and use your current configuration as a starting point you need to add one step to the kernel build steps I posted earlier (the green entry):
Code:

# these 7 steps need to be done when (re)compiling the kernel:
cd /usr/src/linux-3.1
make mrproper
cp /boot/config-3.1 .config
make menuconfig
make modules_install
cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.1-lfs-7.0
cp -v System.map /boot/System.map-3.1
cp -v .config /boot/config-3.1


Quote:

by the way, the sdb1 has ext4 filesystem type.and in make menuconfig step i did choose it as built-in.should i choose it as module?
I would make the FS (ext2/3/4 etc) entries static, not modular.

I personally like to make my kernel as static as possible and I also remove all that isn't needed for my hardware/setup (I have to admit that you need experience to do so). For now try to get a working kernel and don't bother with static/modular or removing unneeded stuff, that is of possible later concern.

Hope this helps.

Roken 11-13-2011 08:36 AM

Oddly, after a moment of madness yesterday I managed to completely trash my own LFS build, so I spent the day rebuilding and am hitting the same problem now. I'm still investigating but I'm 90% certain that it's a kernel problem rather than a grub problem. I'll post back when I have the answer.

devilboy09 11-13-2011 08:54 AM

i think the kernel is the problem, too.grub can not find the root partiton on /dev/sdb1


All times are GMT -5. The time now is 06:37 PM.