KVM 虚拟机Clone

在创建出一个虚拟机后,如果不想每次创建ubuntu16.04 的虚拟机都执行virt-install, 然后启用vncviewer 进入os安装界面从新进行安装的话,就把前面创建出来的虚拟机clone一份,修改hostname, ip address 等配置即可。

1 使用下面指令进行clone

virt-clone -o  ubuntu1604-test -n  ubuntu1604-test-vm1 -f /home/test/Documents/kvmdisk/ubuntu1604-test-vm1.img 

 
说明:以ubuntu1604-test做为源,克隆ubuntu1604-test虚拟机,并创建名称为ubuntu1604-test-vm1的虚拟机,使用磁盘文件/home/test/Documents/kvmdisk/ubuntu1604-test-vm1.img

2 clone 完成之后,用源虚拟机的ip,登陆上新clone出来的ubuntu1604-test-vm1, 修改hostname, 方法是修改/etc/hostname 和/etc/hosts 文件指定hostname为
ubuntu1604-test-vm1,需要重启才能永久生效, 而用hostname -f 修改的hostname重启后就失效了。

3 修改网络配置文件,为这个ubuntu1604-test-vm1 换一个与源虚拟机同网断的新的ip。
修改后的配置文件如下:

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 重启网络

sudo /etc/init.d/networking restart



Tips
如果想修改virsh edit 编辑器,默认是nano
在~/.bashrc 文件中加入 export EDITOR=vim , 重新logon off/on shell session 即可生效

猜你喜欢

转载自www.cnblogs.com/happyorange/p/8967131.html