CentOS6 KVM虚拟机添加硬盘和网卡的方法
一:添加硬盘
方法1
直接修改虚拟机的XML文件,这种方式虚拟机要重新virhs start/create 才可以生效,具体略。
方法2
用attach-disk 命令添加
要添加的LV卷/dev/vg01/lv_add01
[root@KVM ~]#virsh attach-disk kvm_ipvs01 /dev/vg01/lv_add01 vdc
即时生效,但是虚拟机配置文件不会添加,重启后就没了,如果要将运行状态保存至XML文件中,可以用dumpxml命令,用之前最好将XML做个备份。
[root@KVM ~]#virsh dumpxml kvm_ipvs01 >kvm_ipvs01.xml
ISO以磁盘方式添加
[root@KVM qemu]# virsh attach-disk KVM_ipvs01 /root/tasks/win2003.iso vdd
Disk attached successfully
即时生效,成功后到ipvs01中查看
[root@KVM_ipvs01 ~]# mount /dev/vdd /mnt/
[root@KVM_ipvs01 ~]# cd /mnt/
[root@KVM_ipvs01 mnt]# ll
total 3520
-r-xr-xr-x 1 root root 112 Mar 7 2007 autorun.inf
-r-xr-xr-x 1 root root 322730 Mar 7 2007 bootfont.bin
dr-xr-xr-x 1 root root 267478 Mar 7 2007 i386
dr-xr-xr-x 1 root root 184 Mar 7 2007 printers
-r-xr-xr-x 1 root root 18809 Mar 7 2007 read1st.htm
-r-xr-xr-x 1 root root 54458 Mar 7 2007 relnotes.htm
-r-xr-xr-x 1 root root 372014 Mar 7 2007 setupenterprise.htm
-r-xr-xr-x 1 root root 2564096 Mar 7 2007 setup.exe
dr-xr-xr-x 1 root root 142 Mar 7 2007 support
-r-xr-xr-x 1 root root 10 Mar 7 2007 win51
-r-xr-xr-x 1 root root 10 Mar 7 2007 win51ia
-r-xr-xr-x 1 root root 10 Mar 7 2007 win51ia.sp2
二:添加网卡
方法1,修改配置文件,略
方法2,
[root@KVM ~]#attach-interface SNKVM_ipvs01 --type bridge --source br1
[root@KVM ~]#domiflist SN349_ipvs01 查看vnet6为新增的网卡
Interface Type Source Model MAC
-------------------------------------------------------
vnet2 bridge br2 virtio 52:54:00:06:88:f4
vnet6 bridge br1 - 52:54:00:8d:de:df
命令修改即时生效,但不会改动虚拟机XML文件,用下面命令更新至xml
[root@KVM ~]#virsh dumpxml kvm_ipvs01 >kvm_ipvs01.xml
进入虚拟机修改网络配置文件,无需重启
[root@ipvs01 network-scripts]# cp -a ifcfg-eth0 ifcfg-eth1
[root@ipvs01 network-scripts]# vi ifcfg-eth1
DEVICE="eth1" #改为eth1
BOOTPROTO="static"
#HWADDR="52:54:00:06:88:F4" #mac注释掉或者改为上面list中的值
IPADDR="10.10.0.90" #修改IP
IPV6INIT="yes"
MTU="1500"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
#UUID="e5b102fb-1fdf-410b-8b59-5fef69b39df9" #注释掉UUID
重启后网卡2生效
[root@KVM_ipvs01 network-scripts]# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
--