改变kvm镜像大小和使用已经存在的镜像

在这个知识点我们将会用到以下工具:

  • qemu-img
  • losetup
  • tune2fs
  • e2fsck
  • kpartx
  • fdisk
  • resizefs

下面步骤演示我们如何添加空间到先前创建好的raw格式的镜像,扩展root分区和扩展系统镜像。我们的目标是从10G扩展到20G。

(1)首先获取镜像目前大小

root@kvm:# qemu-img info debian.img
image: debian.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 848M

(2)添加额外的10G空间到镜像中

root@kvm:~# qemu-img resize -f raw debian.img +10GB 
Image resized.
注意:并不是所有的镜像格式都支持resize的,在resize前应该转换成raw格式的镜像。

(3)再次获取镜像的大小,看是否有变化

root@kvm:~# qemu-img info debian.img 
image: debian.img
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 848M

二. 使用预先存在的镜像

有很多LINUX发行商他们已经构建好针对QEMU/KVM格式的系统镜像。我们直接来用即可。

(1)去获取 Debian的镜像:

root@kvm:~tmp# wget https://people.debian.org/~aurel32/qemu/amd64/debian_wheezy_amd64_standard.qcow2 
--2017-03-09 22:07:20-- 2 Resolving people.debian.org (people.debian.org)... 2001:41c8:1000:21::21:30, 5.153.231.30 Connecting to people.debian.org (people.debian.org)|2001:41c8:1000:21::21:30|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 267064832 (255M) Saving to: ‘debian_wheezy_amd64_standard.qcow2’ debian_wheezy_amd64_standard.qcow2 100% . [===================================>] 254.69M 35.8MB/s in 8.3s 2017-03-09 22:07:29 (30.9 MB/s) - ‘debian_wheezy_amd64_standard.qcow2’ saved [267064832/267064832]

(2)检查镜象的类型

root@kvm:~tmp# wget https://people.debian.org/~aurel32/qemu/amd64/debian_wheezy_amd64_standard.qcow2 
--2017-03-09 22:07:20-- 2 Resolving people.debian.org (people.debian.org)... 2001:41c8:1000:21::21:30, 5.153.231.30 Connecting to people.debian.org (people.debian.org)|2001:41c8:1000:21::21:30|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 267064832 (255M) Saving to: ‘debian_wheezy_amd64_standard.qcow2’ debian_wheezy_amd64_standard.qcow2 100% . [===================================>] 254.69M 35.8MB/s in 8.3s 2017-03-09 22:07:29 (30.9 MB/s) - ‘debian_wheezy_amd64_standard.qcow2’ saved [267064832/267064832]

(3)下载centos的镜像

root@kvm:/tmp# wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2 --2017-03-09 22:11:34-- https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2Resolving cloud.centos.org (cloud.centos.org)... 2604:4500::2a8a, 136.243.75.209 Connecting to cloud.centos.org (cloud.centos.org)|2604:4500::2a8a|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1361182720 (1.3G) Saving to: ‘CentOS-7-x86_64-GenericCloud.qcow2’
CentOS-7-x86_64-GenericCloud.qcow2 100%[=========================================>] 1.27G 22.3MB/s in 54s
2017-03-09 22:12:29 (24.0 MB/s) - ‘CentOS-7-x86_64-GenericCloud.qcow2’ saved [1361182720/1361182720]
FINISHED --2017-03-09 22:12:29-- Total wall clock time: 54s Downloaded: 1 files, 1.3G in 54s (24.0 MB/s)

(4)检查镜像的类型

root@kvm:~# qemu-img info CentOS-7-x86_64-GenericCloud.qcow2 
image: CentOS-7-x86_64-GenericCloud.qcow2 
file format: qcow2 
virtual size: 8.0G (8589934592 bytes) 
disk size: 1.3G 
cluster_size: 65536 
Format specific information: 
compat: 0.10 
refcount bits: 16 
root@kvm:~#

下面是一些其它发行商LINUX的下地链接:请参考
Official Ubuntu images: https://uec-images.ubuntu.com/releases/
Official CentOS images: https://cloud.centos.org/centos/
Official Debian images: http://cdimage.debian.org/cdimage/openstack/
Official Fedora images: https://alt.fedoraproject.org/cloud/
Official openSUSE : http://download.opensuse.org/repositories/Cloud:/Images:/

 

转自:https://blog.51cto.com/aishangwei/2124463

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值