KVM磁盘扩容

简介:

对于qcow2格式的虚拟磁盘扩容。


  1. 查看磁盘格式

1
2
3
4
5
6
[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.增加容量

1
2
[root@111 ~] # qemu-img resize /kvm/kvm2/xy2.img.qcow2 +2G
Image resized.

3.查看是否增加容量

1
2
3
4
5
6
[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.查看虚拟机

1
2
3
4
5
6
[root@111 ~] # virsh list --all
  Id    名称                         状态
----------------------------------------------------
  -     xiayun1                        关闭
  -     xy1                            关闭
  -     xy2                            关闭

5.连接到虚拟机

1
2
3
4
[root@111 ~] # virsh start xy2 --console
域 xy2 已开始
连接到域 xy2
Escape character is ^]

6.查看磁盘分区是否增加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.创建物理卷

1
2
[root@localhost ~] # pvcreate /dev/vda3
   Physical volume  "/dev/vda3"  successfully created

10.得到物理卷的概要信息

1
2
3
4
[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.加入物理卷

1
2
[root@localhost ~] # vgextend VolGroup /dev/vda3
   Volume group  "VolGroup"  successfully extended

12.查看物理卷组

1
2
3
[root@localhost ~] # vgs
   VG        #PV #LV #SN Attr   VSize  VFree
   VolGroup   2   2   0 wz--n- 11.50g 2.00g

13.查看逻辑卷组

1
2
3
4
[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.全部分配空间

1
2
3
[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 

1
2
3
4
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 

1
2
3
4
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

成功扩容!





      本文转自YU文武貝 51CTO博客,原文链接:http://blog.51cto.com/linuxerxy/1729647,如需转载请自行联系原作者






相关文章
YI
|
9月前
|
Ubuntu Linux 虚拟化
VMware虚拟机磁盘扩容
在VMware虚拟机中使用ubuntu学习时,发现磁盘容量不太够,遂决定给磁盘扩容。本文记录扩容过程。
YI
175 0
|
11月前
|
存储 5G KVM
KVM存储池扩容
KVM存储池扩容
112 0
|
Linux
Centos7 系列:磁盘挂载和磁盘扩容(新加硬盘方式)
在Centos 7 系统中,新添加硬盘,并将其挂载到自定义的新目录下;新添加硬盘,并为已有硬盘扩容。
2369 0
Centos7 系列:磁盘挂载和磁盘扩容(新加硬盘方式)
linux 根分区磁盘 LVM 拉升(磁盘扩容)
linux 根分区磁盘 LVM 拉升(磁盘扩容)
Linux LVM 磁盘扩容
Linux LVM 磁盘扩容
Linux LVM 磁盘扩容
VirtualBox硬盘扩容
VirtualBox硬盘扩容
123 0
|
数据可视化 Linux
LVM扩容
LVM扩容
4005 0
LVM扩容
|
Linux
Linux - 挂载磁盘 + 通过LVM动态实现磁盘的动态扩容
Linux - 挂载磁盘 + 通过LVM动态实现磁盘的动态扩容1 LVM是什么1.1 概念解释LVM(Logical Volume Manager), 逻辑卷管理, 是一种将一至多个硬盘的分区在逻辑上进行组合, 当成一个大硬盘来使用.
2997 0

热门文章

最新文章