直接扩展qcow2磁盘
1、查看磁盘信息
[[email protected] ~]# qemu-img info CentOS-7-x86_64.qcow2
2 、直接扩展磁盘
[[email protected] ~]# qemu-img resize CentOS-7-x86_64.qcow2 +4G
尖叫提示:有快照的磁盘不能扩展,需要先备份并删除快照
3、直接指定修改后的磁盘空间容量
[[email protected] ~]# qemu-img resize CentOS-7-x86_64.qcow2 40G
尖叫提示:有快照的磁盘不能扩展,需要先备份并删除快照
4、查看磁盘信息,发现磁盘已经变大
[[email protected] ~]# qemu-img info CentOS-7-x86_64.qcow2
5、启动虚拟机
[[email protected] ~]# virsh start CentOS-7-x86_64
6、查看虚拟机运行状态
[[email protected] ~]# virsh list --all
7、进入kvm虚拟机,查看磁盘
[[email protected] ~]# fdisk –l
[[email protected] ~]# df –h
[[email protected] ~]# df -T
8、磁盘分区
[[email protected] ~]# fdisk /dev/sda
依次输入
p ##查看磁盘
n ##新建分区
##默认
##默认
##默认
##默认
t ##选择格式
l ##查看有什么格式
8e ##选择lvm类型
p ##查看磁盘
w ##保存
尖叫提示:名称要对应
image.png
9、使用工具partprobe让kernel读取分区信息
[[email protected] ~]# partprobe
尖叫提示:使用fdisk工具只是将分区信息写到磁盘,如果需要mkfs磁盘分区则需要重启系统,而使用partprobe则可以使kernel重新读取分区信息,从而避免重启系统
10、查看kvm虚拟机磁盘
[[email protected] ~]# fdisk –l
[[email protected] ~]# df –h
[[email protected] ~]# df -T
11、创建物理卷
[[email protected] ~]# pvcreate /dev/vda2
12、查看物理卷
[[email protected] ~]# pvdisplay
[[email protected] ~]# pvs
13、创建vg卷组,并把物理卷添加到卷组中
[[email protected] ~]# vgcreate vg /dev/vda2
尖叫提示:如果已经有卷组可以使用“vgextend vg /dev/vda2”命令把物理卷添加到卷组中
14、查看vg卷组
[[email protected] ~]# vgdisplay
15、创建名称root逻辑大小4G的逻辑卷分区
[[email protected] ~]# lvcreate -L 4G -n root vg
16、查看逻辑卷信息
[[email protected] ~]# lvdisplay
17、格式化新逻辑卷
[[email protected] ~]# mkfs.xfs /dev/vg/root
尖叫提示:新逻辑卷经过格式化就可以挂载到系统里存储数据了, centos7.0默认文件系统是xfs,centos6是ext4,centos5是ext3
18、创建需要挂载的目录
[[email protected] ~]# mkdir /bigdata
19、挂载到需要的目录
[[email protected] ~]# mount -t xfs /dev/vg/root /bigdata
20、卸载挂载的逻辑卷
[[email protected] ~]# umount /bigdata
尖叫提示:根据情况执行
21、开机自动挂载
[[email protected] ~]# echo "/dev/vg/root /bigdata xfs defaults 1 2" >> /etc/fstab
22、卸载挂载的逻辑卷
[[email protected] ~]# umount /bigdata
23、逻辑卷扩容
[[email protected] ~]# lvextend -l +100%FREE /dev/vg/root
24、使用 xfs_growfs 命令在线调整xfs格式文件系统大小
[[email protected] ~]# xfs_growfs /dev/vg/root