linux为已有磁盘扩容 kvm,KVM ---- 虚拟磁盘扩容

标签:kvm

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

1、子机的当前磁盘状态

5e35b9aae5b024957162ea80469c4dec.png

母机中查看该系统

f1d748d435cd147a4e364b7fb4a39ea3.png

[[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

34e7c10c748054356e1b0fdda12bf2c6.png

操作步骤:

[[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 如果没有这个分区,需要重启一下。pvcreate /dev/vda4

Physical volume "/dev/vda4" successfully created

446893b979cbf7a3311753053f99e191.png

现在吧vda4加入到VolGroup里面

[[email protected] ~]# vgextend VolGroup /dev/vda4

Volume group "VolGroup" successfully extended

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

2032a246d19410d6bdf1e93940540bb7.png

[[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_rootSize of logical volume VolGroup/lv_root changed from 28.51 GiB (7298 extents) to 33.50 GiB (8577 extents).Logical volume lv_root successfully resizedLV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv_root VolGroup -wi-ao----33.50g

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

e74261d8d74596ecc12e1a2e03eda422.png8d046fdd5cfcbe38be2dd4b84f27ead1.png

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

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

6d3f527cfdc4635e6af3c2fcd65e0406.png

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

virsh edit caimz2  增加如下:

fa9656b595ef556482551524ff03f33c.png

保存退出。

[[email protected] ~]# virsh edit caimz2

Domain caimz2 XML configuration edited.

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

0cb7d0da7e0301b04ba852701fc11306.png格式化:mkfs.ext4 /dev/vdb

5c22d85b46b6e2c88eb2397ec25a6871.png

挂载使用。

[[email protected] ~]# qemu-img resize /caimz/caimz1.qcow2  +5G

This image format does not support resize

标签:kvm

原文:http://caimengzhi.blog.51cto.com/9787265/1703893

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值