linux-4.1.1 user mode linux(UML)试用

原创 2015年07月08日 23:14:07

一、主要资料

http://uml.devloop.org.uk/
http://uml.devloop.org.uk/howto.html

百度


二、起因

想学习linux内核网络,通过VMware和KGDB来调试,机器受不了,编译也慢。初步弄完UML之后,发现

采用UML调试和学习还是比较快的。


三、环境

一台上互联网的机器,好几年前的PC,window7操作系统,装VMWorkStation 10。采用PPoe上网,IP地址:192.168.0.101,

路由器192.168.0.1。


四、安装REHL6.4-i386

虚拟机安装,过程简单。装好后,不知为何不能上网,把网卡改成桥模式,自己配了个IP地址: 192.168.0.200,加了个默认网关,

手工写了个DNS(查看windows 机器的:ipconfig /all):

ifconfig eth0 192.168.0.200

     route add default gw 192.168.0.1

手工编辑 /etc/resolv.conf添加DNS。

vi /etc/resolv.conf 内容如下:
nameserver      221.228.255.1
nameserver      218.2.135.1

ping www.sohu.com,能通。


五、编译

进入REHL6.4;

下载4.1.1源码,解压;

将最顶层 Makefile 文件中的优化选项进行修改 -O2 改成 -O1;

make ARCH=um defconfig
make ARCH=um menuconfig
make ARCH=um 
make ARCH=modules
make ARCH=moduels_install

最后一步会将模块拷贝到/lib/modules目录下,后面要用。


六、下载文件系统并更新

http://fs.devloop.org.uk/

我下载的是 CentOS 6.x 32bit;

解压得到 CentOS6.x-x86-root_fs,工作目录就是linux源码所在目录;

mkdir  ram
mount  CentOS6.x-x86-root_fs  ram/ -o loop
cd  ram/lib/modules/
cp  /lib/modules/4.1.1 . -rf

cd 工作目录

umount ram

注意:如果不将模块考入,启动UML会有烦人的打印显示。


七、启动

./linux ubda=CentOS6.x-x86-root_fs

退出:关机即可,输入: init  0


八、与REHL6.4网络互通

下面步骤在主机REHL6.4上执行:

iptalbels -F (免得误伤,ping的时候不通)
tunctl  -t  tap1 (安装虚拟网卡)
ifconfig tap1 192.168.3.1 (配置虚拟网卡地址)
vi ~/dhcp.conf:

default-lease-time 6000;
max-lease-time 72000;
option domain-name-servers 192.168.3.1;
option routers 192.168.3.1;
server-name "192.168.3.1";
ddns-update-style none;
subnet  192.168.3.0  netmask  255.255.255.0  {
 range 192.168.3.100 192.168.3.254;
}

dhcpd -cf ~/dhcp.conf tap1 (开启DHCP服务)

执行编译出来的linxu:

./linux ubda=CentOS6.x-x86-root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.3.254 con0=fd:0,fd:1

UML进入后ping 192.168.3.1 能通;
注:

1.tunctl/dhcpd命令如未安装,rpm安装一下,就在REHL6.4光盘里面;

2.tap1 ip地址不要搞成192.168.0.X网段了;

3.也可以不采用DHCP,进入客户机后如能看到eth0,手工配置也可以;

4.不采用DHCP启动网卡时很慢,并且有可能进去后eth0没有。



九、上外网

客户机UML:

echo 1 > /proc/sys/net/ipv4/ip_forward
route add default gw 192.168.3.1
vi /etc/resolv.conf  添加内容如下,与windows相同

nameserver      221.228.255.1

nameserver      218.2.135.1

在主机REHL6.4上执行:
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
iptables -I FORWARD -i tap1 -j ACCEPT
iptables -I FORWARD -o tap1 -j ACCEPT

客户机UML:ping www.sohu.com能通。


十、GDB

采用让客户机直接运行,主机gdb attach linux,可以随时添加断点

如果直接在gdb中运行linux,启动后都不知道如何退出操作系统进入gdb....。


在主机上查看进程号 
ps -aef | grep linux
root     21029  2774 14 06:43 pts/0    00:00:20 ./linux ubda=CentOS6.x-x86-root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.3.254 con0=fd:0,fd:1
root     21034 21029  0 06:43 pts/0    00:00:00 ./linux ubda=CentOS6.x-x86-root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.3.254 con0=fd:0,fd:1
root     21035 21029  1 06:43 pts/0    00:00:02 ./linux ubda=CentOS6.x-x86-root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.3.254 con0=fd:0,fd:1
root     21036 21029  0 06:43 pts/0    00:00:00 ./linux ubda=CentOS6.x-x86-root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.3.254 con0=fd:0,fd:1
root     21037 21029  0 06:43 pts/0    00:00:00 [linux]
root     21167 21029  0 06:43 pts/0    00:00:00 [linux]
root     21316 21029  0 06:43 pts/0    00:00:00 [linux]
root     21632 21029  0 06:44 pts/0    00:00:00 [linux]
root     21733 21029  0 06:44 pts/0    00:00:00 [linux]
root     21758 21029  0 06:44 pts/0    00:00:00 [linux]
root     21765 21029  0 06:44 pts/0    00:00:00 [linux]

gdb子进程号:21029  
gdb ./linux
attach 21029  
c

客户机正常运行......

gdb窗口按CTRL+C,进入gdb:

gdb:
^C
Program received signal SIGINT, Interrupt.
0x002c3424 in __kernel_vsyscall ()
(gdb) b uml_net_start_xmit
Breakpoint 2 at 0x80648c3: file arch/um/drivers/net_kern.c, line 212.
(gdb) c
Continuing.
Detaching after fork from child process 21872.
Detaching after fork from child process 21876.

客户机继续运行,客户机执行: ping 221.228.255.1,gdb命令窗口:

Breakpoint 2, uml_net_start_xmit (skb=0xa32d6e0, dev=0xa1ee800) at arch/um/drivers/net_kern.c:212
212             struct uml_net_private *lp = netdev_priv(dev);
(gdb) n
216             netif_stop_queue(dev);
(gdb) p skb
$1 = (struct sk_buff *) 0xa32d6e0
(gdb) p *skb
$2 = {{{next = 0x0, prev = 0xa32d6e0, {tstamp = {tv64 = 0}, skb_mstamp = {{v64 = 0, {stamp_us = 0, stamp_jiffies = 0}}}}}, rbnode = {__rb_parent_color = 0, 
      rb_right = 0xa32d6e0, rb_left = 0x0}}, sk = 0xa0ec920, dev = 0xa1ee800, cb = "b", '\000' <repeats 46 times>, _skb_refdst = 0, destructor = 0x8218f15 <sock_wfree>, 
  sp = 0x0, len = 98, data_len = 0, mac_len = 0, hdr_len = 0, queue_mapping = 0, cloned = 1 '\001', nohdr = 0 '\000', fclone = 0 '\000', peeked = 0 '\000', 
  head_frag = 0 '\000', xmit_more = 0 '\000', headers_start = 0xa32d6e0, __pkt_type_offset = 0xa32d6e0 "", pkt_type = 0 '\000', pfmemalloc = 0 '\000', ignore_df = 1 '\001', 
  nfctinfo = 0 '\000', nf_trace = 0 '\000', ip_summed = 0 '\000', ooo_okay = 0 '\000', l4_hash = 0 '\000', sw_hash = 0 '\000', wifi_acked_valid = 0 '\000', 
  wifi_acked = 0 '\000', no_fcs = 0 '\000', encapsulation = 0 '\000', encap_hdr_csum = 0 '\000', csum_valid = 0 '\000', csum_complete_sw = 0 '\000', csum_level = 0 '\000', 
  csum_bad = 0 '\000', ipvs_property = 0 '\000', inner_protocol_type = 0 '\000', remcsum_offload = 0 '\000', {csum = 3827571675, {csum_start = 7131, csum_offset = 58404}}, 
  priority = 0, skb_iif = 0, hash = 0, vlan_proto = 0, vlan_tci = 0, {napi_id = 0, sender_cpu = 0}, {mark = 0, reserved_tailroom = 0}, {inner_protocol = 0, 
    inner_ipproto = 0 '\000'}, inner_transport_header = 0, inner_network_header = 0, inner_mac_header = 0, protocol = 8, transport_header = 36, network_header = 16, 
  mac_header = 2, headers_end = 0xa32d6e0, tail = 0xa129464 "", end = 0xa129540 "", head = 0xa129400 "", data = 0xa129402 "~蹠OB\004\376", <incomplete sequence \360>, 
  truesize = 704, users = {counter = 1}}
(gdb) where
#0  uml_net_start_xmit (skb=0xa32d6e0, dev=0xa1ee800) at arch/um/drivers/net_kern.c:216
#1  0x0822c218 in __netdev_start_xmit (first=0xa32d6e0, dev=0xa1ee800, txq=0xa176c00, ret=0x8ea7a80) at include/linux/netdevice.h:3610
#2  netdev_start_xmit (first=0xa32d6e0, dev=0xa1ee800, txq=0xa176c00, ret=0x8ea7a80) at include/linux/netdevice.h:3619
#3  xmit_one (first=0xa32d6e0, dev=0xa1ee800, txq=0xa176c00, ret=0x8ea7a80) at net/core/dev.c:2654
#4  dev_hard_start_xmit (first=0xa32d6e0, dev=0xa1ee800, txq=0xa176c00, ret=0x8ea7a80) at net/core/dev.c:2670
#5  0x08243b03 in sch_direct_xmit (skb=0xa32d6e0, q=0xa170c00, dev=0xa1ee800, txq=0xa176c00, root_lock=0xa170c68, validate=true) at net/sched/sch_generic.c:165
#6  0x0822c499 in __dev_xmit_skb (skb=0xa32d6e0, accel_priv=<value optimized out>) at net/core/dev.c:2840
#7  __dev_queue_xmit (skb=0xa32d6e0, accel_priv=<value optimized out>) at net/core/dev.c:2965
#8  0x0822c64f in dev_queue_xmit_sk (sk=0xa0ec920, skb=0xa32d6e0) at net/core/dev.c:3031
#9  0x08236984 in dev_queue_xmit (neigh=0xa170100, skb=0xa32d6e0) at include/linux/netdevice.h:2178
#10 neigh_resolve_output (neigh=0xa170100, skb=0xa32d6e0) at net/core/neighbour.c:1291
#11 0x08253cce in dst_neigh_output (sk=<value optimized out>, skb=0xa32d6e0) at include/net/dst.h:421
#12 ip_finish_output2 (sk=<value optimized out>, skb=0xa32d6e0) at net/ipv4/ip_output.c:206
#13 ip_finish_output (sk=<value optimized out>, skb=0xa32d6e0) at net/ipv4/ip_output.c:276
#14 0x08253d8c in ip_output (sk=0xa0ec920, skb=0xa32d6e0) at net/ipv4/ip_output.c:348
#15 0x082509e8 in dst_output_sk (sk=0xa0ec920, skb=0xa32d6e0) at include/net/dst.h:458
#16 ip_local_out_sk (sk=0xa0ec920, skb=0xa32d6e0) at net/ipv4/ip_output.c:115
#17 0x0825143b in ip_local_out (net=0x83589c0, skb=0xa32d6e0) at include/net/ip.h:119
#18 ip_send_skb (net=0x83589c0, skb=0xa32d6e0) at net/ipv4/ip_output.c:1419
#19 0x08251efd in ip_push_pending_frames (sk=0xa0ec920, fl4=0x8ea7c6c) at net/ipv4/ip_output.c:1439
#20 0x0827352a in raw_sendmsg (sk=0xa0ec920, msg=0x8ea7e08, len=64) at net/ipv4/raw.c:641
#21 0x0828043a in inet_sendmsg (sock=0x9c8fb80, msg=0x8ea7e08, size=64) at net/ipv4/af_inet.c:730
#22 0x08214313 in sock_sendmsg_nosec (sock=0x9c8fb80, msg=0x8ea7e08) at net/socket.c:613
#23 sock_sendmsg (sock=0x9c8fb80, msg=0x8ea7e08) at net/socket.c:623
#24 0x082158ed in ___sys_sendmsg (sock=<value optimized out>, msg=<value optimized out>, msg_sys=0x8ea7e08, flags=0, used_address=0x0) at net/socket.c:1955
#25 0x08215aae in __sys_sendmsg (fd=3, msg=0x80009a34, flags=0) at net/socket.c:1989
#26 0x08215aea in SYSC_sendmsg (fd=3, msg=-2147444172, flags=0) at net/socket.c:2000
#27 SyS_sendmsg (fd=3, msg=-2147444172, flags=0) at net/socket.c:1996
#28 0x082148f5 in SYSC_socketcall (call=16, args=-1077791504) at net/socket.c:2403
#29 SyS_socketcall (call=16, args=-1077791504) at net/socket.c:2321
#30 0x0805f561 in handle_syscall (r=0xa1ac3b0) at arch/um/kernel/skas/syscall.c:35
#31 0x08070c5b in handle_trap (regs=0xa1ac3b0) at arch/um/os-Linux/skas/process.c:174
#32 userspace (regs=0xa1ac3b0) at arch/um/os-Linux/skas/process.c:399
#33 0x0805cc80 in fork_handler () at arch/um/kernel/process.c:149
#34 0x000b43c5 in ?? ()



相关文章推荐

试玩UML(User Mode Linux)

试玩UML(User Mode Linux) 转载时请注明出处:http://blog.csdn.net/absurd/ 这里的UML并非指统一建模语言,而指用户模式的linux。顾名思义,就是让li...
  • absurd
  • absurd
  • 2006年08月14日 19:31
  • 11646

在fedora7上构建UML(User mode linux)(二)

上集讲到,运行 [hid@hid-server ~]$ ./linux ubda=romfs 时重复出现以下错误提示信息: xterm_open: $DISPLAY not set. Fail...

在fedora7上构建UML(User mode linux)(一)

linux系统有很特别的功能,比如可以在一个linux系统上把一个内核当作一个程序来运行,这样称之为User Mode Linux,在内核开发调试过程,做实验,快速开发程序等过程中能达到快速模拟开发板...

建立UML(user mode linux)的linux内核调试环境

其实调试内核我最喜欢的还是print,因为它很灵活,这基本上是一个万能的东西,但是print总是需要自己去找对位置然后写上合适的print语句,有时还要为print一个东西而作很多准备工作。如果很复杂...
  • ZR_Lang
  • ZR_Lang
  • 2012年10月23日 17:32
  • 3462

user mode linux

  • 2011年04月22日 09:51
  • 2.69MB
  • 下载

Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode

在main.c的程序中,当设备初始化完毕后,程序将从内核模式切换到用户模式,也就是所说的任务0,执行fork()函数(该函数使用内嵌的汇编,防止函数调用弄乱堆栈,造成写时复制COPY_ON_WRITE...

透過 User-Mode-Linux 來學習核心設計 (1)

« GCC 函式追蹤功能 |回到主頁面| 透過 User-Mode-Linux 來學習核心設計 (2) » January 11, 2007 透過 User-Mode-Linux 來學習核心...
  • lcw_202
  • lcw_202
  • 2012年03月07日 22:37
  • 489

Vsftp的PASV mode(被动模式传送)和Port模式及 Linux下VsFTP配置全方案

什么叫做PASV mode(被动模式传送)?他是如何工作的? FTP的连接一般是有两个连接的,一个是客户程和服务器传输命令的,另一个是数据传送的连接。FTP服务程序一般会支持两种不同的模式,...
  • binsoft
  • binsoft
  • 2015年03月24日 18:11
  • 6792
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:linux-4.1.1 user mode linux(UML)试用
举报原因:
原因补充:

(最多只允许输入30个字)