KVM ---- 虚拟磁盘扩容

磁盘不够使用,添加新的硬盘,或者扩容当前磁盘。

1、子机的当前磁盘状态

母机中查看该系统

[[email protected] ~]# qemu-img resize /caimz/caimz2.img  +5G
Image resized.
[[email protected] ~]# qemu-img info /caimz/caimz2.img
image: /caimz/caimz2.img
file format: raw
virtual size: 35G (37580963840 bytes)
disk size: 30G

[[email protected] ~]# virsh start caimz2 --console
error: Domain is already active

[[email protected] ~]#
[[email protected] ~]# virsh start caimz2 --console
error: Domain is already active

操作步骤:

[[email protected] ~]# fdisk -l

Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004583c

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       28G  720M   26G   3% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/vda1             477M   31M  421M   7% /boot
[[email protected] ~]# fdisk -l

Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004583c

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[[email protected] ~]# fdisk /dev/vda

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
         switch off the mode (command ‘c‘) and change display units to
         sectors (command ‘u‘).

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-72817, default 1): 62417
Last cylinder, +cylinders or +size{K,M,G} (62416-72817, default 72817): 72817

Command (m for help): p

Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004583c

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 4
First cylinder (1-72817, default 1): 62417  #inode 在/dev/vda2 都是62416 所以应从62417开始
Last cylinder, +cylinders or +size{K,M,G} (62417-72817, default 72817): 72817#结束

Command (m for help): p

Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004583c

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda4           62417       72817     5242104   83  Linux  #新增加的那5G

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.
[[email protected] ~]# fdisk -l

Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004583c

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda4           62417       72817     5242104   83  Linux

Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

创建物理卷

然后再把这个/dev/vda4 加入到lvm里面去:

ls  /dev/vda4 如果没有这个分区,需要重启一下。

[[email protected] ~]# pvcreate /dev/vda4

Physical volume "/dev/vda4" successfully created

现在吧vda4加入到VolGroup里面

[[email protected] ~]# vgextend VolGroup /dev/vda4
  Volume group "VolGroup" successfully extended

查看vda4是不是属于VolGroup组里面。

[[email protected] ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree
  VolGroup   2   2   0 wz--n- 34.50g 5.00g

看逻辑卷

[[email protected] ~]# lvs
  LV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao---- 28.51g                                                   
  lv_swap VolGroup -wi-ao----  1.00g

现在要把之前添加的5G 加到lv_root里面

[[email protected] ~]# lvextend -l +100%FREE /dev/VolGroup/lv_root
  Size of logical volume VolGroup/lv_root changed from 28.51 GiB (7298 extents) to 33.50 GiB (8577 extents).
  Logical volume lv_root successfully resized
[[email protected] ~]# lvs
  LV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao---- 33.50g

lv_swap VolGroup -wi-ao----  1.00g

增加一个新的硬盘来扩容:

1、创建新的磁盘

[[email protected] ~]# qemu-img create -f raw /caimz/caimz2_extend.img 5G
     Formatting ‘/caimz/caimz2_extend.img‘, fmt=raw size=5368709120

2、编辑配置文件

[[email protected] ~]# virsh edit caimz2

添加刚才新建的.img磁盘。

virsh edit caimz2  增加如下:

<disk type=‘file‘ device=‘disk‘>

<driver name=‘qemu‘ type=‘raw‘ cache=‘none‘/>
      <source file=‘/caimz/caimz2_extend.img‘/>
      <target dev=‘vdb‘ bus=‘virtio‘/>
      <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x07‘ function=‘0x0‘/>
    </disk>

保存退出。

[[email protected] ~]# virsh edit caimz2

Domain caimz2 XML configuration edited.

开启虚拟机:virsh start ciamz2
     进入虚拟机:virsh console caizm2

  格式化:mkfs.ext4 /dev/vdb

挂载使用。

[[email protected] ~]# qemu-img resize /caimz/caimz1.qcow2  +5G
This image format does not support resize

时间: 2024-10-12 23:43:05

KVM ---- 虚拟磁盘扩容的相关文章

KVM磁盘扩容

对于qcow2格式的虚拟磁盘扩容. 查看磁盘格式 [[email protected] ~]# qemu-img info /kvm/kvm2/xy2.img.qcow2 image: /kvm/kvm2/xy2.img.qcow2 file format: qcow2 virtual size: 10G (10737418240 bytes) disk size: 1.8G cluster_size: 65536 2.增加容量 [[email protected] ~]# qemu-img r

kvm虚拟机扩容系统盘

一,宿主机扩容虚拟机系统盘 环境 文件系统 CentOS 7 XFS 1.1查看虚拟机(以下操作在宿主机上) [[email protected] ~]# virsh list 4 office-com-ldap-01 running 1.2查看虚拟机系统盘 [[email protected] ~]# virsh domblklist office-com-ldap-01 目标 源 ------------------------------------------------ vda /ho

KVM镜像扩容

进入 data.img所在目录: 给虚拟机镜像文件(.img)追加 4GB 空间: 1.dd if=/dev/zero bs=1024M count=4 >> data.img 扫描检查镜像文件: 2.e2fsck -f data.img 这个时候只是增加了镜像文件(硬盘)的大小,这个镜像文件不是普通的文件,里面包含可 mount/umount 的 loop 文件系统,所以需要重新调整文件系统大小,不然的话进入虚拟机后 df 会发现硬盘大小没变: 3.resize2fs data.img

VirtualBox虚拟磁盘扩容

1. cmd中运行 VBoxManage modifyhd D:\我的资料库\Documents\VirtualBox VMs\ubuntu\ubuntu.vdi --resize 61440 提示错误  Syntax error: Invalid parameter 'VMs\ubuntu\ubuntu.vdi' 原来是路径中不能包含空格,于是更改文件夹VirtualBox VMs为VirtualBoxVMs 再次运行上列命令,出现 0%...10%...20%...30%...40%...5

浅谈虚拟环境下虚拟磁盘的扩容

搭建一个虚拟化平台实现资源复用乃至建设私有云,是一个组织 IT 部门今天几乎必须要做的事情之一.老话说的好,罗马不是一天建成的,今天创建的虚机,分配的虚拟磁盘空间,也许明天就会捉襟见肘.是每次增加一个虚拟磁盘,还是想办法增加虚拟磁盘的大小,这是个考虑的问题. 个人角度,强烈不建议增加虚拟磁盘的数量.原因后文说明.那就选择扩展虚拟磁盘容量吧,如何去做虚拟磁盘的扩容,其实在今天的虚拟化产品都能得到很好的支持.例如: Hyper-V 早期Hyper-V 2.0 (Windows Server 2008

KVM之XFS磁盘扩容

1.前言 根据目前我们使用的需求,以前规划的100G磁盘空间不够,这里将演示XFS文件系统的扩容,因为我使用的是KVM所以也会演示KVM的扩容方式. 2.KVM磁盘扩容 扩容前一定要先备份,或者做快照,不要造成数据的损坏. [[email protected] img]# qemu-img info c7_data_g2.raw #<--查看原磁盘信息 image: c7_data_g2.raw file format: raw virtual size: 100G (107374182400

kvm常用操作

libguestfs-tools 比较好的kvm管理工具虚拟机的管理工具   convirts虚拟化:xen(半虚拟化)宿主和客服机都需要该系统内核,系统内核替换接管系统管理 不需要cpu支持虚拟化        kvm(仅全虚拟化)提供完整的硬件资源且不知道宿主存在 grep --color=auto 'vmx|svm' /proc/cupinfo如果输出的信息中有vmx,说明intel处理器支持完全虚拟化.如果显示svm,说明是AMD的处理器支持虚拟化. 通过yum安装虚拟化的软件包::yu

Linux 虚拟化实践之KVM

一.虚拟化介绍 虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率. 虚拟化使用软件的方法重新定义划分IT资源,可以实现IT资源的动态分配.灵活调度.跨域共享,提高IT资源利用率,使IT资源能够真正成为社会基础设施,服务于各行各业中灵活多变的应用需求. 1).虚拟化模型 处于底层是整个物理系统,也就是我们可以看的见,摸得着的系统硬件,

centos 7.2 kvm虚拟化配置以及常用操作

1. 开始安装kvma. 检查你的系统是否支持虚拟化grep -Ei 'vmx|svm' /proc/cpuinfo如果有输出内容,则支持,其中intelcpu支持会有vmx,amd cpu支持会有svm b. 通过yum安装虚拟化的软件包yum install -y kvmvirt-*  libvirt  bridge-utils qemu-img说明:kvm:软件包中含有KVM内核模块,它在默认linux内核中提供kvm管理程序libvirts:安装虚拟机管理工具,使用virsh等命令来管理