求助!!! 关于插入模块的错误和重新编译内核...

45 views
Skip to first unread message

陈磊

unread,
Mar 2, 2011, 10:54:51 PM3/2/11
to xiyoulinux
我的环境是ubuntu10.04   2.6.32-24的内核  编写模块
这个是makefile

obj-m := hello.o
kernel_path = /usr/src/linux-headers-$(shell uname -r)
all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
                                                                              
执行make命令时提示
make -C /lib/modules/2.6.32-24-generic/build M=/home/lost/Programs/C modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic'
  CC [M]  /home/lost/Programs/C/hello.o
In file included from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/lost/Programs/C/hello.c:2:
include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory
include/linux/mmzone.h:258:5: warning: "MAX_NR_ZONES" is not defined
include/linux/mmzone.h:260:7: warning: "MAX_NR_ZONES" is not defined
include/linux/mmzone.h:262:7: warning: "MAX_NR_ZONES" is not defined
In file included from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/lost/Programs/C/hello.c:2:
include/linux/mmzone.h:300: error: ‘MAX_NR_ZONES’ undeclared here (not in a function)
make[2]: *** [/home/lost/Programs/C/hello.o] Error 1
make[1]: *** [_module_/home/lost/Programs/C] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-24-generic'
make: *** [all] Error 2

其中那个bounds.h 找不到... 在网上各种资料查找后 说可能在编译内核的时候make clean 过 所以那个h文件就被删除了  解决方法是
在 /lib/modules/2.6.32-24-generic/build 下  执行make prepare
make prepare 之后再次提示错误
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-x86
make[1]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'.  Stop.
make: *** [prepare0] Error 2

再次谷歌百度...
网上说可以通过重新编译内核解决...请问学长对上述问题有什么解决办法么??




于是手动开始重新编译内核  下载最新稳定版本 2.6.37.2
重新编译后  sudo update-grub
重启...
载入内核成功 但是又出现错误...
"an error occured while mounting /"
“press s to skip or m for manual ....”
但是按下s 之后进入控制台界面 在控制台界面下登录正常 但是不能进入ubuntu的图形界面
在控制台界面下输入
uname -r 
显示
2.6.23.2
输入df -l
显示 / 已经被挂载...
继续谷歌百度...

网上有类似的问题 但没有说挂不上根文件系统的...
我列举一下我的fstab 文件 和grub.cfg 文件
#fstab
#proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda8 during installation
UUID=4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda9 during installation
UUID=4e8ae8ce-2f32-40d2-9483-0f33c24547ad none            swap    sw              0       0
/dev/sda6       /media/MEDIA    ntfs    auto,rw 0       0
/dev/sda1       /media/SYSTEM   ntfs    auto,rw 0       0

#grub
if [ -s $prefix/grubenv ]; then
  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
}
insmod ext2
set root='(hd0,8)'
search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=640x480
  insmod gfxterm
  insmod vbe
  if terminal_output gfxterm ; then true ; else
    # For backward compatibility with versions of terminal.mod that don't
    # understand terminal_output
    terminal gfxterm
  fi
fi
insmod ext2
set root='(hd0,8)'
search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
set locale_dir=($root)/boot/grub/locale
set lang=en
insmod gettext
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
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.37.2' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    linux    /boot/vmlinuz-2.6.37.2 root=/dev/sda8 ro   quiet splash
}
menuentry 'Ubuntu, with Linux 2.6.37.2 (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    echo    'Loading Linux 2.6.37.2 ...'
    linux    /boot/vmlinuz-2.6.37.2 root=/dev/sda8 ro single
    echo    'Loading initial ramdisk ...'
}
menuentry 'Ubuntu, with Linux 2.6.32-24-generic' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    linux    /boot/vmlinuz-2.6.32-24-generic root=UUID=4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc ro   quiet splash
    initrd    /boot/initrd.img-2.6.32-24-generic
}
menuentry 'Ubuntu, with Linux 2.6.32-24-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    echo    'Loading Linux 2.6.32-24-generic ...'
    linux    /boot/vmlinuz-2.6.32-24-generic root=UUID=4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc ro single
    echo    'Loading initial ramdisk ...'
    initrd    /boot/initrd.img-2.6.32-24-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    linux16    /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
    insmod ext2
    set root='(hd0,8)'
    search --no-floppy --fs-uuid --set 4b4a8477-0ed0-4bf8-9c32-f2d2b1132bfc
    linux16    /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Microsoft Windows XP Professional (on /dev/sda1)" {
    insmod ntfs
    set root='(hd0,1)'
    search --no-floppy --fs-uuid --set 06d07950d07946c9
    drivemap -s (hd0) ${root}
    chainloader +1
}

求指教...

刘周平

unread,
Mar 3, 2011, 12:03:56 AM3/3/11
to 陈磊, xiyoulinux
在 2011年3月3日 上午11:54,陈磊 <losemy...@gmail.com>写道:
我的环境是ubuntu10.04   2.6.32-24的内核  编写模块
这个是makefile

obj-m := hello.o
kernel_path = /usr/src/linux-headers-$(shell uname -r)
all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
                                                                              
执行make命令时提示
make -C /lib/modules/2.6.32-24-generic/build M=/home/lost/Programs/C modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic'
  CC [M]  /home/lost/Programs/C/hello.o
In file included from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/lost/Programs/C/hello.c:2:
include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory
这个问题我之前遇到过, 你可以尝试复制一份其他人系统中的bounds.h文件到相应的目录中, 或者就是重新编译一个新内核(你可以不用新内核作为你的os内核,
只用它作为开发使用, 这样你就可以避免下面那个不能正常启动的问题了)。
这个问题我那时也没有找到具体的方法, 可能是ubuntu 内核的一个bug吧, 换一个内核应该可以! 
你这里缺少 initrd 选项! 检查一下编印内核时是否已经生成该文件了。 

--
要退订此论坛请发邮件至 xiyoulinux-...@googlegroups.com
更多选项: http://groups.google.com/group/xiyoulinux?hl=zh-CN
提问前建议您阅读:http://www.xiyoulinux.cn/blog/?p=64
也请查看我们的FAQ:http://xiyoulinux.cn/wiki/index.php?title=FAQ

陈磊

unread,
Mar 3, 2011, 2:15:34 AM3/3/11
to 刘周平, xiyoulinux
谢谢刘周平学长~~ 
我通过更换内核解决了“an error occured while mounting /” 问题
由于我之前使用的是2.6.37.2的内核
现在我又换了内核2.6.36.4  换成这个内核就不会出现 “an error occured.....” 这种问题了
刘周平学长说我在grub.cfg这个文件中没有initrd这个选项 原因是因为当初建立内核时名字没有统一  所以在grub-mkconfig的时候不能自动创建这一项...
统一名称之后再次grub-mkconfig时就可以了~
Reply all
Reply to author
Forward
0 new messages