爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      KVM虚拟化-存储管理和磁盘扩容

      首页 知识中心 存储 文章详情页

      KVM虚拟化-存储管理和磁盘扩容

      2023-08-09 06:47:47 阅读次数:434

      KVM,存储,虚拟化

      KVM存储模式

      基于文件系统的存储

      • dir: Filesystem Directory 需要有挂载点的文件系统
      • fs: Pre-Formatted Block Device 无需挂载的文件系统,如:位于SAN存储的文件系统,可支持多个主机同时访问,而本地文件系统不支持
      • netfs: Network Exported Directory 网络文件系统,比如:NFS,SAMBA等

      基于设备的存储 - 无需文件系统,性能更好,但可管理性差,无法实现快照

      • Disk: Physical Disk Device
      • Iscsi: isCSI Target
      • logical:LVM Volume Group

      虚拟磁盘类型

      • 固定Fixed
      在配置时,指定磁盘大小
      不管在虚拟磁盘上实际存储多少数据,都将占用相同大小宿主机的磁盘空间
      • 动态Dynamic
      初始空间占用小
      随着空间的使用逐渐增长到最大容量,但是只根据需求使用更多的空间
      • 差异Differencing
      因为创建是差异磁盘,所以只保存变更的数据
      例如,将操作系统安装在父盘,然后创建差异化磁盘来执行进一步配置

      44-KVM虚拟化-存储管理和磁盘扩容

      虚拟镜像文件格式

      KVM 上的磁盘镜像格式包括:

      • raw
      此为默认磁盘格式,但并是一种真正的磁盘格式,而是代表虚拟机所使用的原始镜像,它并不存储元数据,因此可作为保证虚拟机兼容性的候选方案。然而,也正因为它不存储元数据,因此不支持某些高级特往,比如快照和压缩等格式简单,容易转换为其他的格式。
      如果主机文件系统允许,raw 文件可以是预分配(pre-allocated)或 稀疏(sparse)。稀疏文件根据需求分配主机磁盘空间,因此它是一种精简配置形式(thin provisioning)。预分配文件的所有空间需要被预先分配,但它比稀疏文件性能好。当对磁盘 I/O 性能要求非常高,而且通常不需要通过网络传输镜像文件时,可以使用 raw文件
      优点 : 性能好
      缺点 : 空间占用大,功能较少,生产不推荐使用
      • cow
      copy-on-write格式,昙花一现
      • qcow
      QEMU早期的copy-on-write格式,过渡性方案
      • qcow2
      qcow2 镜像文件提供许多高级磁盘镜像特征,如快照、压缩及加密。它们可以用来代表通过模板镜像创建的虚拟机。因为只有虚拟机写入的扇区部分才会分配在镜像中,所以 qcow2 文件的网络传输效率较高。RHEL 7.0 及更新版本支持 qcow2 v3 镜像文件格式按需进行分配磁盘空间,不管文件系统是否支持
      优点 :
      空间节约,功能丰富
      支持快照
      支持zlib的磁盘压缩
      支持AES的加密
      缺点 : 性能较差,生产推荐使用

      案例:查看不同磁盘文件格式支持选项
      #raw
      [root@ubuntu2204 ~]#qemu-img create -f raw -o ?
      Supported raw options:
      size=<size> - Virtual disk size

      The protocol level may support further options.
      Specify the target filename to include those options.

      #qcow2
      [root@ubuntu2204 ~]#qemu-img create -f qcow2 -o ?
      Supported qcow2 options:
      backing_file=<str> - File name of a base image
      backing_fmt=<str> - Image format of the base image
      cluster_size=<size> - qcow2 cluster size
      compat=<str> - Compatibility level (v2 [0.10] or v3 [1.1])
      compression_type=<str> - Compression method used for image cluster compression
      data_file=<str> - File name of an external data file
      data_file_raw=<bool (on/off)> - The external data file must stay valid as a raw image
      encrypt.cipher-alg=<str> - Name of encryption cipher algorithm
      encrypt.cipher-mode=<str> - Name of encryption cipher mode
      encrypt.format=<str> - Encrypt the image, format choices: 'aes', 'luks'
      encrypt.hash-alg=<str> - Name of encryption hash algorithm
      encrypt.iter-time=<num> - Time to spend in PBKDF in milliseconds
      encrypt.ivgen-alg=<str> - Name of IV generator algorithm
      encrypt.ivgen-hash-alg=<str> - Name of IV generator hash algorithm
      encrypt.key-secret=<str> - ID of secret providing qcow AES key or LUKS passphrase
      encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
      extended_l2=<bool (on/off)> - Extended L2 tables
      lazy_refcounts=<bool (on/off)> - Postpone refcount updates
      preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
      refcount_bits=<num> - Width of a reference count entry in bits
      size=<size> - Virtual disk size

      The protocol level may support further options.
      Specify the target filename to include those options.
      • vmdk
      VMware环境当中默认使用的磁盘格式
      • vhd/vhdx
      微软默认采用的文件格式
      • vdi
      VirtualBox 采用的文件格式

      查看KVM支持的磁盘格式

      [root@ubuntu2204 ~]#qemu-img --help|grep Support
      Supported formats: blkdebug blklogwrites blkverify bochs cloop compress copy-before-write copy-on-read dmg file ftp ftps gluster host_cdrom host_device http https iscsi iser luks nbd null-aio null-co nvme parallels preallocate qcow qcow2 qed quorum raw rbd replication ssh throttle vdi vhdx vmdk vpc vvfat

      使用qemu-img管理虚拟磁盘文件

      #qemu-img 包括以下子命令
      check #检查完整性
      create #创建镜像
      commit #提交更改
      compare #比较
      convert #转换
      info #获得信息
      map #映射
      snapshot #快照管理
      rebase #在已有的镜像的基础上创建新的镜像
      resize #调整大小
      amend #修订镜像格式选项

      #格式:qemu-img create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backing_fmt] [-u] [-o options] filename [size]
      • 案例:创建raw格式文件
      #案例1:创建raw格式非稀疏文件
      [root@ubuntu2204 ~]#dd if=/dev/zero of=/opt/vm2.img bs=1M count=1024
      1024+0 records in
      1024+0 records out
      1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.2694 s, 171 MB/s
      [root@ubuntu2204 ~]#qemu-img info /opt/vm2.img
      image: /opt/vm2.img
      file format: raw
      virtual size: 1 GiB (1073741824 bytes) --> 显示1G
      disk size: 1 GiB --> 实际占用磁盘1G

      #案例2:创建raw格式稀疏文件
      [root@ubuntu2204 ~]#dd if=/dev/zero of=/opt/vm3.img bs=1M count=0 seek=1024
      0+0 records in
      0+0 records out
      0 bytes copied, 0.000217691 s, 0.0 kB/s
      [root@ubuntu2204 ~]#qemu-img info /opt/vm3.img
      image: /opt/vm3.img
      file format: raw
      virtual size: 1 GiB (1073741824 bytes) --> 显示1G
      disk size: 0 B --> 实际占用磁盘1字节

      #案例3:指定将非稀疏文件复制为稀疏格式文件
      [root@ubuntu2204 ~]#cp --sparse=always /opt/vm2.img /opt/vm2.img.bk
      [root@ubuntu2204 ~]#qemu-img info /opt/vm2.img
      image: /opt/vm2.img
      file format: raw
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 1 GiB
      [root@ubuntu2204 ~]#qemu-img info /opt/vm2.img.bk
      image: /opt/vm2.img.bk
      file format: raw
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 0 B

      #案例4:指定将稀疏文件复制为非稀疏格式文件
      [root@ubuntu2204 ~]#cp --sparse=never /opt/vm3.img /opt/vm3.img.bk
      [root@ubuntu2204 ~]#qemu-img info /opt/vm3.img
      image: /opt/vm3.img
      file format: raw
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 0 B
      [root@ubuntu2204 ~]#qemu-img info /opt/vm3.img.bk
      image: /opt/vm3.img.bk
      file format: raw
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 1 GiB
      • 案例:创建qcow2格式文件
      #qcow2 格式选项
      backing_file #指定后端镜像文件
      backing_fmt #设置后端镜像的镜像格式
      cluster_size #设置镜像中的簇大小,取值在512到2M之间,默认值为64K
      preallocation #设置镜像文件空间的预分配模式
      encryption #用于设置加密

      [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm1.img 2g
      Formatting '/opt/vm1.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2147483648 lazy_refcounts=off refcount_bits=16
      [root@ubuntu2204 ~]#qemu-img info /opt/vm1.img
      image: /opt/vm1.img
      file format: qcow2
      virtual size: 2 GiB (2147483648 bytes)
      disk size: 196 KiB
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      extended l2: false
      • 案例:检查虚拟磁盘
      *对于关机状态的虚拟机磁盘,可以检查文件错误
      [root@centos8 ~]#virsh list
      Id Name State
      ----------------------------------------------------
      2 centos8 running
      [root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos8.qcow2
      qemu-img: Could not open '/var/lib/libvirt/images/centos8.qcow2': Failed to get
      shared "write" lock
      Is another process using the image [/var/lib/libvirt/images/centos8.qcow2]?
      [root@centos8 ~]#virsh suspend centos8
      Domain centos8 suspended
      [root@centos8 ~]#virsh list
      Id Name State
      ----------------------------------------------------
      2 centos8 paused
      [root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos8.qcow2
      qemu-img: Could not open '/var/lib/libvirt/images/centos8.qcow2': Failed to get
      shared "write" lock
      Is another process using the image [/var/lib/libvirt/images/centos8.qcow2]?
      [root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos7.qcow2
      No errors were found on the image.
      25572/327680 = 7.80% allocated, 1.44% fragmented, 0.00% compressed clusters
      Image end offset: 1676869632

      磁盘预分配策略

      raw 文件的预分配策略和文件系统是否支持有关,而qcow2则无关

      • off
      此为缺省策略,即不使用预分配策略,预分配后的虚拟磁盘占用空间很小,不属于稀疏映像类型,生成的磁盘文件占用空间很小
      • metadata
      只预分配元数据(metadata),预分配后的磁盘文件属于稀疏映像类型,相当于vmware中的磁盘置备选项: Thin Provision(精简配置)
      生成的磁盘文件为稀疏格式,实际占用的空间比off策略稍大一些
      • falloc
      分配文件的块并标识它们的状态为未初始化,即只分配空间,但不置零(不格式化). 预分配后的虚拟磁盘属于非稀疏映像类型,相对full模式来说,创建虚拟磁盘的速度要快很多,相当于vmware中的磁盘置备选项:厚置备延迟置零
      生成的磁盘文件实际占用的空间和分配的空间相同大小
      • full
      分配所有磁盘空间并置零,预分配后的虚拟磁盘属于非稀疏映像类型,创建最慢,相当于vmware中的磁盘置备选项: 厚置备置零
      生成的磁盘文件实际占用的空间和分配的空间相同大小

      案例:创建预分配置策略

      #案例1:默认开启默认预分配策略 - 稀疏格式,根据实际需要自动分配磁盘空间
      [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm1.img 2g
      Formatting '/opt/vm1.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2147483648 lazy_refcounts=off refcount_bits=16
      [root@ubuntu2204 ~]#qemu-img info /opt/vm1.img
      image: /opt/vm1.img
      file format: qcow2
      virtual size: 2 GiB (2147483648 bytes)
      disk size: 196 KiB
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      extended l2: false

      #案例2:指定off关闭预分配
      [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm2.img 1g -o preallocatinotallow=off
      Formatting '/opt/vm2.img', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=off compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16
      [root@ubuntu2204 ~]#qemu-img info /opt/vm2.img
      image: /opt/vm2.img
      file format: qcow2
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 196 KiB
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      extended l2: false

      #案例3:指定预分配metadata
      [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm3.img 1g -o preallocatinotallow=metadata
      Formatting '/opt/vm3.img', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=metadata compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16
      [root@ubuntu2204 ~]#qemu-img info /opt/vm3.img
      image: /opt/vm3.img
      file format: qcow2
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 324 KiB
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      extended l2: false

      #案例4:指定预分配falloc
      [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm4.img 1g -o preallocatinotallow=falloc
      Formatting '/opt/vm4.img', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=falloc compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16
      [root@ubuntu2204 ~]#qemu-img info /opt/vm4.img
      image: /opt/vm4.img
      file format: qcow2
      virtual size: 1 GiB (1073741824 bytes)
      disk size: 1 GiB
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      extended l2: false

      #文件系统显示大小
      [root@ubuntu2204 ~]#ll -h /opt/vm*
      -rw-r--r-- 1 root root 193K Jan 1 17:40 /opt/vm1.img
      -rw-r--r-- 1 root root 193K Jan 1 18:04 /opt/vm2.img
      -rw-r--r-- 1 root root 1.1G Jan 1 18:08 /opt/vm3.img
      -rw-r--r-- 1 root root 1.1G Jan 1 18:08 /opt/vm4.img
      #查看真实大小
      [root@ubuntu2204 ~]#du -h /opt/vm*
      196K /opt/vm1.img
      196K /opt/vm2.img
      324K /opt/vm3.img
      1.1G /opt/vm4.img

      虚拟磁盘格式转换

      #qemu-img 可以将不同格式的虚拟磁盘文件进行格式转化

      #案例:将vmdk转化为raw 和qcow2格式
      [root@centos8 ~]#qemu-img info CentOS8.2.vmdk
      image: CentOS8.2.vmdk
      file format: vmdk
      virtual size: 200G (214748364800 bytes)
      disk size: 1.6G
      cluster_size: 65536
      Format specific information:
      cid: 2898578192
      parent cid: 4294967295
      create type: monolithicSparse
      extents:
      [0]:
      virtual size: 214748364800
      filename: CentOS8.2.vmdk
      cluster size: 65536
      format:
      #默认转化为raw格式
      [root@centos8 ~]#qemu-img convert CentOS8.2.vmdk CentOS8.2.img
      #比较大小
      [root@centos8 ~]#ll -h CentOS8.2.vmdk CentOS8.2.img
      -rw-r--r-- 1 root root 1.6G Sep 20 16:00 CentOS8.2.vmdk
      -rw-r--r-- 1 root root 200G Sep 20 16:10 CentOS8.2.img
      [root@centos8 ~]#du -h CentOS8.2.vmdk CentOS8.2.img
      1.6G CentOS8.2.vmdk
      1.5G CentOS8.2.img
      [root@centos8 ~]#qemu-img info CentOS8.2.img
      image: CentOS8.2.img
      file format: raw
      virtual size: 200G (214748364800 bytes)
      disk size: 1.4G
      [root@centos8 ~]#mv CentOS8.2.img /var/lib/libvirt/images/
      [root@centos8 ~]#virt-install --import --name=centos8-test2 --vcpus=1 --ram=2048
      --disk bus=scsi,path=/var/lib/libvirt/images/CentOS8.2.img --network
      network=default --graphics vnc,listen=0.0.0.0 --os-type=Linux --osvariant=
      centos8 --noautoconsole --boot hd
      #转化为qcow2格式
      [root@centos8 ~]#qemu-img convert -f vmdk -O qcow2 CentOS8.2.vmdk
      CentOS8.2.qcow2
      #比较大小
      [root@centos8 ~]#ll -h CentOS8.2.vmdk CentOS8.2.qcow2
      -rw-r--r-- 1 root root 1.6G Sep 20 16:00 CentOS8.2.vmdk
      -rw-r--r-- 1 root root 1.6G Sep 20 16:12 CentOS8.2.qcow2
      [root@centos8 ~]#du -h CentOS8.2.vmdk CentOS8.2.qcow2
      1.6G CentOS8.2.vmdk
      1.6G CentOS8.2.qcow2
      [root@centos8 ~]#qemu-img info CentOS8.2.qcow2
      image: CentOS8.2.qcow2
      file format: qcow2
      virtual size: 200G (214748364800 bytes)
      disk size: 1.5G
      cluster_size: 65536
      Format specific information:
      compat: 1.1
      lazy refcounts: false
      refcount bits: 16
      corrupt: false
      [root@centos8 ~]#mv CentOS8.2.qcow2 /var/lib/libvirt/images/
      [root@centos8 ~]#virt-install --import --name=centos8-test3 --vcpus=1 --ram=2048
      --disk bus=scsi,path=/var/lib/libvirt/images/CentOS8.2.qcow2 --network
      network=default --graphics vnc,listen=0.0.0.0 --os-type=Linux --osvariant=
      centos8 --noautoconsole --boot hd

      调整虚拟磁盘大小

      *做虚拟磁盘调整之前需要注意以下几点:

      • 操作之前,一定要做好数据备份
      • 增加文件大小后,需要在客户机中使用fdisk、parted等分区工具进行相应的操作才能真正让客户机使用到增加后的镜像空间。
      • 缩小镜像之前,要在客户机中保证里面的文件系统有空余空间,否则会数据丢失。另外xfs文件系统不支持缩减
      • qcow2不支持缩小镜像的操作

      案例:扩展虚拟磁盘

      #思路:扩展分区-扩容物理卷-扩容逻辑卷组-扩容指定逻辑卷
      [root@ubuntu2204 ~]#qemu-img info /var/lib/libvirt/images/centos7-mooreyxia.qcow2
      image: /var/lib/libvirt/images/centos7-mooreyxia.qcow2
      file format: qcow2
      virtual size: 10 GiB (10737418240 bytes)
      disk size: 1.6 GiB
      cluster_size: 65536
      Snapshot list:
      ID TAG VM SIZE DATE VM CLOCK ICOUNT
      1 centos7-s1 0 B 2023-01-01 19:01:27 00:00:00.000 0
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: true
      refcount bits: 16
      corrupt: false
      extended l2: false
      [root@ubuntu2204 ~]#du -sh /var/lib/libvirt/images/centos7-mooreyxia.qcow2
      1.6G /var/lib/libvirt/images/centos7-mooreyxia.qcow2

      #扩容 - 增加10G空间
      [root@ubuntu2204 ~]#qemu-img info /var/lib/libvirt/images/centos7-mooreyxia.qcow2
      image: /var/lib/libvirt/images/centos7-mooreyxia.qcow2
      file format: qcow2
      virtual size: 20 GiB (21474836480 bytes)
      disk size: 1.6 GiB
      cluster_size: 65536
      Snapshot list:
      ID TAG VM SIZE DATE VM CLOCK ICOUNT
      1 centos7-s1 0 B 2023-01-01 19:01:27 00:00:00.000 0
      Format specific information:
      compat: 1.1
      compression type: zlib
      lazy refcounts: true
      refcount bits: 16
      corrupt: false
      extended l2: false

      #qemu-img resize 扩展空间后,在虚拟机内还需执行如下操作才能最终扩容
      [root@localhost ~]# lsblk
      NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
      sr0 11:0 1 1024M 0 rom
      vda 252:0 0 20G 0 disk
      ├─vda1 252:1 0 1G 0 part /boot
      └─vda2 252:2 0 9G 0 part
      ├─centos-root 253:0 0 8G 0 lvm /
      └─centos-swap 253:1 0 1G 0 lvm [SWAP]

      [root@localhost ~]# df -h
      Filesystem Size Used Avail Use% Mounted on
      devtmpfs 908M 0 908M 0% /dev
      tmpfs 919M 0 919M 0% /dev/shm
      tmpfs 919M 8.6M 911M 1% /run
      tmpfs 919M 0 919M 0% /sys/fs/cgroup
      /dev/mapper/centos-root 8.0G 1.3G 6.8G 16% /
      /dev/vda1 1014M 153M 862M 15% /boot
      tmpfs 184M 0 184M 0% /run/user/0

      #重新创建/dev/vda2,容量使用所有空间,/dev/vda2扩容到20G
      [root@localhost ~]# fdisk /dev/vda
      Welcome to fdisk (util-linux 2.23.2).

      Changes will remain in memory only, until you decide to write them.
      Be careful before using the write command.


      Command (m for help): m
      Command action
      a toggle a bootable flag
      b edit bsd disklabel
      c toggle the dos compatibility flag
      d delete a partition
      g create a new empty GPT partition table
      G create an IRIX (SGI) partition table
      l list known partition types
      m print this menu
      n add a new partition
      o create a new empty DOS partition table
      p print the partition table
      q quit without saving changes
      s create a new empty Sun disklabel
      t change a partition's system id
      u change display/entry units
      v verify the partition table
      w write table to disk and exit
      x extra functionality (experts only)

      Command (m for help): p

      Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000df5df

      Device Boot Start End Blocks Id System
      /dev/vda1 * 2048 2099199 1048576 83 Linux
      /dev/vda2 2099200 20971519 9436160 8e Linux LVM

      Command (m for help): d
      Partition number (1,2, default 2):
      Partition 2 is deleted

      Command (m for help): p

      Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000df5df

      Device Boot Start End Blocks Id System
      /dev/vda1 * 2048 2099199 1048576 83 Linux

      Command (m for help): p

      Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000df5df

      Device Boot Start End Blocks Id System
      /dev/vda1 * 2048 2099199 1048576 83 Linux

      Command (m for help): n
      Partition type:
      p primary (1 primary, 0 extended, 3 free)
      e extended
      Select (default p):
      Using default response p
      Partition number (2-4, default 2):
      First sector (2099200-41943039, default 2099200):
      Using default value 2099200
      Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039):
      Using default value 41943039
      Partition 2 of type Linux and of size 19 GiB is set

      Command (m for help): p

      Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000df5df

      Device Boot Start End Blocks Id System
      /dev/vda1 * 2048 2099199 1048576 83 Linux
      /dev/vda2 2099200 41943039 19921920 83 Linux

      Command (m for help): t
      Partition number (1,2, default 2):
      Hex code (type L to list all codes): 8e
      Changed type of partition 'Linux' to 'Linux LVM'

      Command (m for help): p

      Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000df5df

      Device Boot Start End Blocks Id System
      /dev/vda1 * 2048 2099199 1048576 83 Linux
      /dev/vda2 2099200 41943039 19921920 8e Linux LVM

      Command (m for help): w
      The partition table has been altered!

      Calling ioctl() to re-read partition table.

      WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
      The kernel still uses the old table. The new table will be used at
      the next reboot or after you run partprobe(8) or kpartx(8)
      Syncing disks.

      #同步文件系统,扩展逻辑卷
      [root@localhost ~]# lsblk
      NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
      sr0 11:0 1 1024M 0 rom
      vda 252:0 0 20G 0 disk
      ├─vda1 252:1 0 1G 0 part /boot
      └─vda2 252:2 0 19G 0 part
      ├─centos-root 253:0 0 8G 0 lvm /
      └─centos-swap 253:1 0 1G 0 lvm [SWAP]

      [root@localhost ~]# lsblk -f
      NAME FSTYPE LABEL UUID MOUNTPOINT
      sr0
      vda
      ├─vda1 xfs 1a55b4e7-3e79-4319-8fd0-7ceb3d1ab505 /boot
      └─vda2 LVM2_member 0Sybbx-w3aS-ZdSN-1zQO-eXpw-0zqz-YcYT4V
      ├─centos-root xfs f1205cb4-8a06-44a8-bece-89e8610e5a77 /
      └─centos-swap swap 7ccb94cc-3909-4af8-9abf-e1b63d627f52 [SWAP]

      #当前物理卷空间并没有扩容,需要执行下面操作扩容PV
      [root@localhost ~]# pvs
      PV VG Fmt Attr PSize PFree
      /dev/vda2 centos lvm2 a-- <9.00g 0

      [root@localhost ~]# pvresize --setphysicalvolumesize 19G /dev/vda2
      WARNING: /dev/vda2: Overriding real size <19.00 GiB. You could lose data.
      /dev/vda2: Requested size 19.00 GiB exceeds real size <19.00 GiB. Proceed? [y/n]: y
      WARNING: /dev/vda2: Pretending size is 39845888 not 39843840 sectors.
      Physical volume "/dev/vda2" changed
      1 physical volume(s) resized or updated / 0 physical volume(s) not resized

      [root@localhost ~]# pvs
      PV VG Fmt Attr PSize PFree
      /dev/vda2 centos lvm2 a-- <19.00g 10.00g

      #逻辑卷组被自动扩容
      [root@localhost ~]# vgs -a
      VG #PV #LV #SN Attr VSize VFree
      centos 1 2 0 wz--n- <19.00g 0

      #扩容指定逻辑卷
      [root@localhost ~]# lvextend -r -l +100%free /dev/centos/root
      Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to <18.00 GiB (4607 extents).
      Logical volume centos/root successfully resized.
      meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=524032 blks
      = sectsz=512 attr=2, projid32bit=1
      = crc=1 finobt=0 spinodes=0
      data = bsize=4096 blocks=2096128, imaxpct=25
      = sunit=0 swidth=0 blks
      naming =version 2 bsize=4096 ascii-ci=0 ftype=1
      log =internal bsize=4096 blocks=2560, versinotallow=2
      = sectsz=512 sunit=0 blks, lazy-count=1
      realtime =none extsz=4096 blocks=0, rtextents=0
      data blocks changed from 2096128 to 4717568
      [root@localhost ~]# lvs
      LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
      root centos -wi-ao---- <18.00g
      swap centos -wi-ao---- 1.00g
      [root@localhost ~]# lsblk
      NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
      sr0 11:0 1 1024M 0 rom
      vda 252:0 0 20G 0 disk
      ├─vda1 252:1 0 1G 0 part /boot
      └─vda2 252:2 0 19G 0 part
      ├─centos-root 253:0 0 18G 0 lvm /
      └─centos-swap 253:1 0 1G 0 lvm [SWAP]

      --------------------------------------------------------------------------------
      #如果是分区不是逻辑卷,则执行如下操作
      #如果是xfs文件系统
      xfs_growfs /
      #如果是ext
      resize2fs /dev/vda2
      ----------------------------------------------------------------------------------
      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/mooreyxia/5983365,作者:mooreyxia,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:Hudi使用场景

      下一篇:django 清理缓存,解决manage.py没有clear_cache命令

      相关文章

      2025-05-19 09:04:53

      【NetApp数据恢复】误操作导致NetApp存储的卷丢失,卷内虚拟机无法访问的数据恢复案例

      【NetApp数据恢复】误操作导致NetApp存储的卷丢失,卷内虚拟机无法访问的数据恢复案例

      2025-05-19 09:04:53
      存储 , 数据 , 数据恢复 , 解压
      2025-05-13 09:53:13

      mysql 存储函数及调用

      在MySQL中,存储函数(Stored Function)是一种在数据库中定义的特殊类型的函数,它可以从一个或多个参数返回一个值。存储函数在数据库层面上封装了复杂的SQL逻辑,使得在应用程序中调用时更加简单和高效。

      2025-05-13 09:53:13
      MySQL , 函数 , 存储 , 示例 , 触发器 , 语句 , 调用
      2025-05-13 09:49:27

      变量基础_变量场景

      变量基础_变量场景

      2025-05-13 09:49:27
      变量 , 场景 , 存储 , 学习 , 数据 , 编程语言
      2025-05-09 08:20:32

      MySQL——索引(概述和结构介绍)

      索引(index)是帮助 MySQL 高效获取数据的数据结构(是一种有序的数据结构)。

      2025-05-09 08:20:32
      Tree , 存储 , 引擎 , 数据结构 , 查询 , 索引 , 结构
      2025-05-08 09:03:38

      两数相加

      给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。

      2025-05-08 09:03:38
      存储 , 数字 , 相加 , 示例 , 链表
      2025-05-06 09:19:21

      【Linux 从基础到进阶】 Xen 虚拟化技术应用

      Xen 是一款开源的虚拟化技术,广泛应用于云计算和服务器虚拟化中。作为一款高性能的虚拟化平台,Xen 提供了完整的虚拟化(Full Virtualization)和准虚拟化(Paravirtualization)支持,能够在 x86 和 ARM 等架构上运行多个虚拟机。

      2025-05-06 09:19:21
      安装 , 虚拟化 , 虚拟机
      2025-05-06 09:19:21

      【Linux 从基础到进阶】 QEMU 虚拟化配置与优化

      QEMU(Quick Emulator)是一个开源的虚拟化解决方案,能够通过硬件虚拟化支持(如 Intel VT-x、AMD-V)提供高效的虚拟化性能。它不仅可以单独运行作为完整的虚拟机管理程序,还经常与 KVM(Kernel-based Virtual Machine)一起使用,以提高虚拟化效率。

      2025-05-06 09:19:21
      CentOS , KVM , Ubuntu , 虚拟化
      2025-05-06 09:19:12

      Java调用存储过程小结

      Java调用存储过程小结

      2025-05-06 09:19:12
      null , 存储 , 调用 , 返回值
      2025-05-06 09:18:49

      【Linux 从基础到进阶】iSCSI存储配置与管理

      iSCSI(Internet Small Computer System Interface)是一种基于IP网络的存储协议,允许客户端(称为发起者,Initiator)通过TCP/IP网络访问远程存储设备(称为目标,Target)。

      2025-05-06 09:18:49
      存储 , 目标
      2025-05-06 09:18:49

      【Linux 从基础到进阶】Ceph分布式存储系统搭建

      随着数据量的爆炸式增长,传统的存储解决方案逐渐暴露出扩展性差、成本高、管理复杂等问题。Ceph是一种高性能、可扩展的开源分布式存储系统,能够为对象存储、块存储和文件系统提供统一的存储平台。

      2025-05-06 09:18:49
      分布式 , 存储 , 高可用性
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5246458

      查看更多

      最新文章

      【NetApp数据恢复】误操作导致NetApp存储的卷丢失,卷内虚拟机无法访问的数据恢复案例

      2025-05-19 09:04:53

      mysql 存储函数及调用

      2025-05-13 09:53:13

      MySQL——索引(概述和结构介绍)

      2025-05-09 08:20:32

      两数相加

      2025-05-08 09:03:38

      【Linux 从基础到进阶】iSCSI存储配置与管理

      2025-05-06 09:18:49

      【Linux 从基础到进阶】 SSD与HDD存储优化

      2025-05-06 09:18:38

      查看更多

      热门文章

      Ceph 块设备存储

      2023-05-09 05:52:48

      存储相关

      2023-05-04 08:57:32

      vmware

      2023-06-14 09:05:26

      Sql Server 分页存储过程

      2023-05-30 08:05:57

      VMware虚拟机底层存储结构和还原快照恢复原理

      2024-07-01 01:31:56

      Raid5两块硬盘掉线数据恢复方法和数据恢复过程

      2024-07-01 01:31:09

      查看更多

      热门标签

      存储 缓存 内存 数据库 数据 redis mysql 服务器 数据恢复 Redis linux java 链表 MySQL sql
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      自动登录,免密码登录实现方式

      超详细的MySQL存储引擎讲解,学习MySQL这些知识你必须要会!

      oracle数据灾备故障处理

      数据仓库如何分层?数据仓库常见分层有哪些?

      mysql8.0存储函数

      Hive是什么,Hive介绍

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号