此文档只做学习交流使用,请勿用作其他商业用途 author : 朝阳_tony E-mail : linzhaolover@163.com Create Date: 2016-8-15 10:24:05 Last Change: 2016-8-15 11:14:17 转载请注明出处:http://blog.csdn.net/linzhaolover
在云计算Iaas层中,客户对kvm中image的需求格式各样,我可能就做一个基础的image,然后在上面再安装各类package,以适应不同的业务需求;但是,每个人对image的磁盘分区大小,又有不同的需求,这就需要从外面更改磁盘配置才行,下面就简单介绍一下,我采用的方法,方便大家学习交流
openstack 支持的image比较多,有qcow2 还有raw,我的qcow2 ,所以image后缀是qcow2
glance image-download --file old_image.qcow2 image_uuid注意,由于我的image磁盘只是简单分区,没有lvm分区,所以一个–expand 足矣
virt-resize --expand /dev/sda1 old_image.qcow2 newdisk.qcow Examining old_image.qcow2 ... ********** Summary of changes: /dev/sda1: This partition will be resized from 16.0G to 96.0G. The filesystem ext4 on /dev/sda1 will be expanded using the 'resize2fs' method. /dev/sda2: This partition will be left alone. ********** Setting up initial partition table on newdisk.qcow2 ... Copying /dev/sda1 ... 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 Copying /dev/sda2 ... 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 Expanding /dev/sda1 using the 'resize2fs' method ... Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly. # virt-filesystems --long -h --all -a newdisk.qcow2 Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ext4 - - 96G - #新的系统盘大小 /dev/sda2 filesystem unknown - - 1.0K - /dev/sda5 filesystem swap - - 4.0G - /dev/sda1 partition - - 83 96G /dev/sda # 新系统盘大小 /dev/sda2 partition - - 05 1.0K /dev/sda /dev/sda5 partition - - 82 4.0G /dev/sda /dev/sda device - - - 100G -由于我的image是qcow2的格式,在输出我依然想适用qcow2,所以在-O qcow2 时候输出qcow2.
qemu-img convert -c -O qcow2 newdisk.qcow2 compress_newdisk.qcow2 qemu-img info compress_newdisk.qcow2 image: compress_newdisk.qcow2 file format: qcow2 virtual size: 100G (107374182400 bytes) disk size: 575M # 变小了不少,这样导入glance也是很方便使用 cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false* Reference : * http://serverfault.com/questions/38456/online-resize-of-mounted-ext3-logical-volume http://libguestfs.org/virt-resize.1.html