标签:kvm
对于qcow2格式的虚拟磁盘扩容。
查看磁盘格式
[root@111 ~]# 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.增加容量
[root@111 ~]# qemu-img resize /kvm/kvm2/xy2.img.qcow2 +2G Image resized.
3.查看是否增加容量
[root@111 ~]# qemu-img info /kvm/kvm2/xy2.img.qcow2 image: /kvm/kvm2/xy2.img.qcow2 file format: qcow2 virtual size: 12G (12884901888 bytes) disk size: 1.8G cluster_size: 65536
4.查看虚拟机
[root@111 ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- - xiayun1 关闭 - xy1 关闭 - xy2 关闭
5.连接到虚拟机
[root@111 ~]# virsh start xy2 --console 域 xy2 已开始 连接到域 xy2 Escape character is ^]
6.查看磁盘分区是否增加
[root@localhost ~]# fdisk -l Disk /dev/vda: 12.9 GB, 12884901888 bytes 16 heads, 63 sectors/track, 24966 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: 0x0002fcf1 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 20806 9972736 8e Linux LVM Partition 2 does not end on cylinder boundary. Disk /dev/mapper/VolGroup-lv_root: 9168 MB, 9168748544 bytes 255 heads, 63 sectors/track, 1114 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: 1040 MB, 1040187392 bytes 255 heads, 63 sectors/track, 126 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
7.磁盘分区[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): p Disk /dev/vda: 12.9 GB, 12884901888 bytes 16 heads, 63 sectors/track, 24966 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: 0x0002fcf1 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 20806 9972736 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): 3 First cylinder (1-24966, default 1): 20807 Last cylinder, +cylinders or +size{K,M,G} (20807-24966, default 24966): Using default value 24966 Command (m for help): p Disk /dev/vda: 12.9 GB, 12884901888 bytes 16 heads, 63 sectors/track, 24966 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: 0x0002fcf1 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 20806 9972736 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 20807 24966 2096640 83 Linux 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.
8.查看是否有vda3
ls /dev/vda3
若没有 ,virsh destroy xy2;virsh start xy2 --console 关闭虚拟机重启
9.创建物理卷
[root@localhost ~]# pvcreate /dev/vda3 Physical volume "/dev/vda3" successfully created
10.得到物理卷的概要信息
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 VolGroup lvm2 a-- 9.51g 0 /dev/vda3 lvm2 a-- 2.00g 2.00g
11.加入物理卷
[root@localhost ~]# vgextend VolGroup /dev/vda3 Volume group "VolGroup" successfully extended
12.查看物理卷组
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree VolGroup 2 2 0 wz--n- 11.50g 2.00g
13.查看逻辑卷组
[root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_root VolGroup -wi-ao---- 8.54g lv_swap VolGroup -wi-ao---- 992.00m
14.全部分配空间
[root@localhost ~]# lvextend -l +100%FREE /dev/VolGroup/lv_root Extending logical volume lv_root to 10.54 GiB Logical volume lv_root successfully resized
15.df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.5G 736M 7.3G 10% / tmpfs 246M 0 246M 0% /dev/shm /dev/vda1 485M 33M 427M 8% /boot
16.resize2fs /dev/VolGroup/lv_root
17.df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 11G 738M 9.2G 8% / tmpfs 246M 0 246M 0% /dev/shm /dev/vda1 485M 33M 427M 8% /boot
成功扩容!
本文出自 “echo xiayun” 博客,请务必保留此出处http://linuxerxy.blog.51cto.com/10707334/1729647
标签:kvm
原文地址:http://linuxerxy.blog.51cto.com/10707334/1729647