ubuntu下使用qemu虚拟机

安装qemu

apt-get install qemu qemu-kvm qemu-system-gui -y

创建qcow2格式的虚拟磁盘(默认raw格式)

qemu-img create -f qcow2 ubuntu20.qcow2 20G

查看虚拟磁盘信息

qemu-img info centos2.raw

qemu启动

# 默认启动图形界面(从iso安装系统)
qemu-system-x86_64 -m 4096 -smp 4 --enable-kvm -boot d -hda ubuntu20.qcow2 -cdrom ubuntu-20.04-live-server-amd64.iso
-m 4096              # 虚拟机内存4096MB
-smp 4               # 虚拟机4个vcpu
-hda                 # 硬盘文件
-cdrom               # 光盘文件
-boot                # 启动顺序,从光盘启动
-vnc :1              # VNC
--nographic          # 不使用图形界面,console
-serial telent:localhost:4321,server,nowait    # 图形+localhost 4321

ssh – NAT

创建网桥virbr0

sudo brctl added virbr0
sudo ifconfig virbr0 192.168.122.1 net mask 255.255.255.0 up

创建tap接口tap0,并添加到网桥

sudo tunctl -t tap0
sudo ifconfig tap0 0.0.0.0 up
sudo brctl addif virbr0 tap0

虚拟机使用tap0作为网络设备启动

qemu-system-x86_64 -m 4096 -smp 4 --enable-kvm  -boot d -hda /opt/ubuntu20.qcow2 -cdrom /home/kylin/ubuntu-20.04-live-server-amd64.iso \
-netdev tap,id=tapnet,ifname=tap0,script=no \
-device rtl8139,netdev=tapnet
-netdev 指定网络方式
-device 指定硬件,网卡使用netdev

ssh – Bridge

只有在创建网桥的时候和 ssh – NAT 有差别,其余的步骤方法是都一样的

refe

https://man.archlinux.org/man/qemu.1
https://wiki.archlinux.org/index.php/QEMU_(简体中文)
https://blog.csdn.net/RichardYSteven/article/details/54807927?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&dist_request_id=1328602.9293.16149062389857733&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control
https://blog.csdn.net/RichardYSteven/article/details/54645328?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

上一篇:Linux虚拟化KVM-Qemu分析(八)之virtio初探


下一篇:qemu-kvm的ioeventfd机制