上一章中,我们创建了一个vm1虚拟机,虚拟机的配置文件在
[root@kvm ~]# cat /etc/libvirt/qemu/vm1.xml
克隆虚拟机
克隆虚拟机必须先关闭虚拟机,查看虚拟机状态
[root@kvm ~]# virsh list --all
Id Name State
----------------------------------------------------
- vm1 shut off
开始克隆了,我们把vm1 虚拟机克隆一个叫vm2,其磁盘位置在/home/kvm/images/vm2
virt-clone -o vm1 -n vm2 -f /home/kvm/images/vm2.img
[root@kvm ~]# virt-clone -o vm1 -n vm2 -f /home/kvm/images/vm2.img
WARNING The requested volume capacity will exceed the available pool space when the volume is fully allocated. (10240 M requested capacity > 3844 M available)
WARNING The requested volume capacity will exceed the available pool space when the volume is fully allocated. (10240 M requested capacity > 3844 M available)
Allocating 'vm2.img' | 10 GB 00:52
Clone 'vm2' created successfully.
3.然后查看虚拟机列表
[root@kvm ~]# virsh list --all
Id Name State
----------------------------------------------------
- vm1 shut off
- vm2 shut off
4.我们启动虚拟机,并且通过console 连接,
[root@kvm ~]# virsh console vm2
Connected to domain vm2
Escape character is ^]
Welcome to CentOS
Starting udev: G[ OK ]
Setting hostname vm1: [ OK ]
Setting up Logical Volume Management: 2 logical volume(s) in volume group "vg_vm1" now active
[ OK ]
Checking filesystems
Checking all file systems.
[/sbin/fsck.ext4 (1) -- /] fsck.ext4 -a /dev/mapper/vg_vm1-lv_root
/dev/mapper/vg_vm1-lv_root: clean, 23060/558624 files, 267724/2230272 blocks
[/sbin/fsck.ext4 (1) -- /boot] fsck.ext4 -a /dev/sda1
/dev/sda1: clean, 38/128016 files, 57869/512000 blocks
[ OK ]
Remounting root filesystem in read-write mode: [ OK ]
Mounting local filesystems: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
Entering non-interactive startup
Starting monitoring for VG vg_vm1: 2 logical volume(s) in volume group "vg_vm1" monitored
[ OK ]
ip6tables: Applying firewall rules: [ OK ]
iptables: Applying firewall rules: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
[FAILED]
Starting auditd: [ OK ]
Starting system logger: [ OK ]
Mounting filesystems: [ OK ]
Retrigger failed udev events[ OK ]
Adding udev persistent rules[ OK ]
Starting kdump:[FAILED]
Starting sshd: [ OK ]
Starting postfix: [ OK ]
Starting crond: [ OK ]
CentOS release 6.8 (Final)
Kernel 2.6.32-642.el6.x86_64 on an x86_64
vm1 login: root
Password:
Last login: Sun Mar 19 18:28:16 on ttyS0
[root@vm1 ~]#
6.查看网卡
[root@vm1 ~]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
没有看见eth0,我们需要修改网卡配置
[root@vm1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.1.100.140
PREFIX=24
GATEWAY=10.1.100.2
DNS1=223.5.5.5
DNS2=223.6.6.6
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
重启网络
故障解决
1.重启网卡报错
[root@vm1 ~]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
[FAILED]
解决办法:
[root@vm1 ~]# rm -rf /etc/udev/rules.d/70-persistent-net.rules
然后重启
[root@vm2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 52:54:00:12:44:F6
inet addr:10.1.100.140 Bcast:10.1.100.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe12:44f6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1418 (1.3 KiB) TX bytes:767 (767.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)