Ubuntu如何编译网卡驱动

By | 2021-01-27

仅供参考

编译环境:
Windows 10 Ubuntu WLS (微软子系统)

演示一:编译intel有线网卡驱动igb-5.4.6

进入驱动src,make编译直接报错

laohu@HUCHANGHUI:~/igb-5.4.6/src$ make
common.mk:82: *** Kernel header files not in any of the expected locations.
common.mk:83: *** Install the appropriate kernel development package, e.g.
common.mk:84: *** kernel-devel, for building kernel modules and try again.  Stop.

安装内核源码
sudo apt-get install linux-headers-$(uname -r)

laohu@HUCHANGHUI:~$ sudo apt-get install linux-headers-$(uname -r)
[sudo] password for laohu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.4.0-19041-Microsoft
E: Couldn't find any package by glob 'linux-headers-4.4.0-19041-Microsoft'
E: Couldn't find any package by regex 'linux-headers-4.4.0-19041-Microsoft'

没有这个内核,真实系统或虚拟机应该是不会出错的

安装通用内核替代
sudo apt-get install linux-headers-generic

安装编译工具包
sudo apt-get install build-essential

因为uname -r 输出的内核版本不存在,所以要修改编译路径

这里创建软连接就可以了
sudo ln -s /usr/src/linux-headers-5.4.0-65-generic /usr/src/linux

sudo make编译成功

演示二:编译realtek 8101网卡驱动

进入src目录编译报错

laohu@HUCHANGHUI:~/realtek-r8101-linux-driver-master/src$ make modules
find: ‘/lib/modules/4.4.0-19041-Microsoft/kernel/drivers/net/ethernet’: No such file or directory
find: ‘/lib/modules/4.4.0-19041-Microsoft/kernel/drivers/net’: No such file or directory
make -C /lib/modules/4.4.0-19041-Microsoft/build M=/home/laohu/realtek-r8101-linux-driver-master/src modules
make[1]: *** /lib/modules/4.4.0-19041-Microsoft/build: No such file or directory.  Stop.
make: *** [Makefile:116: modules] Error 2

同样是编译路径引起,修改Makefile文件

修改后编译成功

2 thoughts on “Ubuntu如何编译网卡驱动

  1. naoki

    common.mk:130: *** Linux kernel source not configured – missing version header file. Stop.

    不知道应该修改哪里呢?

    Reply
    1. laohu Post author

      内核源码配置有问题,加点警告日志打印下路径吧

      Reply

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注