CentOS7.2 KVM虛擬化之虛擬機根分區(qū)擴容
一、擴展虛擬磁盤
1. 關閉虛擬機
virsh shutdown web01
2.查看虛擬機磁盤當前大小
[root@kvm01 /data]# qemu-img info centos2-clone.qcow2
image: centos2-clone.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
3.擴展磁盤大小
[root@kvm01 /data]# qemu-img resize centos2-clone.qcow2 +10G
4.再次查看虛擬機大小
[root@kvm01 /data]# qemu-img info centos2-clone.qcow2
image: centos2-clone.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
二契讲、擴展虛擬機根分區(qū)
1.查看當前分區(qū)狀況畸裳,可以看到/dev/vda 大小變化
[root@localhost ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000513fd
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20971519 10484736 83 Linux #注意這里起始cylinder 是2048缰犁,起始cylinder 絕對不可以改,否則會破壞原分區(qū)的數(shù)據(jù)怖糊。
2.擴展根分區(qū)
[root@localhost ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
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: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000513fd
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20971519 10484736 83 Linux
Command (m for help): d
Selected partition 1 #根/分區(qū)是多少就輸入幾帅容,這里是/dev/vda3
Partition 1 is deleted
Command (m for help): p
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000513fd
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1 #之前是多少,這里還輸入多少
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
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.
三蓬抄、重啟虛擬機丰嘉,完成根分區(qū)擴容
執(zhí)行如下命令,重啟系統(tǒng)
[root@localhost ~]#reboot
重啟后執(zhí)行如下命令嚷缭,完成根分區(qū)擴充
[root@localhost ~]# xfs_growfs /dev/vda1
meta-data=/dev/vda1 isize=256 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621184 to 5242624
四饮亏、驗證
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 912M 20G 5% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 491M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0