百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> linux 编译内核时网卡驱动丢失如何解决
分享文章到:

linux 编译内核时网卡驱动丢失如何解决

发布时间:01/15 来源: 浏览: 关键词:
Linux在编译内核期间遇到了网卡驱动丢失问题,看看下面我是如何把网卡找回的,有出现类似问题的朋友可以参考一下。

我的系统 OS version : Centos 5.9 kernel : 2.6.18-402 更新内核版本: 2.6.20

由于 yum 里面的内核头文件和卡发包并没有过多的源码 .c 文件。所以只能从 www.kernel.org 下载 相近的版本,有人肯定说了下你还不下个最新的 内核版本,答: 如内核版本跨度比较大,本人担心会出现各种问题,很多老的编译选项新版内核不支持。

首先先下载 原系统的 开发包和头文件:
shell $> yum install kernel-devel kernel-headers
解压 2.6.20 内核压缩包,开始编译内核
shell $> mv linux-2.6.20.tar.bz2 /usr/src/
shell $> cd /usr/src/
shell $> tar jxvf linux-2.6.20.tar.bz2
shell $> cd linux-2.6.20
# 修改源码 更改自己需要的,我修改了 tun 相关的 源码文件。
shell $> make mrproper
# 选择需要的选项和修改的选项,删除多余的选项
shell $> make menuconfig
shell $> make -j 12
shell $> make modules_install
shell $> make install

# 修改 grub.conf 用新内核启动后发现网卡驱动并未发现!但是驱动加载了
2.6.20 shell $> lsmod |grep tg3
# 查看日志:
2.6.20 shell $> vim /var/log/message
# 查找tg3 相关日志:

Feb 26 11:02:01 localhost kernel: input: PC Speaker as /class/input/input1
Feb 26 11:02:01 localhost kernel: tg3: Unknown symbol pci_channel_offline
Feb 26 11:02:01 localhost kernel: intel_rng: Firmware space is locked read-only. If you can't or
Feb 26 11:02:01 localhost kernel: intel_rng: don't want to disable this in firmware setup, and if
Feb 26 11:02:01 localhost kernel: intel_rng: you are certain that your system has a functional
Feb 26 11:02:01 localhost kernel: intel_rng: RNG, try using the 'no_fwh_detect' option.

# 看到了 pci_channel_offline
# 下载对应网卡的驱动,编译安装看是否有错:
shell $> wget http://www.broadcom.com/support/license.php?file=570x/linux-3.136h.zip
shell $> reboot
2.6.20 shell $> unzip linux-3.137h.zip
2.6.20 shell $> tar zxvf tg3-3.136h.tar.gz
2.6.20 shell $> cd tg3-3.136h
2.6.20 shell $> make
# 并没有报错,但是有警告:

sh makeflags.sh /lib/modules/2.6.20/source  > tg3_flags.h
make -C /lib/modules/2.6.20/build SUBDIRS=/data1/software/tg3-3.136h modules
make[1]: Entering directory `/data1/software/linux-2.6.20'
  CC [M]  /data1/software/tg3-3.136h/tg3.o
/data1/software/tg3-3.136h/tg3.c: In function ‘tg3_ape_lock’:
/data1/software/tg3-3.136h/tg3.c:845: 警告:隐式声明函数 ‘pci_channel_offline’
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "pci_channel_offline" [/data1/software/tg3-3.136h/tg3.ko] undefined!
  CC      /data1/software/tg3-3.136h/tg3.mod.o
  LD [M]  /data1/software/tg3-3.136h/tg3.ko
make[1]: Leaving directory `/data1/software/linux-2.6.20'

# 按照常规,警告我们是可以忽略的,那么我们更新这个驱动应该就没问题了,我跟你想的一样可是他还是有问题的
2.6.20 shell $> make install
2.6.20 shell $> rmmod tg3
2.6.20 shell $> modprobe tg3
# 还是报错了,看日志还是 Unknown symbol pci_channel_offline
# 然后我就想 ,那我在老内核里编译看出错吗?结果在老内核里没有报错,我就在看老内核里 的 pci.h 文件,找到了 pci_channel_offline 方法:

static inline int pci_channel_offline(struct pci_dev *pdev)
{
        return (pdev->error_state != pci_channel_io_normal);
}

# 那么好,我把这段 复制到 2.6.20 内核里的 pci.h 里面
2.6.20 shell $> vim /usr/src/linux-2.6.20/include/linux/pci.h
# 加在 183行下面,在从新编译 网卡驱动
2.6.20 shell $> make clean
2.6.20 shell $> make
# 这次 make 没错了
2.6.20 shell $> make install
2.6.20 shell $> rmmod tg3
2.6.20 shell $> modprobe tg3
# 重启网卡
2.6.20 shell $> /etc/init.d/network restart

# 至此解决!




Linux 内核编译,解决网卡驱动缺少的问题


>//Linux 内核编译,解决网卡驱动缺少的问题,使用更新的内核来完善驱动
准备工作
整理出系统硬件、文件系统类型、网络协议
uname -r //查看系统版本号,如果系统与编译的内核一样,需要将/lib/modules 下内容备份
因为将来make modules-install步骤会覆盖整个路径下的内容
{下载linux内核,地址为:http://www.kernel.org/pub/linux/kernel/ ,假设名称为linux-x-y-z.tar.gz
如果内核已经安装,在/usr/src/目录有linux子目录,在光驱中找到kernel-source-2.xx.xx.rpm文件,,如RedHat linuxde RPm目录
是/redhat/RPMS/目录,使用rpm -ivh kernel-source-2.xx.xx.rpm安装内核}

cd /usr/src/linux //清除编译内核时残留的.o文件以及不必要的关联
make mrproper   //如果你是下载的内核代码,并且是第一次编译,就没有必要执行这一个步骤
make xconfig //图形界面下使用,配置内核
{make menyconfig //字符界面下使用}
make dep //设置关联文件
make clean //清理不必要的文件
make bzImage // 编译大内核(比如需要SCSI支持)
{make zImage//编译校内核}
make modules //编译模块,可加载模块,内核选项中为M的选项,编译时间跟M选项的数量有关
make modules_install  //把编译好的modules拷贝到/lib/modules下

A:mv /usr/src/linuxX.X.X/system.map /boot/system.map
B:mv /usr/src/linuxX.X.X/archi/i386/boot/bzImage /boot/vmlinuz //使用新内核
/etc/lilo.conf //修改/etc/lilo.conf 加一个启动选项,使用新内核bzimage or zimage启动

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
linear
default=linux-new    ### 告诉lilo缺省使用新内核启动linux ###
append="mem=256M"

image=/boot/vmlinuz-2.2.14-5.0
        label=linux
        read-only
        root=/dev/hda5

image=/boot/bzImage(zImage)
        label=linux-new
        read-only
        root=/dev/hda5
//方法二:修改grup.conf文件
A:mv /usr/src/linuxX.X.X/system.map /boot/system.map
B:mv /usr/src/linuxX.X.X/archi/i386/boot/bzimage /boot/vmlinuz   //更换内核

//修改grub ,/etc/grup.conf
image=/boot/vmlinuz-2.2.14-5.0
        label=linux
        read-only
        root=/dev/hda5

image=/boot/bzImage(zImage)
        label=linux-new
        read-only
        root=/dev/hda5
 
//方法三:修改启动配置文件  /boot/grub/grub.conf
/*格式如下:
title 显示在启动菜单上的名称
root 根文件系统挂载分区
kernel 压缩过的内核文件名
initrd 根文件系统文件名
              如:
              title My new kernel
              root (hd0,2)
              kernel /boot/vmlinuz-x.y.z
              initrd /boot/initrd-x.y.z.img
*/

//mkinitrd initrd-内核版本号 内核版本号命令重新生成ram磁盘文件
mkinitrd initrd-2.2.14-5.0 2.2.14-5.0
initrd=/boot/initrd-2.2.14-5.0 //把/etc/lilo.conf中的initrd指向新生成的initrd-2.2.14-5.0文件

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有2人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板