kvm 虚拟机qcow2磁盘格式扩容
目录
一、查看原磁盘镜像的大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cd /data/kvm/iso/ qemu-img info centos-2.qcow2 root@la:/data/kvm/iso# qemu-img info centos-2.qcow2 image: centos-2.qcow2 file format: qcow2 virtual size: 30G (32212254720 bytes) disk size: 1.8G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true refcount bits: 16 corrupt: false |
二、扩容100G磁盘
1 2 |
root@la:/data/kvm/iso# qemu-img resize centos-2.qcow2 +100g Image resized. |
三、查看扩容后的磁盘大小
1 2 3 4 5 6 7 8 9 10 11 |
root@la:/data/kvm/iso# qemu-img info centos-2.qcow2 image: centos-2.qcow2 file format: qcow2 virtual size: 130G (139586437120 bytes) disk size: 1.8G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true refcount bits: 16 corrupt: false |
四、启动VM,并将硬盘扩容
4.1 查看分区
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 |
[root@centos-3 ~]# fdisk -l Disk /dev/vda: 130 GiB, 139586437120 bytes, 272629760 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xda83b106 Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 2099199 2097152 1G 83 Linux /dev/vda2 2099200 62914559 60815360 29G 8e Linux LVM Disk /dev/mapper/cl-root: 26 GiB, 27913093120 bytes, 54517760 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/cl-swap: 3 GiB, 3221225472 bytes, 6291456 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes |
4.2 扩展分区
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 |
[root@centos-3 ~]# fdisk /dev/vda Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/vda: 130 GiB, 139586437120 bytes, 272629760 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xda83b106 Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 2099199 2097152 1G 83 Linux /dev/vda2 2099200 62914559 60815360 29G 8e Linux LVM Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): 3 First sector (62914560-272629759, default 62914560): Last sector, +sectors or +size{K,M,G,T,P} (62914560-272629759, default 272629759): Created a new partition 3 of type 'Linux' and of size 100 GiB. Command (m for help): w The partition table has been altered. Syncing disks. |
4.3 创建物理卷并加入卷组,扩展逻辑卷
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 |
#新扩展分区为/dev/vda3,将其直接扩展到/目录 [root@centos-3 ~]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 cl lvm2 a-- <29.00g 0 [root@centos-3 ~]# pvcreate /dev/vda3 Physical volume "/dev/vda3" successfully created. [root@centos-3 ~]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 cl lvm2 a-- <29.00g 0 /dev/vda3 lvm2 --- 100.00g 100.00g [root@centos-3 ~]# vgextend cl /dev/vda3 Volume group "cl" successfully extended [root@centos-3 ~]# lvextend -l +100%FREE /dev/mapper/cl-root Size of logical volume cl/root changed from <26.00 GiB (6655 extents) to 125.99 GiB (32254 extents). Logical volume cl/root successfully resized. [root@centos-3 ~]# resize2fs /dev/mapper/cl-root resize2fs 1.44.6 (5-Mar-2019) resize2fs: Bad magic number in super-block while trying to open /dev/mapper/cl-root Couldn't find valid filesystem superblock. [root@centos-3 ~]# xfs_growfs /dev/mmapper/cl-root xfs_growfs: path resolution failed for /dev/mmapper/cl-root: No such file or directory [root@centos-3 ~]# xfs_growfs / meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=1703680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=6814720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=3327, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 6814720 to 33028096 |
4.4 成功扩容
1 2 3 4 5 6 7 8 9 |
[root@centos-3 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/cl-root 126G 2.4G 124G 2% / /dev/vda1 976M 139M 771M 16% /boot tmpfs 379M 0 379M 0% /run/user/0 |
by cpp.la
One Reply to “kvm 虚拟机qcow2磁盘格式扩容”