Libvirt中windows虛擬機器的動態記憶體管理

來源:互聯網
上載者:User

標籤:libvirt   virtio   windows   

很短的前提

Libvirt支援對虛擬機器進行記憶體動態擴充,但是windows虛擬機器首先需要安裝virtio-win驅動。

KVM提供的virtio-win驅動:
http://www.linux-kvm.org/page/WindowsGuestDrivers/Download_Drivers
http://alt.fedoraproject.org/pub/alt/virtio-win/

以下是栗子

鏡像:windows2008R2,64位
virtio-win:virtio-win-0.1-100.iso
disk:差分鏡像(qemu-img create -f qcow2 -b ./windows_2008R2_x86_64 disk)

使用qemu命令啟動虛擬機器並載入virtio驅動:

qemu-system-x86_64 -hda ./windows_2008R2_x86_64 -drive file=./disk,if=virtio -drive file=./virtio-win-0.1-100.iso,media=cdrom,index=1 -net nic,model=virtio -net user -boot d -vga std -m 4096 -usbdevice tablet -vnc :50 -enable-kvm

通過vnc訪問該虛擬機器,進行以下操作:

  1. 進入“裝置管理員” - “系統裝置”,安裝“未知裝置”為“Virtio Balloon Driver”
  2. 將virtio-win光碟機中的WIN7/X86目錄拷貝到“c:/Program files/Balloon”
  3. 以管理員身份使用cmd命令列進入上述目錄
  4. 執行“BLNSVR.exe -i”用以安裝BLNSVR服務
  5. 順利關機儲存設定

至此,該disk檔案已經具備了擷取詳細記憶體資訊、動態調整記憶體大小的能力,驗證的方法如下:

記憶體詳細資料擷取驗證:

1.使用該disk檔案啟動虛擬機器,在xml檔案中添加如下段落用於啟用balloon裝置,同時設定採集周期為10s

...<devices>    <memballoon model=‘virtio‘>      <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x02‘ function=‘0x0‘/>      <stats period=‘10‘/>    </memballoon>  </devices></domain>

2.採集時間可以手動設定

virsh dommemstat <dommain> --period <time(sec)>

3.擷取虛擬機器的當前記憶體用量

virsh dommemstat <dommain>

記憶體動態大小調整驗證:

1.關閉虛擬機器

virsh destroy <domain>

2.設定虛擬機器最大記憶體值(如果已經寫入xml檔案可以跳過)

virsh setmaxmem <domain> --size <max_size>

3.啟動虛擬機器

virsh start <domain>

4.動態調整

virsh setmem <domain> --size <mem_size>

有點不同於linux系統的地方在於windows會顯示設定的最大記憶體值,會讓人產生誤解。

參考資料
https://pve.proxmox.com/wiki/Dynamic_Memory_Management#Ballooning

另一個地址

Libvirt中windows虛擬機器的動態記憶體管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.