EVE-NG下安装OpenWRT x86

新建目录,在EVE-NG中以“linux-”开头,添加节点的时候就可以找到这个镜像

[email protected]:~# mkdir /opt/unetlab/addons/qemu/linux-openwrt
创建虚拟机的硬盘镜像文件
[email protected]:~# qemu-img create -f qcow2 hda.qcow2 1G
Formatting 'hda.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
[email protected]:~# ll
-rw-r--r--  1 root root 42281968 Aug 12 02:23 hda.qcow2
-rw-r--r--  1 root root 42281968 Aug 12 02:19 openwrt-koolshare-mod-v2.19-r8118-26796a2-x86-64-combined-squashfs.img.gz

解压openwrt镜像(之前已经将openwrt的镜像通过SFTP上传到EVE-NG主机中)

[email protected]:~# gzip -d openwrt-koolshare-mod-v2.19-r8118-26796a2-x86-64-combined-squashfs.img.gz
[email protected]:~# ll
-rw-r--r--  1 root root  42281968 Aug 12 02:23 hda.qcow2
-rw-r--r--  1 root root 248844387 Aug 12 02:19 openwrt-koolshare-mod-v2.19-r8118-26796a2-x86-64-combined-squashfs.img

使用Linux命令dd,将openwrt镜像写入刚才创建的空白硬盘镜像文件。这步操作相当于克隆。

[email protected]:~# dd if=openwrt-koolshare-mod-v2.19-r8118-26796a2-x86-64-combined-squashfs.img of=hda.qcow2
486024+1 records in
486024+1 records out
248844387 bytes (249 MB, 237 MiB) copied, 1.41203 s, 176 MB/s

将克隆好的硬盘镜像文件移动到刚才创建的目录

[email protected]:~# mv hda.qcow2 /opt/unetlab/addons/qemu/linux-openwrt/

在EVE-NG页面中新建一个Lab,添加一个节点,选择“linux-openwrt” 启动虚拟机时,出现如下提示

skipd[4325]: can't create table 14: unable to open database file

虚拟机中没有network这个文件,创建文件时提示没有空间

[email protected](none):/# ll /etc/config/
-rw-rw-r--    1 root     root          2845 Jul  4 01:51 mwan3
-rw-------    1 root     root          2153 Jul  4 01:51 nlbwmon
-rw-r--r--    1 root     root           121 Jul  4 01:51 p910nd
没有/etc/config/network
[email protected](none):/# touch /etc/config/network
touch: /etc/config/network: No space left on device
[email protected](none):/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                36.8M     36.8M         0 100% /rom
tmpfs                   245.8M     96.0K    245.7M   0% /tmp
/dev/loop0               61.0K     11.0K     46.0K  19% /overlay
overlayfs:/overlay       61.0K     11.0K     46.0K  19% /
/dev/sda1               196.8M      3.5M    189.4M   2% /boot
/dev/sda1               196.8M      3.5M    189.4M   2% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
[email protected](none):/# fdisk -l
Disk /dev/loop0: 68.5 KiB, 70144 bytes, 137 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
硬盘只有237.3M,但是创建硬盘镜像文件时分配的是1G,说明使用dd命令后,硬盘镜像文件的virtual size被改变成跟openwrt镜像一样大
Disk /dev/sda: 237.3 MiB, 248844800 bytes, 486025 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9cfbe460
Device     Boot  Start     End Sectors  Size Id Type
/dev/sda1  *       512  410111  409600  200M 83 Linux
/dev/sda2       410624 1434623 1024000  500M 83 Linux

重新克隆

[email protected]:~# dd if=openwrt-koolshare-mod-v2.19-r8118-26796a2-x86-64-combined-squashfs.img of=hda.qcow2
486024+1 records in
486024+1 records out
248844387 bytes (249 MB, 237 MiB) copied, 1.54757 s, 161 MB/s
[email protected]:~#
[email protected]:~#
[email protected]:~# qemu-img info hda.qcow2
image: hda.qcow2
file format: raw
virtual size: 237M (248844800 bytes)
disk size: 237M

克隆后再使用qemu-img命令增大硬盘镜像文件的大小

[email protected]:~# qemu-img resize hda.qcow2 +750M
WARNING: Image format was not specified for 'hda.qcow2' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
Image resized.
[email protected]:~# ll
-rw-r--r--  1 root root 1035276800 Aug 12 04:06 hda.qcow2

启动openwrt后可以修改配置了 由于openwrt默认已经做了一些配置,如Lan口的IP为192.168.1.1/24,但这些配置跟我现有的网络不同网段,需要修改openwrt的IP

[email protected]:/# vim /etc/config/network
config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'
config globals 'globals'
        option ula_prefix 'fddc:9d6e:885b::/48'
config interface 'lan'
        option type 'bridge'
        option ifname 'eth0 eth1 eth2 eth3'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'
默认LAN口IP为192.168.1.1/24
虚拟机中的网卡eth0与默认配置中的eth0刚好是一样的
config interface 'wan'
        option ifname 'eth4'
        option proto 'dhcp'
config interface 'wan6'
        option ifname 'eth4'
        option proto 'dhcpv6'
修改为
config interface 'lan'
        option type 'bridge'
        option ifname 'eth0 eth1 eth2 eth3'
        option proto 'static'
        option ipaddr '10.55.55.25'
        option netmask '255.255.255.224'
        option ip6assign '60'
        option gateway '10.55.55.1'
        option broadcast '255.255.255.255'
        option dns '114.114.114.114 8.8.8.8'
在命令行下修改IP,使得可以从Web页面登录,之后可以在页面修改IP等信息
[email protected]:/# service network restart

测试openwrt能否连接互联网

[email protected]:/# ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114): 56 data bytes
64 bytes from 114.114.114.114: seq=0 ttl=66 time=26.109 ms
64 bytes from 114.114.114.114: seq=1 ttl=69 time=25.583 ms
64 bytes from 114.114.114.114: seq=2 ttl=91 time=25.252 ms
^C
--- 114.114.114.114 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 25.252/25.648/26.109 ms
[email protected]:/# ping baidu.com
PING baidu.com (123.125.115.110): 56 data bytes
64 bytes from 123.125.115.110: seq=0 ttl=51 time=43.248 ms
64 bytes from 123.125.115.110: seq=1 ttl=51 time=43.957 ms
64 bytes from 123.125.115.110: seq=2 ttl=51 time=43.682 ms
64 bytes from 123.125.115.110: seq=3 ttl=51 time=43.305 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/

查看正常情况下的硬盘分区信息

[email protected]:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                36.8M     36.8M         0 100% /rom
tmpfs                   245.8M    860.0K    244.9M   0% /tmp
/dev/loop0              461.3M     24.9M    342.4M   7% /overlay
overlayfs:/overlay      461.3M     24.9M    342.4M   7% /
/dev/sda1               196.8M      3.5M    189.4M   2% /boot
/dev/sda1               196.8M      3.5M    189.4M   2% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
[email protected]:/# fdisk -l
Disk /dev/loop0: 463.3 MiB, 485752832 bytes, 948736 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 987.3 MiB, 1035276800 bytes, 2022025 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9cfbe460
Device     Boot  Start     End Sectors  Size Id Type
/dev/sda1  *       512  410111  409600  200M 83 Linux
/dev/sda2       410624 1434623 1024000  500M 83 Linux

这里使用的是Koolshare版本的openwrt 默认页面登录密码:koolshare

LEDE(coolshare)软件中心界面
LEDE(coolshare)软件中心界面

0 Comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注