当我们需要扩展模板镜像的虚拟磁盘大小时,比如原来的虚拟磁盘大小为20G,现在我们想将其扩展到30G,那么我们可以根据如下步骤来操作。

整个流程可以分为三个阶段:

1、扩展KVM镜像磁盘文件大小到30G。

2、扩展磁盘分区大小为30G。

3、扩展文件系统大小为30G。

假若当前有一个名为 test_extend.img 的模板镜像,其格式为 qcow2, virtual_size为 20G

1、首先可以使用qemu-img来查看该模板镜像的元信息:

root@cason:~/image# qemu-img info test_extend.img
image: test_extend.img
file format: qcow2
virtual size: 20G ( bytes)
disk size: 309M
cluster_size:
Format specific information:
compat: 1.1
lazy refcounts: false
root@cason:~/image#

2、由于需要使用到qemu-nbd,因此我们需要先确认nbd模板已经被load:

root@cason:~/image# lsmod | grep nbd
root@cason:~/image#

执行如上命令发现没有任何输出,则表示当前系统并没有加载nbd模块

3、加载nbd模板,并再次确认(若没有nbd模块,则可以参考这里进行编译安装):

root@cason:~/image# modprobe nbd max_part=
root@cason:~/image# lsmod | grep nbd
nbd
root@cason:~/image#

此时nbd模板已经正常加载了

4、通过qemu-img命令来扩展虚拟磁盘的virtual_size为 30G:

root@cason:~/image# qemu-img resize test_extend.img
Image resized.
root@cason:~/image# qemu-img info test_extend.img
image: test_extend.img
file format: qcow2
virtual size: 30G ( bytes)
disk size: 309M
cluster_size:
Format specific information:
compat: 1.1
lazy refcounts: false
root@cason:~/image#

5、下面通过qemu-nbd挂载test_extend.img到/dev/nbd0设备上:

root@cason:~/image# qemu-nbd -c /dev/nbd0 ./test_extend.img
root@cason:~/image# ll /dev/nbd* | grep nbd0
brw-rw---- root disk , 11月 : /dev/nbd0
brw-rw---- root disk , 11月 : /dev/nbd0p1
root@cason:~/image#

挂载成功后,在/dev/下会看到如上信息,其中/dev/nbd0p1表示该虚拟磁盘仅有一个分区

6、下面开始通过fdisk来扩展虚拟磁盘分区大小:

root@cason:~/image# fdisk /dev/nbd0

Command (m for help): p

Disk /dev/nbd0: 32.2 GB,  bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000e8e8d Device Boot Start End Blocks Id System
/dev/nbd0p1 * Linux Command (m for help): d
Selected partition Command (m for help): p Disk /dev/nbd0: 32.2 GB, bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000e8e8d Device Boot Start End Blocks Id System Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p): p
Partition number (-, default ):
Using default value
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value Command (m for help): p Disk /dev/nbd0: 32.2 GB, bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000e8e8d Device Boot Start End Blocks Id System
/dev/nbd0p1 Linux Command (m for help): a
Partition number (-): Command (m for help): p Disk /dev/nbd0: 32.2 GB, bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000e8e8d Device Boot Start End Blocks Id System
/dev/nbd0p1 * Linux Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
root@cason:~/image#

如此以来,我们已经将该虚拟磁盘的分区大小扩展到了30G

7、至此,我们还需要将文件系统扩展到30G:

root@cason:~/image# e2fsck -fp /dev/nbd0p1
/dev/nbd0p1: Deleted inode has zero dtime. FIXED.
/dev/nbd0p1: / files (0.2% non-contiguous), / blocks root@cason:~/image# resize2fs /dev/nbd0p1
resize2fs 1.42. (-Feb-)
Resizing the filesystem on /dev/nbd0p1 to (4k) blocks.
The filesystem on /dev/nbd0p1 is now blocks long. root@cason:~/image# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected

至此,我们就完成了扩展虚拟磁盘大小的操作。

扩展KVM镜像的虚拟磁盘大小的更多相关文章

  1. KVM镜像管理利器-guestfish使用详解

    原文  http://xiaoli110.blog.51cto.com/1724/1568307   KVM镜像管理利器-guestfish使用详解 本文介绍以下内容: 1. 虚拟机镜像挂载及w2k8 ...

  2. 制作kvm镜像、格式转换

    2018-12-25 制作kvm镜像(以centos 7 为例) 执行创建虚拟机命令 virt-install --name centos7_kvm --memory --vcpus= --disk ...

  3. #openstack centos6 centos7 kvm镜像制作

    #openstack centos6 centos7 kvm 镜像制作 openstack windows 2008镜像 制作 http://www.cnblogs.com/elvi/p/800129 ...

  4. OpenStack手动制作CentOS 7 KVM镜像

    在前面讲解KVM的时候,我们已经学习了如何制作KVM镜像,那么制作OpenStack使用的镜像和KVM是有一些区别的. 1.    下载CentOS 7官方ISO安装镜像这里使用国内阿里云的镜像源进行 ...

  5. 17.KVM安装之虚拟磁盘,安装脚本

    1.创建磁盘 vm.list 指定虚拟磁盘名称和主机名 create_vm.sh    #创建vm.list中的虚拟磁盘,并指定大小100G #!/bin/bash VM_DIR="/opt ...

  6. VirtualBox修改现有VDI虚拟磁盘大小

    之前创建的虚拟磁盘10G,现需要更大的空间,而又不想使用新增虚拟磁盘的方法. 通过查看资料发现VirtulBox提供的VBoxManage modifyhd命令可以解决,该命令的具体用法: VBoxM ...

  7. KVM镜像image 转换 调整

    qemu-img create -f raw test.raw 8G 创建一个raw格式,大小为8G的镜像. qemu-img info disk1.qcow2     #查看镜像大小及实际占用多少空 ...

  8. 用vmware workstation制作cloudstack(kvm)镜像及问题解决办法

    说明1:vmware workstation镜像是vmdk格式 说明2:cloudstack配置文件目录:/run/libvirt/qemu/     kvm配置文件目录:/etc/libvirt/q ...

  9. OpenStack制作Windows 2008 KVM镜像

    1.下载驱动程序 [root@linux-node1 ~]# cd /usr/local/src [root@linux-node1 src]# wget https://launchpad.net/ ...

随机推荐

  1. http错误和异常处理,认证和代理设置

    http错误: import urllib.requestreq = urllib.request.Request('http://www.python.org/fish.html')try:urll ...

  2. Redis系列-存储篇sorted set主要操作函数小结

    redis支持有序集合,即sorted set.sorted set在set的基础上,增加了排序属性,是set的升级版.这里简要谈谈sorted set的常用函数: 1)insert a)  zadd ...

  3. mac 安装memcached服务

    使用homebrew安装,homebrew安装方法http://brew.sh/ 安装memcached服务 brew install memcached 配置开机启动(用brew安装之后下面会提示怎 ...

  4. 单人SVN提交bug

    The working copy "初识tableVIew" failed to commit files. fatal: Unable to create '/Users/zjj ...

  5. shell变量的使用

    转载请标明http://www.cnblogs.com/winifred-tang94/ shell环境中变量有三种类型: a.  环境变量:可以在shell脚本中直接利用“$环境变量名称”的形式引用 ...

  6. SharePoint 2013 开发——SharePoint Designer 2013工作流

    博客地址:http://blog.csdn.net/FoxDave SharePoint Designer 2013为开发者和高级用户提供了两种创建定制工作流的模式: 基于文本的设计器--即我们一直 ...

  7. swift语言之多线程操作和操作队列(上)———坚持51天吃掉大象

    欢迎有兴趣的朋友,参与我的美女同事发起的活动<51天吃掉大象>,该美女真的很疯狂,希望和大家一起坚持51天做一件事情,我加入这个队伍,希望坚持51天每天写一篇技术文章.关注她的微信公众号: ...

  8. ArrayList的使用方法【转载】

    *** Source URL: http://i.yesky.com/bbs/jsp/view.jsp?articleID=889992&forumID=150 *** 1.什么是ArrayL ...

  9. 获取一个 app 的 URL Scheme 的方法:

    获取一个 app 的 URL Scheme 的方法: 上这个网站 URL Schemes 查一下相应的 app 的 URL Scheme 是否有被收录 第一种方法没找到的话,把相应的 app 的 ip ...

  10. C# 跨线程操作控件(简洁)

                                              C# 跨线程操作控件 .net 原则上禁止跨线程访问控件,因为这样可能造成错误的发生.解决此问题的方法有两个: 第一 ...