在服务器上创建一个虚拟机
使用以下命令创建一个VM:
sudo qemu-system-x86_64 -kernel /home/bzImage-vswd-30B7 -initrd /home/cpio-vswd-30B7.bak -machine pc-i440fx-3.1,accel=kvm,usb=off -net nic -net tap -m 4096M -smp 8 -append ‘root=/dev/ram rw console=ttyS0’ -nographic -virtfs local,id=fs1,path=shared,security_model=none,mount_tag=qemu-shared -cpu max -hda /home/root.qcow2
#-m 4096M为指定虚拟机内存大小
#-smp 8 指定虚拟机的内核数
#-machine pc-i440fx-3.1,accel=kvm,usb=off 对虚拟机进行加速,不指定这些参数,虚拟机的内部操作类似软件模拟,执行相关操作特别慢
在执行上述命令的情况下得到一个错误:
qemu-system-x86_64: -netdev tap,id=tap1: network script /etc/qemu-ifup failed with status 256
默认情况下是没有/etc/qemu-ifup文件,需要自己进行创建:
#!/bin/sh
set -x
switch=br0
if [ -n "$1" ];then
ip tuntap add $1 mode tap user `whoami`
ip link set $1 up
sleep 0.5s
ip link set $1 master $switch
exit 0
else
echo "Error: no interface specified"
exit 1
fi
同时设置qemu-ifup文件的权限,chmod 0755 qemu-ifup。就可以解决上述问题,产生对应的虚拟网桥。
ifconfig qemu-br0 down #关闭网桥
ifconfig qemu-br0 up #关闭网桥