您的位置:首页 > 其它

KVM - 虚拟磁盘扩容

2015-10-17 22:38 471 查看
磁盘不够使用,添加新的硬盘,或者扩容当前磁盘。
1、子机的当前磁盘状态



母机中查看该系统



[root@bogon ~]# qemu-img resize /caimz/caimz2.img +5G
Image resized.
[root@bogon ~]# qemu-img info /caimz/caimz2.img
image: /caimz/caimz2.img
file format: raw
virtual size: 35G (37580963840 bytes)
disk size: 30G
[root@bogon ~]# virsh start caimz2 --console
error: Domain is already active

[root@bogon ~]#
[root@bogon ~]# virsh start caimz2 --console
error: Domain is already active




操作步骤:
[root@localhost ~]# 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

[root@localhost ~]# 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
[root@localhost ~]# 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

[root@localhost ~]# 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.
[root@localhost ~]# 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 如果没有这个分区,需要重启一下。

[root@localhost ~]# pvcreate /dev/vda4
Physical volume "/dev/vda4" successfully created



现在吧vda4加入到VolGroup里面
[root@localhost ~]# vgextend VolGroup /dev/vda4
Volume group "VolGroup" successfully extended
查看vda4是不是属于VolGroup组里面。



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

看逻辑卷
[root@localhost ~]# 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里面
[root@localhost ~]# 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
[root@localhost ~]# 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、创建新的磁盘
[root@bogon ~]# qemu-img create -f raw /caimz/caimz2_extend.img 5G
Formatting '/caimz/caimz2_extend.img', fmt=raw size=5368709120
2、编辑配置文件
[root@bogon ~]# 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>



保存退出。
[root@bogon ~]# virsh edit caimz2
Domain caimz2 XML configuration edited.
开启虚拟机:virsh start ciamz2
进入虚拟机:virsh console caizm2


格式化:mkfs.ext4 /dev/vdb



挂载使用。
[root@bogon ~]# qemu-img resize /caimz/caimz1.qcow2 +5G
This image format does not support resize
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: