一、扩展虚拟机磁盘
1.关闭虚拟机
virsh shutdown web01
2.查看虚拟机磁盘当前大小
[root@KVM01 ~]# qemu-img info /vm-images/vm1-clone.img
image: /vm-images/vm1-clone.img
file format: qcow2
virtual size: 10G (11206127360 bytes)
disk size: 1.7G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
3.扩展磁盘大小
qemu-img resize /vm-images/vm1-clone.img +5G
4.再次查看虚拟机磁盘当前大小
[root@kvm01 ~]# qemu-img info /vm-images/vm1-clone.img
image: /vm-images/vm1-clone.img
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 1.7G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
二、扩展虚拟机根分区
1.查看当前分区状况,可以看到磁盘/dev/vda大小变化
[root@localhost ~]# fdisk -l
Disk /dev/vda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/vda1 * 1 25 200781 83 Linux
/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris
/dev/vda3 157 1305 9229342+ 83 Linux #注意这里起始cylinder 是157,起始cylinder 绝对不可以改,否则会破坏原分区的数据。
2.扩展根分区
[root@localhost ~]# fdisk /dev/vda
The number of cylinders for this disk is set to 1958.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/vda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/vda1 * 1 25 200781 83 Linux
/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris
/dev/vda3 157 1305 9229342+ 83 Linux
Command (m for help): d #删除原本分区
Partition number (1-4): 3 #之前根/分区是多少就输入几,这里是/dev/vda3
Command (m for help): p
Disk /dev/vda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/vda1 * 1 25 200781 83 Linux
/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
Select (default p): p
Partition number (1-4): 3 #之前是多少,这里还输入多少
First cylinder (157-1958, default 157):#直接回车
Using default value 157
Last cylinder or +size or +sizeM or +sizeK (157-1958, default 1958): #直接回车,由之前1305,扩为1958
Using default value 1958
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
三、重启虚拟机,完成根分区扩容
执行如下命令,重启系统
[root@localhost ~]#reboot
重启后执行如下命令,刷新磁盘
[root@localhost ~]# xfs_growfs /dev/vda1 meta-data=/dev/vda1 isize=512 agcount=7, agsize=655296 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=3931904, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
四、验证
查看当前磁盘状态
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/vda3 14G 1.3G 12G 11% / /dev/vda1 190M 12M 169M 7% /boot tmpfs 379M 0 379M 0% /dev/shm
如上,完成根分区扩容
赞赏
微信赞赏
支付宝赞赏