最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】Ubuntu下为QEMU准备qemu-ifup和qemu-ifdown

QEMU crifan 5323浏览 0评论

【背景】

折腾:

【记录】尝试用QEMU模拟ARM开发板去加载并运行Uboot,kernel,rootfs

期间,需要为QEMU准备qemu-ifup和qemu-ifdown。

【折腾过程】

1.确认是已有tun设备节点的:

crifan@ubuntu:embedded$ ls /dev/net/
tun
crifan@ubuntu:embedded$ ls /dev/net/ -hla
total 0
drwxr-xr-x  2 root root      60 Aug 16 02:13 .
drwxr-xr-x 15 root root    4.3K Aug 16 02:13 ..
crw-rw-rwT  1 root root 10, 200 Aug 16 02:13 tun
crifan@ubuntu:embedded$ file /dev/net/tun
/dev/net/tun: sticky character special

2.参考:

http://en.wikibooks.org/wiki/QEMU/Networking

去创建对应的qemu-ifup和qemu-ifdown:

(1)qemu-ifup:

内容为:

#!/bin/sh 
# 
# script to bring up the tun device in QEMU in bridged mode 
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host - change to suit your host
#
ETH0IPADDR=192.168.0.3
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
#
# First take eth0 down, then bring it up with IP address 0.0.0.0 
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
/usr/sbin/openvpn --mktun --dev $1 --user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 $1
# 
# only a single bridge so loops are not possible, turn off spanning tree protocol
#
/usr/sbin/brctl stp br0 off 
# 
# Bring up the bridge with ETH0IPADDR and add the default route 
#
/sbin/ifconfig br0 $ETH0IPADDR netmask 255.255.255.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
#
# stop firewall - comment this out if you don't use Firestarter
#
/sbin/service firestarter stop 

(2)qemu-ifdown

#!/bin/sh 
# 
# Script to bring down and delete bridge br0 when QEMU exits 
# 
# Bring down eth0 and br0 
#
/sbin/ifdown eth0
/sbin/ifdown br0
/sbin/ifconfig br0 down 
# 
# Delete the bridge
#
/usr/sbin/brctl delbr br0 
# 
# bring up eth0 in "normal" mode 
#
/sbin/ifconfig eth0 -promisc
/sbin/ifup eth0 
#
# delete the tap device
#
/usr/sbin/openvpn --rmtun --dev $1
#
# start firewall again
# 
/sbin/service firestarter start

然后再拷贝到etc,并且加上可执行的权限:

crifan@ubuntu:ifup_ifdown$ gedit qemu-ifup

(gedit:3688): Gtk-WARNING **: Attempting to read the recently used resources file at `/home/crifan/.local/share/recently-used.xbel', but the parser failed: Failed to open file '/home/crifan/.local/share/recently-used.xbel': Permission denied.
crifan@ubuntu:ifup_ifdown$ gedit qemu-ifdown
crifan@ubuntu:ifup_ifdown$ ls
qemu-ifdown  qemu-ifup
crifan@ubuntu:ifup_ifdown$ cp qemu-ifup qemu-ifdown /etc/
cp: cannot create regular file ‘/etc/qemu-ifup’: Permission denied
cp: cannot create regular file ‘/etc/qemu-ifdown’: Permission denied
crifan@ubuntu:ifup_ifdown$ sudo cp qemu-ifup qemu-ifdown /etc/
crifan@ubuntu:ifup_ifdown$ cd /etc
crifan@ubuntu:etc$ ls
acpi                    host.conf                profile.d
adduser.conf            hostname                 protocols
adjtime                 hosts                    pulse
alternatives            hosts.allow              python
anacrontab              hosts.deny               python2.7
apg.conf                hp                       python3
apm                     ifplugd                  python3.3
apparmor                init                     qemu-ifdown
apparmor.d              init.d                   qemu-ifup
apport                  initramfs-tools          rc0.d
apt                     inputrc                  rc1.d
aptdaemon               insserv                  rc2.d
at-spi2                 insserv.conf             rc3.d
avahi                   insserv.conf.d           rc4.d
bash.bashrc             iproute2                 rc5.d
bash_completion         issue                    rc6.d
bash_completion.d       issue.net                rc.local
bindresvport.blacklist  java                     rc.local~
blkid.conf              java-7-openjdk           rcS.d
blkid.tab               kbd                      remote-login-service.conf
bluetooth               kernel                   resolvconf
bonobo-activation       kernel-img.conf          resolv.conf
brlapi.key              kerneloops.conf          rmt
brltty                  ldap                     rpc
brltty.conf             ld.so.cache              rsyslog.conf
ca-certificates         ld.so.conf               rsyslog.d
ca-certificates.conf    ld.so.conf.d             samba
calendar                legal                    sane.d
chatscripts             libaudit.conf            securetty
checkbox.d              libnl-3                  security
colord.conf             libpaper.d               selinux
compizconfig            libreoffice              sensors3.conf
ConsoleKit              lightdm                  sensors.d
console-setup           lintianrc                services
cracklib                locale.alias             sgml
cron.d                  localtime                shadow
cron.daily              logcheck                 shadow~
cron.hourly             login.defs               shadow-
cron.monthly            logrotate.conf           shells
crontab                 logrotate.d              signond.conf
cron.weekly             lsb-base                 signon-ui
cups                    lsb-base-logging.sh      skel
cupshelpers             lsb-release              snmp
dbus-1                  ltrace.conf              sound
debconf.conf            magic                    speech-dispatcher
debian_version          magic.mime               ssh
default                 mailcap                  ssl
deluser.conf            mailcap.order            subversion
depmod.d                manpath.config           sudoers
dhcp                    mime.types               sudoers~
dhcp3                   mke2fs.conf              sudoers.d
dictionaries-common     modprobe.d               sysctl.conf
dkms                    modules                  sysctl.d
dnsmasq.d               motd                     systemd
doc-base                mtab                     terminfo
dpkg                    mtab.fuselock            texmf
drirc                   mtools.conf              thunderbird
emacs                   nanorc                   timezone
environment             netscsid.conf            tpvmlp.conf
firefox                 network                  ucf.conf
fonts                   NetworkManager           udev
foomatic                networks                 udisks2
fstab                   newt                     ufw
fstab.d                 nsswitch.conf            updatedb.conf
fuse.conf               obex-data-server         update-manager
gai.conf                opt                      update-motd.d
gconf                   os-release               update-notifier
gdb                     pam.conf                 UPower
ghostscript             pam.d                    upstart-xsessions
gnome                   papersize                usb_modeswitch.conf
gnome-app-install       passwd                   usb_modeswitch.d
gnome-settings-daemon   passwd~                  vim
gnome-vfs-2.0           passwd-                  vmware-tools
groff                   pcmcia                   vtrgb
group                   perl                     wgetrc
group-                  pkcs11                   wodim.conf
grub.d                  pm                       wpa_supplicant
gshadow                 pnm2ppa.conf             X11
gshadow-                polkit-1                 xdg
gtk-2.0                 popularity-contest.conf  xml
gtk-3.0                 ppp                      xul-ext
hdparm.conf             profile                  zsh_command_not_found
crifan@ubuntu:etc$ sudo chmod +x qemu-ifup
crifan@ubuntu:etc$ sudo chmod +x qemu-ifdown
crifan@ubuntu:etc$ ls qemu-if& -lha
[1] 3733
ls: cannot access qemu-if: No such file or directory
No command '-lha' found, did you mean:
 Command 'lha' from package 'jlha-utils' (universe)
 Command 'lha' from package 'lhasa' (universe)
 Command 'lha' from package 'lha' (multiverse)
 Command 'jlha' from package 'jlha-utils' (universe)
-lha: command not found
[1]+  Exit 2                  ls --color=auto qemu-if
crifan@ubuntu:etc$ ls qemu-if* -lha
-rwxr-xr-x 1 root root  428 Aug 16 02:51 qemu-ifdown
-rwxr-xr-x 1 root root 1.1K Aug 16 02:51 qemu-ifup
crifan@ubuntu:etc$ 

 

如此,就完成了。

qemu ifup and ifdown added run authority

 

【总结】

主要就是:

创建对应的qemu-ifup和qemu-ifdown两个文件,然后拷贝到etc中,并且给予execute的权限。

转载请注明:在路上 » 【记录】Ubuntu下为QEMU准备qemu-ifup和qemu-ifdown

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.235 seconds, using 22.22MB memory