OpenWrt in VirtualBox

Prerequisites

  • Download and install  VirtualBox
  • Get an OpenWrt image:
    • Either use an existing image,
      • Download the  generic combined image for x86 (32-bit), e.g.  chaos_calmer/15.05.1/x86/LEDE 17.01.1 x86
      • Download the  generic combined image for x86_x64 (64-bit), e.g.  chaos_calmer/15.05.1/x86/64LEDE 17.01.1 x86_x64
      • Uncompress the image if needed:  gunzip openwrt.img.gz
      • Convert it to native VirtualBox format:  VBoxManage convertfromraw --format VDI openwrt.img openwrt.vdi (in virtualbox version 5.0.12 the " --format VDI" is at the end of command)
      • For vmdk format : VirtualBox format:  VBoxManage convertfromraw --format VMDK openwrt.img openwrt.vmdk
    • Or  compile your own image ( Target System → x86 and  Target Images → Build VirtualBox image files).  ext4 needs to be enabled first.

Notes

for x86_x64 (64-bit) make sure Intel VT-x or AMD-V is enabled, If you do not see this option in your motherboard, you must check the motherboard manual and specifications to identify whether the motherboard supports virtualization technology, Some of the old motherboards on Desktop or Laptop do not offer this feature, x86 is ok.

VM Setup in VirtualBox

  • Start VirtualBox

Initial Form

  • Click  New to add a virtual machine (VM)

OpenWrt and Kernel version

  • Choose a  Name for your virtual machine
  • Choose  Linux for your  Operating System
  • Choose  Other Linux (32 bit) or  Other Linux (64 bit) for your  Version
  • Click  Next
  • Optionally decrease RAM size from  256 MB to something smaller
  • Click  Next

  • Choose  Use existing hard disk
  • Click the  file icon to open  Virtual Media Manager

  • Click  Add and choose your  .vdi or  .vmdk file using the dialog
  • Select your image in the list and click  Select
  • Click  Next and  Finish

  • This concludes the VM setup!
  • Click  Start to boot the OpenWrt VM

  • GRUB greets you, and boots using one of the available configurations (unless you intervene)
  • dmesg boot messages scroll by
  • Press Enter to activate the console

Troubleshooting

  • If your virtual machine boots but doesn't activate the console
    • Press Enter
  • If you rebuild the disk image, and VirtualBox complains about invalid UUIDs for the disk
    • You need to remove the disk from  both the VM  and also from the  Virtual Media Manager
    • Then add the disk image to the VM again
  • If your virtual machine is booting and one of the messages seen is  Waiting for root device PARTUUID=-02… and you compiled the image
    • Make sure the machine you compiled the image on has the command  hexdump and  dd installed on it before compiling the image

Setting up networking

 
Enable Internet access through VirtualBox's NAT gateway
  • halt the VM if it runs
  • Open the VM's settings
  • In the  Network tab
    • Configure  Adapter 1 to use  NAT
    • Configure  Adapter 2 to use  Bridge Adapter
      • Select your host machine's interface , e.g.wlp2s0 is wireless interface in Ubuntu 15.0
      • Best to disable promiscuous mode or its your choice
  • Boot into your openwrt VM
  • In file  /etc/config/network do the following

 

 config 'interface' 'wan'
                  option 'proto' 'dhcp'
                  option 'ifname' 'eth0'
              
 config 'interface' 'lan'
                  #option type 'bridge'
                  option ifname 'eth1'
                  #option ip6assign '60'
                  

 

  • Reboot openwrt VM

Your OpenWrt VM now has Internet access through VirtualBox's NAT gateway.

Set up networking with other VirtualBox VMs
  • halt the VM if it runs
  • Open the VM's settings
  • In the  Network tab
    • Configure  Adapter 1 to use  internal network, and choose a name for it
    • If you also need Internet connectivity, configure another adapter to use NAT, as above.
  • Boot the VM
  • In file  /etc/config/network configure the  lan interface to use  eth0, and set an interface type and address
    config interface 'lan'
            option ifname 'eth0'
            option type 'bridge'
            option proto 'static' 
            option ipaddr '192.168.1.1'
            option netmask '255.255.255.0'
    #       option ip6assign '60'  # Unused, no IPv6 in this example
  • If you want to use VirtualBox's internal network's DHCP server, use  option proto 'dhcp'
  • Bring up the  lan interface with  ifup lan

Your OpenWrt VM can now interface with other VirtualBox VMs on your host that are also configured to use the internal network you set up.

转载于:https://www.cnblogs.com/yinwun/p/7802580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值