kvm linux虛擬機在線擴展磁盤


說明:

1) vmware ESXi虛擬化平台也支持這台在線擴展磁盤功能。

2) kvm虛擬機也支持在線擴展磁盤功能,在線擴展有特定的使用環境,主要用於不能隨便停用的生產環境中。

3) 經過測試KVM在線擴展磁盤功能只適用於RHEL/CentOS/OEL6.x環境,5.x不支持在線的擴展磁盤,其它ubuntu等其它Linux我沒有測試,不做評論。

本文出自:http://koumm.blog.51cto.com

本文為了測試,專門安裝了OEL6.3虛擬機。

1.  安裝oel6.3虛擬機

安裝oeltest02虛擬機

# qemu-img create -f qcow2  /data/test02.qcow2  7G    
# virt-install --name=oeltest02 --os-variant=RHEL6.3 --ram 512 --vcpus=1 --disk path=/data/test01.qcow2,format=qcow2,size=7,bus=virtio --accelerate --cdrom /data/iso/oel63x64.iso --vnc --vncport=5911 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole 

目的是使用實驗環境磁盤改為virtio驅動下的vda磁盤,這種scsi磁盤可以熱插撥,可以動態添加。

整個安裝過程略,虛擬機各種配置略,可以參考系列文章前面的內容。

2.  給oeltest02虛擬機在線添加磁盤

(1)  查看現有磁盤

[root@node1 data]# virsh domblklist oeltest02

image

(2) 創建一塊qcow2虛擬磁盤

[root@node1 data]# qemu-img create -f qcow2 test02_add01.qcow2 4G

image

(3) 在線添加這台qcow2虛擬磁盤

# virsh attach-disk oeltest02 /data/test02_add01.qcow2 vdb --cache=none --subdriver=qcow2

image

image

(4) 進入oeltest02虛擬機查看添加磁盤情況

[root@node1 data]#    
[root@node1 data]# virsh console oeltest02    
連接到域 oeltest02    
Escape character is ^] 

Oracle Linux Server release 6.3   
Kernel 2.6.32-279.el6.x86_64 on an x86_64 

test02 login: root   
Password:     
Last login: Thu Sep 12 00:46:27 on ttyS0    
[root@test02 ~]# 

[root@test02 ~]# fdisk –l

即可看到剛才添加的磁盤已經被虛擬機適別到了。

image

可以看到有兩個scsi存儲設備。

image

注:再次說明只有RHEL/CentOS/OEL6.x版本在線添加磁盤,虛擬機直接可以在線識別。

(5) 修改虛擬機配置文件添加新增磁盤配置

1)  查看當前虛擬機配置文件

這里查看到的虛擬機配置文件是內存中存放的配置,重啟后會消失,需要將新添的磁盤配置保存到配置文件中。

[root@node1 data]# virsh dumpxml oeltest02   
<domain type='kvm' id='5'>    
  <name>oeltest02</name>    
  <uuid>2dfb812d-703c-3d5b-68b7-516f618e7944</uuid>    
  <memory unit='KiB'>1048576</memory>    
  <currentMemory unit='KiB'>1048576</currentMemory>    
  <vcpu placement='static'>2</vcpu>    
  <os>    
    <type arch='x86_64' machine='rhel6.4.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='/data/test02.qcow2'/>    
      <target dev='vda' bus='virtio'/>    
      <alias name='virtio-disk0'/>    
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>    
    </disk>    
    <disk type='file' device='disk'>       
      <driver name='qemu' type='qcow2' cache='none'/>        
      <source file='/data/test02_add01.qcow2'/>        
      <target dev='vdb' bus='virtio'/>        
      <alias name='virtio-disk1'/>        
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' 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'>    
      <alias name='usb0'/>    
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' 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:ff:2f:70'/>    
      <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/3'/>    
      <target port='0'/>    
      <alias name='serial0'/>    
    </serial>    
    <console type='pty' tty='/dev/pts/3'>    
      <source path='/dev/pts/3'/>    
      <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='0x05' function='0x0'/>    
    </memballoon>    
  </devices>    
  <seclabel type='none'/>    
</domain> 

[root@node1 data]# 

2) 保存新增磁盤配置

[root@node1 data]# virsh edit oeltest02

image

說明:對RHEL/CentOS/OEL5.x版本虛擬機在線添加磁盤按照第4小節處理。

3. 將新增磁盤並入虛擬機邏輯卷中

(1) 分區過程如下

[root@test02 ~]# fdisk /dev/vdb

[root@test02 ~]# partprobe 

(2) 創建邏輯卷過程如下

 

225838141.jpg

到此oeltest02虛擬機在線添加磁盤並在線擴展磁盤成功。

2014-03-14日修改, 感謝xiaoli110提供如下解決辦法。

4. OEL/RHEL/CentOS5.x虛擬機在線添加磁盤過程

說明:OEL/RHEL/CentOS5.x虛擬機按照上面的過程在線添加磁盤,磁盤識別不出來,需要在添加磁盤后,修改配置文件后重啟,不能在線識別到磁盤。需要采用如下方式處理,即可以實現在線添加磁盤的功能。

(1) 先登錄進虛擬機執行兩次如下命令

modprobe acpiphp
modprobe acpiphp

wKioL1MjDFrBi72iAAF25zSS1v0744.jpg

(2) 虛擬主機上創建磁盤並添加磁盤

wKioL1MjDKXwEp2AAAIpagxtF2k671.jpg

以上方式要感謝xiaoli110網友指教。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM