virtualization on linux
Beginner’s guide to setup VMs on Linux, without the pain of VirtualBox
Why?
- Virtualbox’s installation is more tiresome
- Virutalbox’s CLI looks more complex. Check it here
Resort: libvirt + virt-install
- They are open-source and free
- There is also a GUI based on it, called virt-manager
- Unlike virtualbox, you can find installation guides easily from major distro’s official site:
How do I create a new VM in terminal?
- install an OS iso, and in command line
# here we use ubuntu 22.04.3 as an example
virt-install \
--connect qemu:///system \
--name $YOUR_VM_NAME \
--os-variant ubuntu22.04 \
--vcpus 2 \
--ram 2048 \
--disk size=20 \
--location /tmp/ubuntu-22.04.3-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \
--network network:default \
--nographics \
--extra-args "console=ttyS0"
- you can check the manual of virt-install for the meaning of each flag
How do I create a new VM with GUI?
- virt-manager is straightforward. If you have previous experience with VMWare Fusion, Parallel Desktop, VirtualBOx, it’s easy to start with.
- Here is a redhat blog for how to use it: the blog
VM management
# list all the VMs (their names) created by virt-install
virsh list --all # this will only show the VMs created by the current user
# turn on a VM which in `shut off` state
virsh start <VM_name>
# gracefully shutdown a VM
virsh shutdown <VM_name>
# forcefully shutdown a VM
virsh destroy <VM_name>
# remove a vm when it's off
virsh undefine <name>
- you can find more here