扩展KVM镜像的虚拟磁盘大小
当我们需要扩展模板镜像的虚拟磁盘大小时,比如原来的虚拟磁盘大小为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镜像的虚拟磁盘大小的更多相关文章
- KVM镜像管理利器-guestfish使用详解
原文 http://xiaoli110.blog.51cto.com/1724/1568307 KVM镜像管理利器-guestfish使用详解 本文介绍以下内容: 1. 虚拟机镜像挂载及w2k8 ...
- 制作kvm镜像、格式转换
2018-12-25 制作kvm镜像(以centos 7 为例) 执行创建虚拟机命令 virt-install --name centos7_kvm --memory --vcpus= --disk ...
- #openstack centos6 centos7 kvm镜像制作
#openstack centos6 centos7 kvm 镜像制作 openstack windows 2008镜像 制作 http://www.cnblogs.com/elvi/p/800129 ...
- OpenStack手动制作CentOS 7 KVM镜像
在前面讲解KVM的时候,我们已经学习了如何制作KVM镜像,那么制作OpenStack使用的镜像和KVM是有一些区别的. 1. 下载CentOS 7官方ISO安装镜像这里使用国内阿里云的镜像源进行 ...
- 17.KVM安装之虚拟磁盘,安装脚本
1.创建磁盘 vm.list 指定虚拟磁盘名称和主机名 create_vm.sh #创建vm.list中的虚拟磁盘,并指定大小100G #!/bin/bash VM_DIR="/opt ...
- VirtualBox修改现有VDI虚拟磁盘大小
之前创建的虚拟磁盘10G,现需要更大的空间,而又不想使用新增虚拟磁盘的方法. 通过查看资料发现VirtulBox提供的VBoxManage modifyhd命令可以解决,该命令的具体用法: VBoxM ...
- KVM镜像image 转换 调整
qemu-img create -f raw test.raw 8G 创建一个raw格式,大小为8G的镜像. qemu-img info disk1.qcow2 #查看镜像大小及实际占用多少空 ...
- 用vmware workstation制作cloudstack(kvm)镜像及问题解决办法
说明1:vmware workstation镜像是vmdk格式 说明2:cloudstack配置文件目录:/run/libvirt/qemu/ kvm配置文件目录:/etc/libvirt/q ...
- OpenStack制作Windows 2008 KVM镜像
1.下载驱动程序 [root@linux-node1 ~]# cd /usr/local/src [root@linux-node1 src]# wget https://launchpad.net/ ...
随机推荐
- 服务器后端开发系列——《实战Memcached内存缓存系统》
1.实战Memcached缓存系统(1)Memcached基础及示例程序 内容:建筑Memcached背景知识和入门示例程序. 2.实战Memcached缓存系统(2)Memcached Java A ...
- 网卡eth0配置信息
DEVICE=eth0:0 //虚拟网络接口,随意 ONBOOT=yes //系统启动时激活 BOOTPROTO=static //使用静态ip地址 IPADDR=192.168.6.100 //该虚 ...
- uva 10491
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- bzoj 2744: [HEOI2012]朋友圈
#include<cstdio> #include<iostream> #define M 3010 using namespace std; ],u[M*M>>] ...
- c#中使用servicestackredis操作redis
下载地址: https://github.com/mythz/ServiceStack.Redis 添加dll引用: using ServiceStack.Common.Extensions;usin ...
- linux 安装vpn
机器环境 centos Linux wdcp安装脚本和步骤第一步: wget http://www.huzs.net/soft/pptp_onekey/pptpd6.sh sh pptpd6.sh ...
- Core Text概述
本文是我翻译的苹果官方文档<Core Text Overview> Core Text框架是高级的底层文字布局和处理字体的技术.它在Mac OS X v10.5 and iOS 3.2开始 ...
- IOS文件管理-NSFileMangager-NSdata
Ios下的文件管理, Ios下不像windows 文件系统那样可以访问任何的文件目录,如C盘.D盘什么的.在Ios中每个应用程序只能访问当前程序的目录,也即sandbox(沙盒模型). iOS为每个应 ...
- 04-树5 Complete Binary Search Tree
这题也是第二次做,本想第一次做时参考的算法会和老师讲的一样,不想老师讲的算法用在这题感觉还不如思雪园友的算法(http://www.cnblogs.com/sixue/archive/2015/04. ...
- How Android Draws Views
https://developer.android.com/guide/topics/ui/how-android-draws.html