231003_Linux上跑KVM虚拟机
既然我本机是Linux,那运行虚拟机何不用KVM呢。如果是win/mac,那还用不了KVM(1类虚拟机),只能用virtualbox,vmware(2类虚拟机)。
流れ简单说就是:安装环境;启动libvirt daemon;开启虚拟网络;virt-manager作为前端界面可以在里面操作了
检查处理器是否支持硬件虚拟化
1 | LC_ALL=C lscpu | grep Virtualization |
现在的处理器肯定都是支持的,If it looks like your processor does not support virtualization, it is almost certainly turned off in the BIOS.
KVM(Kernel-based Virtual Machine)集中在Linux内核里了,不需要安装
安装qemu
1 | sudo pacman -S qemu |
选qemu-full
安装libvert (检查iptables-nft 有没有,没的话装上)
1 | sudo pacman -S libvirt |
安装virt-manager
1 | sudo pacman -S virt-manager |
==开启libvirt daemon (不然之后的virshなど都用不了)==
1 | systemctl start libvirtd |
加入libvirt user group (archwiki写了,但我没这样做 担心和虚拟机的稳定性有关,还是加入了)
1 | sudo usermod -a -G libvirt $(whoami) |
应该打开virt-manager不需要输入口令了
安装其他可能有用的包
1 | sudo pacman -S ovmf vde2 dnsmasq bridge-utils openbsd-netcat |
(archwikiによると、ebtables已经被iptables的功能包含了,所以不需要了)
创建的虚拟机的虚拟硬盘存放在/var/lib/libvirt/images下面.qcow2文件
用virt-manager创建虚拟机,startしようとするところ、虚拟网络报错:
1 | Requested operation is not valid: network 'default' is not active |
解决:https://askubuntu.com/questions/1036297/cant-start-kvm-guest-network-default-is-not-active
First, confirm that the default network is indeed inactive:
1 | sudo virsh net-list --all |
If so, ==start the default network==:
1 | sudo virsh net-start default |
Run the first command line again to see if it worked.
https://github.com/kubernetes/minikube/issues/828 这里还看到了
First time users need currently do:
1 | virsh net-autostart default |
虽然我net-autostart就没実行了
但我sudo virsh net-start default
又报错:
1 | error: Failed to start network default |
问了chatgpt,我就试着开启iptables
1 | systemctl start iptables |
然后再尝试运行虚拟机,结果它就起来了
macOS虚拟机を環境構築してみる
https://christitus.com/macos-on-linux/ & https://www.youtube.com/watch?v=dMLNP6FfhkI 但用的仓库有点旧了
需要安装dmg2img
https://github.com/kholia/OSX-KVM これにしよう
参考资料
https://wiki.archlinux.org/title/KVM
https://wiki.archlinux.org/title/QEMU
https://wiki.archlinux.org/title/Libvirt
https://wiki.archlinux.org/title/Virt-manager
Virt-Manager Is The Better Way To Manage VMs
KVM - A great virtualization solution for Linux 用的不是default的虚拟网络
https://computingforgeeks.com/install-kvm-qemu-virt-manager-arch-manjar/
- Title: 231003_Linux上跑KVM虚拟机
- Author: Haoliang Tang
- Created at : 2023-10-03 00:00:00
- Updated at : 2023-11-02 20:30:49
- Link: https://hl-tang.github.io/2023/10/03/231003_Linux上跑KVM虚拟机/
- License: This work is licensed under CC BY-NC-SA 4.0.