KVM虛擬機(jī)的磁盤(pán)大小修改

kvm 虛擬機(jī)的磁盤(pán)大小可通過(guò)命令:qemu-img resize filename size 來(lái)改,要注意的是resize只支持raw格式的磁盤(pán)文件,如果想更改qcow2等格式的磁盤(pán)大小,需先用qemu-img convert 轉(zhuǎn)換磁盤(pán)格式后才能更改大?。涣硗?,用命令改完大小后需重啟kvm虛擬機(jī),系統(tǒng)才能識(shí)別新添加的磁盤(pán)容量。

1.修改格式
qemu-img是管理qemu虛擬磁盤(pán)的命令行工具集,功能包括查看,創(chuàng)建,檢查,轉(zhuǎn)換,快照,調(diào)整大小等。
下面簡(jiǎn)要看看它的格式轉(zhuǎn)換功能。
root@jun-live:~#man qemu-img
convert [-c] [-p] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-S sparse_size] filename [filename2 [...]] output_filename
Supported formats: raw cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 qed vhdx parallels nbd blkdebug host_cdrom host_floppy host_device file gluster
可以看到,qemu-img支持的格式非常豐富,基本上目前主流的虛擬化磁盤(pán)格式都支持。

示例:qcow2--->raw
root@jun-live:images#qemu-img info ubuntu14.04.img
image: ubuntu14.04.img
file format: qcow2
virtual size: 200G (214748364800 bytes)
disk size: 5G
root@jun-live:images#qemu-img convert -p -f qcow2 -O raw ubuntu14.04.img ubuntu14.04.raw
root@jun-live:images#qemu-img info ubuntu14.04.raw
image: ubuntu14.04.raw
file format: raw
virtual size: 200G (214748364800 bytes)
disk size: 5G
轉(zhuǎn)換時(shí)間與原文件大小正相關(guān),原文件越大時(shí)間越長(zhǎng),反之越短。
轉(zhuǎn)換完成后,會(huì)生成目標(biāo)映像文件,原文件仍保留。

2.修改大小
然后用qemu-img resize更改磁盤(pán)大小
以xp為例,原來(lái)磁盤(pán)的大小為100M,更改為250M
[root@kvmserver ]# qemu-img info xp_4_test.disk01
image: xp_4_test.disk01
file format: raw
virtual size: 99M (100000000 bytes)
disk size: 54M
[root@kvmserver]# qemu-img resize xp_4_test.disk01 +150M //更改大小
Image resized.
[root@kvmserver]# qemu-img info xp_4_test.disk01
image: xp_4_test.disk01
file format: raw
virtual size: 250M (262144000 bytes) //可以看到大小已更改為250M
disk size: 54M
重啟kvm虛擬機(jī)
[root@kvmserver ]# virsh shutdown xp_4_test

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容