KVM 虚拟化技术之 扩充磁盘

创建一块新磁盘

[root@kvm images]# qemu-img create -f qcow2 vm1-disk.qcow2 2G
Formatting 'vm1-disk1', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 
[root@kvm images]# ls
vm1-disk.qcow2  vm1.img  vm1.qcow2  vm2.img

编辑配置文件

[root@kvm images]# virsh edit vm1

增加

<disk type='file' device='disk'>     
  <driver name='qemu' type='qcow2' cache='none'/>      
  <source file='/home/kvm/images/vm1-disk.qcow2'/>      
  <target dev='hdb' bus='ide'/>      
 </disk>

然后 启动vm1 实例

[root@kvm images]# virsh start vm1
Domain vm1 started

连接虚拟机,查看磁盘

[root@vm1 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000aaa7c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_vm1-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_vm1-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

然后挂载磁盘什么的就不用多说了。