KVM : Create Virtual Machine2021/05/10 |
Install GuestOS and create Virtual Machine.
This example shows to install Ubuntu 21.04. |
|
[1] | On this example, Download an ISO file of Ubuntu on a directory first and Install GuestOS from the ISO on the text mode. It's OK on the console or remote connection via SSH and so on. Furthermore, Virtual Machine's images are placed at [/var/lib/libvirt/images] by default as a Storage Pool, but this example shows to create and use a new Storage Pool.(use any place you like) |
# create a storage pool root@dlp:~# mkdir -p /var/kvm/images root@dlp:~# virt-install \ --name ubuntu2104 \ --ram 4096 \ --disk path=/var/kvm/images/ubuntu2104.img,size=20 \ --vcpus 2 \ --os-variant ubuntu20.04 \ --network bridge=br0 \ --graphics none \ --console pty,target_type=serial \ --location /home/ubuntu-21.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \ --extra-args 'console=ttyS0,115200n8 serial' # installation starts ================================================================================ Welcome! [ Help ] ================================================================================ As the installer is running on a serial console, it has started in basic mode, using only the ASCII character set and black and white colours. If you are connecting from a terminal emulator such as gnome-terminal that supports unicode and rich colours you can switch to "rich mode" which uses unicode, colours and supports many languages. You can also connect to the installer over the network via SSH, which will allow use of rich mode. [ Switch to rich mode ] [ View SSH instructions ] [ Continue in basic mode < ] # select [Continue in basic mode] # after this, installation proceeds with the common procedure |
The example of options above means like follows. There are many options for others, make sure with [man virt-install].
|
[2] | After finishing installation, restart computer and then login prompt is shown like follwos. That's OK if logined normally with a user you set during the installation. |
Ubuntu 21.04 localhost ttyS0 localhost login: ubuntu Password: Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-16-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Mon May 10 04:56:41 UTC 2021 System load: 0.06 Memory usage: 4% Processes: 130 Usage of /: 33.1% of 18.57GB Swap usage: 0% Users logged in: 0 => There were exceptions while processing one or more plugins. See /var/log/landscape/sysinfo.log for more information. 10 updates can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable ubuntu@localhost:~$ |
[3] | Move to GuestOS to HostOS with Ctrl + ] key. Move to HostOS to GuestOS with a command [virsh console (name of virtual machine)]. |
ubuntu@localhost:~$
root@dlp:~# # Ctrl + ] key root@dlp:~# # Host's console virsh console ubuntu2104 # switch to Guest's console Connected to domain 'ubuntu2104'
Escape character is ^]
ubuntu@localhost:~$ # Enter key # Guest's console
|
[4] | It's easy to replicate a copy VM from current VM with a command below. |
root@dlp:~# virt-clone --original ubuntu2104 --name template --file /var/kvm/images/template.img Allocating 'template.img' | 20 GB 00:00:04 Clone 'template' created successfully. # disk image root@dlp:~# ll /var/kvm/images/template.img -rw------- 1 root root 3140485120 May 10 05:03 /var/kvm/images/template.img # configuration file root@dlp:~# ll /etc/libvirt/qemu/template.xml -rw------- 1 root root 5260 May 10 05:03 /etc/libvirt/qemu/template.xml |
Sponsored Link |