标签:kvm lvm
kvm虚拟机也支持在线扩展磁盘功能,在线扩展有特定的使用环境,主要用于不能随便停用的生产环境中,本文以hadoop为例具体步骤如下:
1,查看现有磁盘
[root@KVM test]# virsh list --all Id Name State ---------------------------------------------------- 1 win7 running 17 hadoop1 running 18 hadoop4 running 20 hadoop2 running - hadoop3 shut off [root@KVM test]# virsh domblklist hadoop1 Target Source ------------------------------------------------ vda /images/test/hadoop1.qcow2 hdc -
2,创建一块qcow2虚拟磁盘
[root@KVM test]# qemu-img create -f qcow2 hadoop1_add01.qcow2 5G Formatting ‘hadoop1_add01.qcow2‘, fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 [root@KVM test]#
[root@KVM test]# virsh attach-disk hadoop1 /images/test/hadoop1_add01.qcow2 vdb --cache=none --subdriver=qcow2 Disk attached successfully [root@KVM test]# virsh domblklist hadoop1 Target Source ------------------------------------------------ vda /images/test/hadoop1.qcow2 vdb /images/test/hadoop1_add01.qcow2 hdc -
5,然后进入系统里边划分区
fdisk /dev/vdb
6,划分逻辑卷LVM省略,前边的可以参考。
7,修改虚拟机配置文件,把新增的磁盘配置写到虚拟机磁盘配置
(1)查看当前虚拟机hadoop1的磁盘配置
[root@KVM test]# virsh dumpxml hadoop1 <domain type=‘qemu‘ id=‘17‘> <name>hadoop1</name> <uuid>919f0921-0736-ad5b-780b-a440de2f35cb</uuid> <memory unit=‘KiB‘>524288</memory> <currentMemory unit=‘KiB‘>524288</currentMemory> <vcpu placement=‘static‘>1</vcpu> <os> <type arch=‘x86_64‘ machine=‘rhel6.6.0‘>hvm</type> <boot dev=‘hd‘/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset=‘utc‘/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/> <source file=‘/images/test/hadoop1.qcow2‘/> <target dev=‘vda‘ bus=‘virtio‘/> <alias name=‘virtio-disk0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x05‘ function=‘0x0‘/> </disk> <disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/> <source file=‘/images/test/hadoop1_add01.qcow2‘/> <target dev=‘vdb‘ bus=‘virtio‘/> <alias name=‘virtio-disk1‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x07‘ function=‘0x0‘/> </disk> <disk type=‘block‘ device=‘cdrom‘> <driver name=‘qemu‘ type=‘raw‘/> <target dev=‘hdc‘ bus=‘ide‘/> <readonly/> <alias name=‘ide0-1-0‘/> <address type=‘drive‘ controller=‘0‘ bus=‘1‘ target=‘0‘ unit=‘0‘/> </disk> <controller type=‘usb‘ index=‘0‘ model=‘ich9-ehci1‘> <alias name=‘usb0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x7‘/> </controller> <controller type=‘usb‘ index=‘0‘ model=‘ich9-uhci1‘> <alias name=‘usb0‘/> <master startport=‘0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x0‘ multifunction=‘on‘/> </controller> <controller type=‘usb‘ index=‘0‘ model=‘ich9-uhci2‘> <alias name=‘usb0‘/> <master startport=‘2‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x1‘/> </controller> <controller type=‘usb‘ index=‘0‘ model=‘ich9-uhci3‘> <alias name=‘usb0‘/> <master startport=‘4‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x2‘/> </controller> <controller type=‘ide‘ index=‘0‘> <alias name=‘ide0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x01‘ function=‘0x1‘/> </controller> <interface type=‘bridge‘> <mac address=‘52:54:00:b6:bf:1f‘/> <source bridge=‘br0‘/> <target dev=‘vnet1‘/> <model type=‘virtio‘/> <alias name=‘net0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x03‘ function=‘0x0‘/> </interface> <serial type=‘pty‘> <source path=‘/dev/pts/2‘/> <target port=‘0‘/> <alias name=‘serial0‘/> </serial> <console type=‘pty‘ tty=‘/dev/pts/2‘> <source path=‘/dev/pts/2‘/> <target type=‘serial‘ port=‘0‘/> <alias name=‘serial0‘/> </console> <input type=‘mouse‘ bus=‘ps2‘/> <graphics type=‘vnc‘ port=‘5911‘ autoport=‘no‘ listen=‘0.0.0.0‘> <listen type=‘address‘ address=‘0.0.0.0‘/> </graphics> <video> <model type=‘cirrus‘ vram=‘9216‘ heads=‘1‘/> <alias name=‘video0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x02‘ function=‘0x0‘/> </video> <memballoon model=‘virtio‘> <alias name=‘balloon0‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x06‘ function=‘0x0‘/> </memballoon> </devices> </domain>
(2)把以下配置添加到/etc/libvirt/qemu/hadoop1.xml配置文件中
<disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/> <source file=‘/images/test/hadoop1_add01.qcow2‘/> <target dev=‘vdb‘ bus=‘virtio‘/> <alias name=‘virtio-disk1‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x07‘ function=‘0x0‘/> </disk>
当把所有的配置文件写到虚拟机的配置信息后,及时重启也能生效。
本文出自 “清风明月” 博客,请务必保留此出处http://liqingbiao.blog.51cto.com/3044896/1741252
KVM虚拟化笔记(十一)------kvm Linux虚拟机在线扩展磁盘
标签:kvm lvm
原文地址:http://liqingbiao.blog.51cto.com/3044896/1741252