手动调整KVM镜像image的disk磁盘大小
2016-08-15 11:16
281 查看
声明
此文档只做学习交流使用,请勿用作其他商业用途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的磁盘分区大小,又有不同的需求,这就需要从外面更改磁盘配置才行,下面就简单介绍一下,我采用的方法,方便大家学习交流准备image
openstack 支持的image比较多,有qcow2 还有raw,我的qcow2 ,所以image后缀是qcow2glance image-download --file old_image.qcow2 image_uuid
查看磁盘分区
# qemu-img info old_image.qcow2 image: old_image.qcow2 file format: qcow2 virtual size: 20G (21474836480 bytes) ##虚拟磁盘大小是20G disk size: 1.7G ##当前实际文件大小1.7G cluster_size: 65536 Format specific information: compat: 0.10 # virt-filesystems --long -h --all -a old_image.qcow2 Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ext4 - - 16G - #系统盘,也就是根目录 /dev/sda2 filesystem unknown - - 1.0K - /dev/sda5 filesystem swap - - 4.0G - /dev/sda1 partition - - 83 16G /dev/sda # 系统盘,一会我们扩增这个磁盘 /dev/sda2 partition - - 05 1.0K /dev/sda /dev/sda5 partition - - 82 4.0G /dev/sda /dev/sda device - - - 20G -
创建新的空image
qemu-img create -f qcow2 newdisk.qcow2 100G Formatting 'newdisk.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off
进行磁盘扩展
注意,由于我的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
查看新image大小
qemu-img info newdisk.qcow2 image: newdisk.qcow2 file format: qcow2 virtual size: 100G (107374182400 bytes) disk size: 5.7G # 由1.7G变成5.7G ,这有点大 cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false
压缩转换image
由于我的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
相关文章推荐
- disk image(磁盘镜像)
- HTML Image Auto Resize, HTML图片大小自动调整
- 使用VMware虚拟磁盘管理工具调整磁盘大小
- Azure ARM (18) 将Azure RM Manage Disk托管磁盘的Image,跨订阅迁移
- 通过命令修改KVM磁盘大小
- 调整ESX的VMFS磁盘格式的块大小,让单个虚拟磁盘支持更大容量
- kvm install 报错could not open disk imageXXX: Permission denied
- 使用VMware虚拟磁盘管理工具调整磁盘大小
- Using qemu-img convert physical disk to KVM image
- CentOS无损调整home,root磁盘的大小
- 制作任意大小的根文件系统镜像ramdisk.image.gz
- Windows2003可用无损磁盘分区工具,磁盘大小调整软件
- 调整 VirtualBox 虚拟机的磁盘大小
- VMware vm linux 虚拟机 硬盘空间不足 磁盘最大大小调整 方案
- window 7 调整磁盘空间大小
- iOS UITableViewCell 中 调整imageView 的图片大小
- Accessing the contents of a KVM disk image file
- 自定义(手动调整).net中图像的调色板(How to adjust (customize) image's palette in .net?)
- 使用VMware虚拟磁盘管理工具调整磁盘大小
- VMware vm linux 虚拟机 硬盘空间不足 磁盘最大大小调整 方案