ubuntu18.04使用KVM虚拟机

第一步、修改源

第二步、更新源、更新软件包

[email protected]:~# apt update&&apt upgrade -y

第三步、安装qemu-kvm(kvm在用户空间的管理工具),libvirt-bin(一个服务,其下组件可用来管理kvm虚拟机)

Libvirt-bin装完后会创建一个虚拟网桥virbr0网桥,其IP为192.168.122.1

[email protected]:~# apt install qemu-kvm libvirt-bin -y

[email protected]:~# systemctl start libvirtd

[email protected]:~# systemctl enable libvirtd

[email protected]:~# systemctl status libvirtd.service

第四步:查看网络情况

发现创建了一个virbr0的虚拟网桥

 

第五步:安装virtinst,该工具是libvirtd的工具,用于管理虚拟机

[email protected]:~# apt install -y virtinst

第六步、安装vnc服务,用于待会儿连接虚拟机,如果不安装使用console也可以

[email protected]:~# apt install -y vnc4server

第七步、下载镜像到虚拟机

镜像尽量放在家目录的位置,否则可能会出现权限问题

第八步、创建虚拟网桥

[email protected]:~# cp /etc/netplan/50-cloud-init.yaml  50-cloud-init.yaml_bak

[email protected]:~# vim /etc/netplan/50-cloud-init.yaml

[email protected]:~# netplan apply

删除virbr0这个虚拟网桥,因为用不到:

第九步、创建一块磁盘空间待会儿用于创建kvm虚拟机,大小为10G,格式为qcow2

[email protected]:~# qemu-img create -f qcow2 /opt/ubuntu18.04.qcow2 10G

第十步、创建kvm虚拟机

第十一步、用vnc连接

然后就进入安装界面:

第十二步、安装时要注意:

  1. 步使用swap分区
  2. 只分一个根
  3. 不使用lvm
  4. 关闭iptables

 

第十三步:其他

[email protected]:~# virsh -c qemu:///system list查看正在运行的虚拟机

[email protected]:~# virsh -c qemu:///system list –all查看所有虚拟机

[email protected]:~# virsh start ubuntu18.04启动关闭状态的虚拟机

[email protected]:~# virsh start ubuntu18.04删除虚拟机

 

IP查看:

分区查看:

内存及swap查看(忘了手动分区,产生了swap分区):

 

查看硬盘大小: