ubuntu配置linux内核,Linux内核调试环境搭建(基于ubuntu12.04)

一、测试环境

物理机:ubuntu16.04 LTS

target(被调试机)环境:VirtualBox 5.0.20+ubuntu 12.04 LTS + linux kernel 3.0.4

host(调试机)环境:VirtualBox 5.0.20+ubuntu 12.04 LTS + gdb

二、搭建虚拟机环境

安装VirtualBox 然后

新建一个标准的虚拟机镜像就OK!然后加载ISO一步一步安装就行!(磁盘大小最好稍微大点,大约40G已经相当够用了) 我安装的是ubuntu 12.04 上述已经说明环境!下同

安装完毕后点击设置 如图进行串口设置

0e641e5a3d2fd5b295d0ef972779937b.png

说明:这里的com1 即是 系统里面的/dev/ttyS0,然后启动系统。

三、编译以及安装内核

到内核官网下载你自己需要调试的内核版本!(https://www.kernel.org/pub/linux/kernel/)

这里我下的是3.0.4,解压到/opt目录下,然后转到linux-3.0.4目录,复制现有内核的config 到 当前目录为 .config

rroot@netfairy-VirtualBox:/opt/linux-3.0.4# cp /boot/config-3.2.0-29-generic-pae .config

执行

make menuconfig

注意这里可能会出现

*** Unable to find the ncurses libraries or the

*** required header files.

*** 'make menuconfig' requires the ncurses libraries.

***

*** Install ncurses (ncurses-devel) and try again.

***

make[1]: *** [scripts/kconfig/dochecklxdialog] 错误 1

make: *** [menuconfig] 错误 2

那么就需要执行下面一条命令

sudo apt-get install libncurses5-dev

然后开始配置内核

root@netfairy-VirtualBox:/opt/linux-3.0.4# make menuconfig

(下面配置为必须进行的)

位置:

General setup--->

-> Prompt for development and/or incomplete code/drivers

Kernel hacking--->

-*- Magic SysRq key //默认选上了

[*] Kernel debugging //默认选上了

[*] Compile the kernel with debug info //默认选上了

[*] KGDB: kernel debugging with remote gdb ---> //默认选上了

KGDB: use kgdb over the serial console //默认选上了

[*]KGDB:allow debugging with traps in notifiers //默认选上了,别选别的

[] Write protect kernel read-only data struct ures

四、编译内核

执行

make -j4

执行

make modules_install

执行

make install

编译安装已经完毕

五、修改grub

将下面内容修改,下面两个图盗别人的

6599332561587249713.png

修改后为

6608824645468554525.png

其实就是删除第131 行 和 155 行

然后在

linux /boot/vmlinuz-2.6.32.61 root=UUID=f8c18f80-7723-470b-98a852566006 ro

后面 和

quiet

前面加以下内容

kgdb=ttyS0,115200 kgdboc=ttyS0,115200 kgdbwait

然后保存退出即可!重启电脑,克隆一台一模一样的虚拟机作为host机,修改串口如下

然后启动target机器,如图,选择

0de5d58a036fcf270bf3b7847bd036e1.png

选择要调试的内核,出现下面这样子表明成功(如果不出现的话重启试试)

3fba462c13e0492976e0e84f8646cd9b.png

然后启动host机器,选择原来的内核,正常登入系统

d2f8fa8685b05cfde824bbcd2349f3d2.png

切换到要调试的内核目录

root@netfairy-VirtualBox:/home/netfairy# cd /opt/linux-3.0.4/

然后

root@netfairy-VirtualBox:/opt/linux-3.0.4# gdb vmlinux

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04

Copyright (C) 2012 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type "show copying"

and "show warranty" for details.

This GDB was configured as "i686-linux-gnu".

For bug reporting instructions, please see:

...

Reading symbols from /opt/linux-3.0.4/vmlinux...done.

接着

set remotebaud 115200

最后

(gdb) target remote /dev/ttyS0

Remote debugging using /dev/ttyS0

kgdb_breakpoint () at kernel/debug/debug_core.c:960

960wmb(); /* Sync point after breakpoint */

然后continue就可以让target跑起来了

如果需要断下来,在被调试机的终端执行

echo g > /proc/sysrq-trigger

517bd7253d1abdbcc6c8e3b1874f25d8.png

六、下面是我遇到的一些问题和解决办法:

问题一:

gcc: error: elf_i386: No such file or directory

OBJCOPY arch/x86/vdso/vdso32-int80.so

objcopy: 'arch/x86/vdso/vdso32-int80.so.dbg': No such file

make[2]: *** [arch/x86/vdso/vdso32-int80.so] Error 1

make[1]: *** [arch/x86/vdso] Error 2

make: *** [arch/x86] Error 2

解决:

In arch/x86/vdso/Makefile :

replace "-m elf_x86_64" by "-m64" on the line starting with VDSO_LDFLAGS_vdso.lds

replace "-m elf_i386" by "-m32" on the line starting with VDSO_LDFLAGS_vdso32.lds

问题二:

In file included from drivers/net/igbvf/ethtool.c:36:0:

drivers/net/igbvf/igbvf.h: 在文件作用域:

drivers/net/igbvf/igbvf.h:128:15: 错误: 重复的成员‘page’

make[4]: *** [drivers/net/igbvf/ethtool.o] 错误 1

make[3]: *** [drivers/net/igbvf] 错误 2

make[2]: *** [drivers/net] 错误 2

make[1]: *** [drivers] 错误 2

make[1]:正在离开目录 `/usr/src/linux-2.6.32.2'

make: *** [debian/stamp/build/kernel] 错误 2

解决:

打开igbvf.h:,看128行,代码为:struct page *page;再往上看,第123行,也有struct page *page这行代码,这个结构定义在内部的一个结构体中。就是他的名字与128行的重复了,而4.6.3的编译器对不支持这种方式的定义,我们修改128行的代码为struct page *pagep;保存退出;

问题三:VirtualBox里Ubuntu的共享文件夹无法访问 之问题:You do not have the permissions necessary to view the contents of ‘shared_folder’

解决:sudo usermod -a -G vboxsf netfairy

问题四:

安装好新内核,但是开机直接进入系统,无内核选择菜单

解决:

编辑 /boot/grub/grub.cfg

找到 timeout 【注:第二个地方的那几个timeout】数字改为10,保存。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu 12.04中进行网络配置有以下步骤: 1. 打开网络配置文件 /etc/network/interfaces:sudo vim /etc/network/interfaces 2. 如果要配置动态获取IP地址,添加以下内容: ``` auto eth0 iface eth0 inet dhcp ``` 3. 如果要配置静态IP地址,添加以下内容(根据实际情况修改IP地址、子网掩码和网关): ``` auto eth0 iface eth0 inet static address 192.168.1.201 netmask 255.255.255.0 gateway 192.168.1.1 ``` 4. 重启网络接口使配置生效: ``` sudo ifconfig eth0 down sudo ifconfig eth0 up ``` 5. 使用 ifconfig 命令检查IP地址是否配置成功。 6. 如果仍然无法上网,可能是DNS服务器未配置。编辑 /etc/resolv.conf 文件并添加DNS服务器地址: ``` nameserver 8.8.8.8 nameserver 8.8.4.4 ``` 注意,如果 /etc/resolv.conf 文件是从 /etc/resolvconf/resolv.conf.d/head 文件加载的,可以直接编辑 head 文件添加上述两行配置: ``` sudo vim /etc/resolvconf/resolv.conf.d/head ``` 7. 保存修改后,重启网络服务使配置生效: ``` sudo /etc/init.d/networking restart ``` 以上是在Ubuntu 12.04中进行网络配置的步骤,通过按照上述步骤进行配置,您应该能够成功连接到互联网。如果仍然无法连接,请尝试重新启动机器。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ubuntu12.04 server 配置网络](https://blog.csdn.net/weixingstudio/article/details/7912572)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ubuntu 12.04 网络设置](https://blog.csdn.net/PHPData/article/details/12655733)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值