当我们需要扩展模板镜像的虚拟磁盘大小时,比如原来的虚拟磁盘大小为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. sql server还原数据库文件(.bak)常见问题解决办法笔记

    还原的时候出现错误:备份集中的数据库备份与现有的数据库不同 SQL Server 2005数据库还原出错错误具体信息为:备份集中的数据库备份与现有的A数据库不同 具体操作如下:第一次:新建了数据库A, ...

  2. a标签的css样式四个状态的设计

    表示所有状态下的连接 如 a{color:red} ① a:link:未访问链接 ,如 a:link {color:blue} ② a:visited:已访问链接 ,如 a:visited{color ...

  3. QQ2013登录报文简单分析(不可用于非法用途)

    [NO.1 2013-05-08 00:31:16 046 SEND 115字节]02 31 03 08 25 27 B5 88 6F 91 D2 03 00 00 00 0101 01 00 00 ...

  4. CNAPS Code 查询(招商银行)

    招商银行的妹子实在太傻了,根本不知道什么是CNAPS Code.联行号,完全答非所问. 最后还是自己搞定了,如图: 最后再看看招行人员的英语水平,真是不知道什么是东西:

  5. Servlet下

    HTTP简介 HTTP是 hypertext transfer protocol(超文本传输协议)的简写,它是 TCP/IP 协议集中的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...

  6. wp8.1 Study9:针对不同的屏幕和手机方向调整UI

    一.预备知识 现在不同屏幕大小WP8.1手机越来越多,那么在设计UI时,这需要我们考虑这个问题.在WP中,比例因子(a scale factor)能很好的解决问题,而且在微软系统的PC/平板/手机都是 ...

  7. POJ 1741 树的点分治

    题目大意: 树上找到有多少条路径的边权值和>=k 这里在树上进行点分治,需要找到重心保证自己的不会出现过于长的链来降低复杂度 #include <cstdio> #include & ...

  8. 戴文的Linux内核专题:07内核配置(3)

    转自Linux中国 OK,我们还继续配置内核.还有更多功能等待着去配置. 下一个问题(Enable ELF core dumps (ELF_CORE))询问的是内核是否可以生成内核转储文件.这会使内核 ...

  9. (转载)Htmlparser Filter 简要归纳

    1 . 逻辑关系:与或非 AndFilter()           Creates a new instance of an AndFilter. AndFilter(NodeFilter[] pr ...

  10. T420修改wifi灯闪动模式

    给T420新装了centos7发现默认的配置wifi灯是工作时闪动的,有点晃眼,想改成简单的on 的时候常亮,off的时候常暗的模式 添加配置文件: vi /etc/modprobe.d/wlanle ...