kvm之Linux虚拟机在线扩展磁盘
kvm虚拟机也支持在线扩展磁盘功能,在线扩展有特定的使用环境,主要用于不能随便停用的生产环境中,本文以hadoop为例具体步骤如下:1,查看现有磁盘1
2
3
4
5
6
7
8
9
10
11
12
13
# virsh list --all
Id Name State
----------------------------------------------------
1 win7 running
17 hadoop1 running
18 hadoop4 running
20 hadoop2 running
- hadoop3 shut off
# virsh domblklist hadoop1
Target Source
------------------------------------------------
vda /images/test/hadoop1.qcow2
hdc -
2,创建一块qcow2虚拟磁盘
1
2
3
# qemu-img create -f qcow2 hadoop1_add01.qcow2 5G
Formatting 'hadoop1_add01.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536
#
3,在线添加这台qcow2虚拟磁盘
1
2
3
4
5
6
7
8
# virsh attach-disk hadoop1 /images/test/hadoop1_add01.qcow2 vdb --cache=none --subdriver=qcow2
Disk attached successfully
# virsh domblklist hadoop1
Target Source
------------------------------------------------
vda /images/test/hadoop1.qcow2
vdb /images/test/hadoop1_add01.qcow2
hdc -
4,进入虚拟机查看,如下图:
5,然后进入系统里边划分区
fdisk /dev/vdb
6,划分逻辑卷LVM省略,前边的可以参考。
7,修改虚拟机配置文件,把新增的磁盘配置写到虚拟机磁盘配置
(1)查看当前虚拟机hadoop1的磁盘配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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配置文件中
1
2
3
4
5
6
7
<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>
当把所有的配置文件写到虚拟机的配置信息后,及时重启也能生效。
页:
[1]