扩展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/ ...
随机推荐
- 如何使用JCONSOLE 监控eclipse的tomcat
在默认情况下,使用jconsole 监控本地tomcat 是不需要任何配置的,直接连接就可以监控tomcat. 但是在eclipse 下启动是监控不了. 解决方法: 设置jvm参数: ...
- C#入门篇6-8:字符串操作 深入研究字符串的内存驻留机制
//字符串的内存驻留机制 public static void Test() { //当有多个字符串变量包含了同样的字符串实际值时, //CLR可能不会为它们重复地分配内存,而是让它们统统指向同一个字 ...
- 克隆机器后eth1变为eth0问题
1. 清空该文件 2.进入网络配置文件把HADDR 和UUID注释掉,并重启 3.成功修改eth0 4. 4.可以结合这篇帖子来看 http://www.cnblogs.com/zydev/p/4 ...
- Mongodb Management Studio
1.服务器管理功能添加服务器,删除服务器 2.服务器,数据库,表,列,索引,树形显示和状态信息查看 3.查询分析器功能.支持select,insert,Delete,update支持自定义分页函数 $ ...
- if语句使用
package yuan; public class Yuan { public static void main(String[] args) { int a = 1; int b = 8; int ...
- C#遍历窗体所有控件或某类型所有控件
//遍历窗体所有控件, foreach (Control control in this.Controls) { //遍历后的操作... control.Enabled = false; } 遍历某个 ...
- left join 多表关联查询
A表--left join-- B表 --on--A和B表相等的字段-- 此时AB已关联 --left join--C表--on --A(或B)与C表相等的字段 此时ABC已关联 --left j ...
- 2.4.2电子书fb.c文件
显示层面头文件 定义结构体,为显示统一标准 int (*DeviceInit)(void); 显示类驱动初始化 int (*ShowPixel)(int iPenX, int iPenY, unsig ...
- [开发笔记]-多线程异步操作如何访问HttpContext?
如何获取文件绝对路径? 在定时器回调或者Cache的移除通知中,有时确实需要访问文件,然而对于开发人员来说, 他们并不知道网站会被部署在哪个目录下,因此不可能写出绝对路径, 他们只知道相对于网站根目录 ...
- MBProgressHUD.h file not found
MBProgressHUD框架,怎么我导入MBProgressHUD+MJ.h会报错.(即MBProgressHUD+MJ根本不存在),我看其他人的视屏又可以导入 MBProgressHUD.h fi ...