关于LVM的介绍,可以参考乐观的豌豆的书关于逻辑卷管理的章节,非常的详细,讲的很清楚 http://vbird.dic.ksu.edu.tw/linux_basic/0420quota_3.php
创建及扩展raw文件
创建4G空的文件
dd if=/dev/zero of=4G.img bs=1024k count=4096
追加到原有的镜像之后
cat vm1.img 4G.img > vm1_new.img
挂在raw文件
在进行虚拟机故障排除的时候非常有用,下面是挂在方法:
[root@localhost ~]# fdisk -lu conpaas.img
last_lba(): I don't know how to handle files with mode 81a4
You must set cylinders.
You can do this from the extra functions menu.
Disk conpaas.img: 0 MB, 0 bytes
4 heads, 32 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
conpaas.img1 * 2048 4192256 2095104+ 83 Linux
Partition 1 has different physical/logical endings:
phys=(1023, 3, 32) logical=(32752, 0, 1)
查看到sectors单位和分区Start的位置,得到偏移量进行挂载
[root@localhost ~]# mount -o loop,offset=$[2048*512] conpaas.img /mnt
raw文件与lv转换
方式比较简单,直接dd就行了
dd if=/dev/vg/vm1 of=vm1.img bs=10m
dd if=vm1.img of=/dev/vg/vm1 bs=10m(必须先创建vm1逻辑卷,并且要比vm1.img文件大)
下面是virsh命令创建虚拟机用到的配置文件,‘disk’平常用的多的几种方式,以iso文件作为cdrom,raw和lv作为磁盘.
<domain type='xen'>
<name>conpaasimg2g</name>
<uuid>cab3ba1a-f7e9-4c02-8ba3-ca82abaa6312</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/lib64/xen/dtdwdm/qemu-dm</emulator>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/debian.iso'/>
<target dev='hdc' bus='ide'/>
</disk>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/debian.img'/>
<target dev='hda' bus='ide'/>
</disk>
<!--disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/vg/lvol30'/>
<target dev='hdb' bus='ide'/>
</disk-->
<interface type='bridge'>
<mac address='0e:27:1e:50:e4:ea'/>
<source bridge='brvlan121'/>
<script path='vif-bridge'/>
<target dev='vif-1.0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='6009' passwd='123456'/>
</devices>
</domain>
qcow2
下面有一篇关于qcow2简介的文章,收藏一下,先感谢这位作者
Qcow2文件格式简述
http://bbs.linuxtone.org/forum.php?mod=viewthread&tid=24268&fromuid=41256
另外最近研究的xtreemfs中有一个场景,
利用qcow2的快照特性以及xtreemfs的replication来快速部署大量虚拟机,再对xtreemfs熟悉一段时间后再总结。