After creating a virtual machine, if you don't want to execute virt-install every time you create a virtual machine of ubuntu16.04, and then enable vncviewer to enter the os installation interface to re-install, just clone the virtual machine created earlier and modify it hostname, ip address, etc. can be configured.
1 Use the following command to clone
virt-clone -o ubuntu1604-test -n ubuntu1604-test-vm1 -f /home/test/Documents/kvmdisk/ubuntu1604-test-vm1.img
Description: Take ubuntu1604-test as the source, clone the ubuntu1604-test virtual machine, and create a virtual machine named ubuntu1604-test-vm1, use the disk file /home/test/Documents/kvmdisk/ubuntu1604-test-vm1.img
2 After the clone is completed, use the ip of the source virtual machine to log in to the ubuntu1604-test-vm1 from the new clone, and modify the hostname. The method is to modify the /etc/hostname and /etc/hosts files to specify the hostname as
ubuntu1604-test-vm1, which needs to be restarted. It can take effect permanently, and the hostname modified with hostname -f will be invalid after restarting.
3 Modify the network configuration file and replace the ubuntu1604-test-vm1 with a new ip that is disconnected from the same network as the source virtual machine.
The modified configuration file is as follows:
test@ubuntu1604-test-vm1:~$ cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens3 iface ens3 inet static address 192.168.122.2 netmask 255.255.255.0 gateway 192.168.122.1
4 Restart the network
sudo /etc/init.d/networking restart
Tips
If you want to modify the virsh edit editor, the default is nano
to add export EDITOR=vim to the ~/.bashrc file, and re-logon off/on shell session will take effect