1. 程式人生 > >KVM虛擬機器磁碟空間擴容

KVM虛擬機器磁碟空間擴容

一,環境說明:

add_disk.img磁碟映像檔案原本是2G大小。

 

二,在宿主機上操作對虛擬機器磁碟空間擴容

# virsh blockresize --domain template --path /iptv/src/add_disk.img --size 4G

Block device '/iptv/src/add_disk.img' is resized

# qemu-img info ./add_disk.img

image: ./add_disk.img

file format: qcow2

virtual size: 4.0G (4294967296 bytes)-----------注意,已經增大了,原來是2G的;

disk size: 200K

cluster_size: 65536

Format specific information:

compat: 1.1

lazy refcounts: false

引數說明:

--path:必須跟的是img檔案的絕對路徑。

 

在虛擬機器中檢視,確實已經增大了:

# fdisk -l

磁碟 /dev/vdb:4294 MB, 4294967296 位元組,8388608 個扇區

Units = 扇區 of 1 * 512 = 512 bytes

扇區大小(邏輯/物理):512 位元組 / 512 位元組

I/O 大小(最小/最佳):512 位元組 / 512 位元組

 

 

附錄:virsh blockresize子命令使用方法介紹

# virsh help blockresize

NAME

blockresize - Resize block device of domain.

SYNOPSIS

blockresize <domain> <path> <size>

DESCRIPTION

Resize block device of domain.

OPTIONS

[--domain] <string> domain name, id or uuid

[--path] <string> Fully-qualified path of block device

[--size] <number> New size of the block device, as scaled integer (default KiB)

 

# man virsh

blockresize domain path size

Resize a block device of domain while the domain is running.

path specifies the absolute path of the block device;(path指定虛擬機器的塊裝置檔案的絕對路徑,也就是說,比如你的虛擬機器的磁碟映像檔案為/tm/test.img,則這裡path的值就是/tmp/test.img) it corresponds to a unique target name (<target dev='name'/>) or source file (<source file='name'/>) for one of the disk devices attached to domain (see also domblklist for listing these names).(這個path指定的塊裝置對要與附屬於域的所有磁碟裝置中的一個獨一無二的target名稱(在xml檔案中,由<target dev='name'/>)或原始檔(在xml檔案中,由<source file='name'/>指定的)指定的塊裝置一致);

size is a scaled integer (see NOTES above) which defaults to KiB (blocks of 1024 bytes) if there is no suffix.(預設是KB,如果不指定size的單位,則使用KB,但也可以使用M,G,T等單位) You must use a suffix of "B" to get bytes (note that for historical reasons, this differs from vol-resize which defaults to bytes without a suffix).