一、配置Vagrantfile
Vagrantfile 配置内容如下:
Vagrant.configure("2") do |config| config.vm.box = "ntrepid8/openwrt-15.05-x86" config.vm.network "public_network", ip: "192.168.0.11" config.vm.synced_folder ".", "/vagrant", type: "virtualbox" config.vm.provider "virtualbox" do |v| v.memory = 2048 v.cpus = 2 end end
启动openwrt x86 虚拟机
vagrant up
二、配置openwrt
通过ssh进入虚拟机,默认vagrant使用的是本地2222端口:
ssh -p 2222 [email protected]
进入之后,显示 openwrt 默认页面:
BusyBox v1.23.2 (2016-01-27 21:04:08 EST) built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- CHAOS CALMER (Chaos Calmer, r48666) ----------------------------------------------------- * 1 1/2 oz Gin Shake with a glassful * 1/4 oz Triple Sec of broken ice and pour * 3/4 oz Lime Juice unstrained into a goblet. * 1 1/2 oz Orange Juice * 1 tsp. Grenadine Syrup -----------------------------------------------------
安装opkg更新包
opkg update //更新包列表,这一步是必须的 opkg install luci //安装luci,非常强大的web管理工具 opkg install luci-i18n-chinese //安装luci中文语言包
如果在执行”opkg update”命令出现如下错误:
Collected errors: * opkg_download: Failed to download http://downloads.openwrt.org/chaos_calmer/15.05/x86/generic/packages/luma/Packages.gz, wget returned 8. * opkg_download: Failed to download http://downloads.openwrt.org/chaos_calmer/15.05/x86/generic/packages/luma/Packages.sig, wget returned 8.
造成的原因,可能是官方删除了luma包文件;
解决办法:编辑 /etc/opkg/distfeeds.conf 删除对应的包,再执行”opkg update”
openwrt默认是不允许外网访问的,所以在虚拟机内启动openwrt之后,需要修改下防火墙设置
cat /etc/config/network #查看网口配置 sudo vi /etc/config/firewall #编辑下wan口的 option input ACCEPT sudo /etc/init.d/firewall restart #重启防火墙 sudo passwd #设置luci的登录root密码
虚拟机挂载usb网卡
所需组件:
opkg install usbutils #提供了lsusb功能 opkg install kmod-rtl8192cu #Realtek RTL8192CU/RTL8188CU support opkg install kmod-rtlwifi # Realtek common driver part opkg install kmod-cfg80211 #cfg80211 – wireless configuration API opkg install kmod-lib80211 #802.11 Networking stack opkg install kmod-mac80211 #Linux 802.11 Wireless Networking Stack opkg install hostapd opkg install hostapd-utils #插入网卡,重启路由 dmesg #打印Linux系统开机启动信息,查看是否已挂载usb网卡 ifconfig wlan1 up wifi detect > /etc/config/wireless opkg update opkg install luci-app-mwan3 opkg install luci-i18n-base-zh-cn #安装中文语言包
其他
Luci配置
Luci是 Lua ConfigurationInterface的简称,作用是在OpenWrt整个系统的配置集中化。
Luci参考文档:https://wiki.openwrt.org/zh-cn/doc/uci
/www/cgi-bin/luci #luci 执行文件 /etc/config/ #uci配置文件目录 uci #命令行修改uci配置
虚拟机镜像转换
openwrt img镜像转成vdi或者vmdk格式,https://wiki.openwrt.org/doc/howto/virtualbox
VBoxManage convertfromraw --format VDI openwrt.img openwrt.vdi VBoxManage convertfromraw --format VMDK openwrt.img openwrt.vmdk
虚拟机配置文件示例
openwrt.vmx
.encoding = "GBK" config.version = "8" virtualHW.version = "12" vcpu.hotadd = "TRUE" scsi0.present = "TRUE" scsi0.virtualDev = "lsilogic" memsize = "512" mem.hotadd = "TRUE" ide1:0.present = "TRUE" ide1:0.fileName = "openwrt-15.05-x86-generic-combined-ext4.vmdk" ethernet0.present = "TRUE" ethernet0.connectionType = "custom" ethernet0.wakeOnPcktRcv = "FALSE" ethernet0.addressType = "generated" ethernet1.present = "TRUE" ethernet1.connectionType = "nat" ethernet1.wakeOnPcktRcv = "FALSE" ethernet1.addressType = "static" pciBridge0.present = "TRUE" pciBridge4.present = "TRUE" pciBridge4.virtualDev = "pcieRootPort" pciBridge4.functions = "8" pciBridge5.present = "TRUE" pciBridge5.virtualDev = "pcieRootPort" pciBridge5.functions = "8" pciBridge6.present = "TRUE" pciBridge6.virtualDev = "pcieRootPort" pciBridge6.functions = "8" pciBridge7.present = "TRUE" pciBridge7.virtualDev = "pcieRootPort" pciBridge7.functions = "8" vmci0.present = "TRUE" hpet0.present = "TRUE" usb.vbluetooth.startConnected = "TRUE" displayName = "OpenWRT" guestOS = "other26xlinux" nvram = "OpenWRT.nvram" virtualHW.productCompatibility = "hosted" powerType.powerOff = "soft" powerType.powerOn = "soft" powerType.suspend = "soft" powerType.reset = "soft" extendedConfigFile = "OpenWRT.vmxf" ethernet0.vnet = "VMnet1" ethernet1.vnet = "VMnet0" uuid.bios = "56 4d 24 01 81 1a 1d 2e-e6 81 8f f3 24 50 8f 51" uuid.location = "56 4d 24 01 81 1a 1d 2e-e6 81 8f f3 24 50 8f 51" migrate.hostlog = ".\OpenWRT-0567545d.hlog" ide1:0.redo = "" pciBridge0.pciSlotNumber = "17" pciBridge4.pciSlotNumber = "21" pciBridge5.pciSlotNumber = "22" pciBridge6.pciSlotNumber = "23" pciBridge7.pciSlotNumber = "24" scsi0.pciSlotNumber = "16" ethernet0.pciSlotNumber = "32" ethernet1.pciSlotNumber = "33" vmci0.pciSlotNumber = "34" ethernet0.generatedAddress = "00:0c:29:50:8f:51" ethernet0.generatedAddressOffset = "0" ethernet1.generatedAddressOffset = "10" vmci0.id = "609259345" monitor.phys_bits_used = "42" vmotion.checkpointFBSize = "33554432" vmotion.checkpointSVGAPrimarySize = "33554432" cleanShutdown = "TRUE" softPowerOff = "FALSE" tools.remindInstall = "TRUE" floppy0.present = "FALSE" tools.syncTime = "FALSE" usb.present = "TRUE" ehci.present = "TRUE" ehci.pciSlotNumber = "35" usb.pciSlotNumber = "36" checkpoint.vmState = "" usb:1.speed = "2" usb:1.present = "TRUE" usb:1.deviceType = "hub" usb:1.port = "1" usb:1.parent = "-1" ethernet1.address = "00:0C:29:50:8F:52" usb:0.present = "TRUE" usb:0.deviceType = "hid" usb:0.port = "0" usb:0.parent = "-1" usb.autoConnect.device0 = "path:1/0/0/1 autoclean:1"
Comments on this entry are closed.