前言
1. 网络搭建
1.实验目的
在嵌入式linux开发中需要使用虚拟机ubuntu18.04开发,需要搭建以下环境,以便使用NFS开发。
- 虚拟机ping通WIN10,以便可以上网
- WIN10ping通虚拟机,以便vscode SSH远程登陆
- 开发板ping通虚拟机,以便NFS下载kernal与设备树
2.实验环境
WIN10搭载ubunt18.04虚拟机,一根网线通过物理网口开发板连接WIN10。
3.实验步骤
-
设置Microsoft KM-TEST 环回地址
解决虚拟机与宿主机不在同一个网段中,不能相互ping通的问题
此虚拟网卡可以固定为WIN10和虚拟机ubuntu18.04的通信媒介 -
使用USB带网口分频器链接开发板,激活以太网3的网卡
-
ubuntu18.04设置虚拟双网卡并按照以下方式桥接到WIN10物理网卡
-
添加网络适配器2,自定义为虚拟网络VNET2
- 网络适配器1,自定义为虚拟网络VNET0
- IP规划
虚拟机网络适配器1与KM-TEST环回地址在同一网段
虚拟机网络适配器2与开发板,开发板连接的物理网卡(Realtek USB FE Family Controller)在同一网段
如果物理网卡(Realtek USB FE Family Controller),自动分配IP
WIN终端查看其IP
- ubuntu18.04设置双网卡IP
sudo vim /etc/netplan/01-network-manager-all.yaml
sudo netplan apply(启动网卡配置)
1 # Let NetworkManager manage all devices on this system
2 network:
3 ethernets:
4 ens33:
5 dhcp4: no
6 addresses: [192.168.20.156/24]
7 optional: true
8 nameservers:
9 addresses: [114.114.114.114,223.6.6.6]
10 ens38:
11 dhcp4: no
12 addresses: [192.168.0.154/24]
13 optional: true
14 gateway4: 192.168.0.1
15 nameservers:
16 addresses: [114.114.114.114,223.6.6.6]
17 # version: 2
18 #renderer: NetworkManager
>>> ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.20.156 netmask 255.255.255.0 broadcast 192.168.20.255
inet6 fe80::20c:29ff:fea0:3496 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a0:34:96 txqueuelen 1000 (Ethernet)
RX packets 641 bytes 62599 (62.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 126 bytes 11315 (11.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.154 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::20c:29ff:fea0:34a0 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a0:34:a0 txqueuelen 1000 (Ethernet)
RX packets 100781 bytes 7098397 (7.0 MB)
RX errors 0 dropped 7142 overruns 0 frame 0
TX packets 69158 bytes 5122447 (5.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5337 bytes 414162 (414.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5337 bytes 414162 (414.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[sheldon@ubuntu ~]@~
说明配置生效
- ubuntu18.04测试
make xxx_defconfig------>.config
make makefile---->export <.config>---->include <config.mk>---->export ARCH CPU BOARD
uboot 启动详细流程
Start.S->board_init_f–>mem alloc->uboot code relocate->
六,移植uboot-设置默认环境变量,完善u-boot
2.ubuntu18.04设置上网
在1的基础上,将/etc/netplan/01-network-manager-all.yaml改为
在1的基础上,可以实现虚拟机上网,又能联通开发板
适配器1要和上网卡在同一网段,重要gateway要相同
sudo netplan apply
# Let NetworkManager manage all devices on this system
network:
ethernets:
ens33:
dhcp4: false
addresses: [192.168.1.156/24]
optional: true
gateway4: 192.168.1.1
nameservers:
addresses: [114.114.114.114,223.6.6.6]
ens38:
dhcp4: false
addresses: [192.168.20.154/24]
optional: true
#gateway4: 192.168.1.1
#nameservers:
#addresses: [114.114.114.114,223.6.6.6]
# version: 2
# version: 2
#renderer: NetworkManager
>>> ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.156 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 240e:305:7882:2fe1:20c:29ff:fe31:9955 prefixlen 64 scopeid 0x0<global>
inet6 fe80::20c:29ff:fe31:9955 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:31:99:55 txqueuelen 1000 (Ethernet)
RX packets 3394 bytes 309342 (309.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4789 bytes 618399 (618.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.20.154 netmask 255.255.255.0 broadcast 192.168.20.255
inet6 fe80::20c:29ff:fe31:995f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:31:99:5f txqueuelen 1000 (Ethernet)
RX packets 37132 bytes 3916418 (3.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 44010 bytes 62167661 (62.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0