新增硬盘(关闭虚拟机)
- 宿主机添加一块硬盘
[root@mrxy-py kvmdisk]# qemu-img create -f raw /data1/kvmdisk/WMS-test-2-2.img 50G
Formatting '/data1/kvmdisk/WMS-test-2-2.img', fmt=raw size=53687091200
- 添加新磁盘信息加入配置文件
#关闭电源
[root@mrxy-py kvmdisk]# virsh destroy WMS-test-2
Domain WMS-test-2 destroyed
#配置文件添加信息
[root@mrxy-py kvmdisk]# virsh edit WMS-test-2
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/data1/kvmdisk/WMS-test-2-2.img'/>
<target dev='vdb' bus='ide'/>
</disk>
3.启动虚拟机并配置硬盘
[root@mrxy-py kvmdisk]# virsh start WMS-test-2
Domain WMS-test-2 started
fdisk /dev/sdb
mkfs.ext4 /dev/sdb
mount /dev/vdb /data
vi /etc/fstab
得到到/dev/sdb这个分区的UUID使用命令:blkid /dev/sdb
Cat << EOF >> /etc/fstab
UUID="f7dbec85-ec1e-4291-bf91-73587dc81855"/data ext4 defaults 0 0
EOF
扩容硬盘
#查看硬盘信息
[root@mrxy-py kvmdisk]# qemu-img info /data1/kvmdisk/WMS-test-3.img
image: /data1/kvmdisk/WMS-test-3.img
file format: raw
virtual size: 50G (53695545344 bytes)
disk size: 50G
#增加硬盘信息
[root@mrxy-py kvmdisk]# qemu-img resize /data1/kvmdisk/WMS-test-3.img +50G
Image resized.
#查看增加后硬盘信息
[root@mrxy-py kvmdisk]# qemu-img info /data1/kvmdisk/WMS-test-3.img
image: /data1/kvmdisk/WMS-test-3.img
file format: raw
virtual size: 100G (107382636544 bytes)
disk size: 50G