leeham 2020-01-31
[01 ~]# virsh shutdown vm01-centos7 域 vm01-centos7 被关闭 [-01 ~]# virsh edit vm01-centos7 <domain type=‘kvm‘> <name>vm01-centos7</name> <uuid>c2784b15-5feb-4b5a-b768-a0b55bbb7c54</uuid> <memory unit=‘KiB‘>524288</memory> <currentMemory unit=‘KiB‘>524288</currentMemory> #修改当前内存 <vcpu placement=‘static‘>1</vcpu> #修改当前CPU数 <os>
[01 ~]# virsh create /etc/libvirt/qemu/vm01-centos7.xml 域 vm01-centos7 被创建(从 /etc/libvirt/qemu/vm01-centos7.xml) #从配置文件加载启动虚机。 [-01 ~]# virsh dominfo vm01-centos7 Id: 10 名称: vm01-centos7 UUID: c2784b15-5feb-4b5a-b768-a0b55bbb7c54 OS 类型: hvm 状态: running CPU: 1 CPU 时间: 23.0s 最大内存: 524288 KiB 使用的内存: 524288 KiB 持久: 是 自动启动: 禁用 管理的保存: 否 安全性模式: none 安全性 DOI: 0
virsh setmaxmem vm01-centos6.8 4G #需要关闭此虚机 虚机内存调整 virsh setmem UAKVM2 2G --config #关机状态下调整 virsh setmem UAKVM2 2G #开机状态下调整
[01 ~]# virsh edit vm01-centos7 <disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘/> <source file=‘/data/images/vm01-centos7.img‘/> #磁盘路径 <target dev=‘vda‘ bus=‘virtio‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x06‘ function=‘0x0‘/> </disk>
[01 ~]# qemu-img info /data/images/vm01-centos7.img image: /data/images/vm01-centos7.img file format: qcow2 virtual size: 10G (10737418240 bytes) disk size: 1.2G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1580475507 0 2020-01-31 20:58:27 00:00:00.000 Format specific information: compat: 1.1 lazy refcounts: true
[01 ~]# virsh edit vm01-centos7 [ ~]# qemu-img info /data/images/vm01-centos7.img
提醒:必须保证宿主机有足够的空间。
1 [ ~]# virsh console 2
[ ~]# vgcreate -s 16m vg01 /dev/vdb1 [ ~]# lvcreate -L 1g -n lv01 vg01 [ ~]# mkfs.ext4 /dev/vg01/lv01 [ ~]# mkdir /data [ ~]# mount /dev/vg01/lv01 /data/
[ ~]# virsh edit vm01-centos6.8 <disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘/> <source file=‘/data/images/vm01-centos6.8.img‘/> #磁盘路径 <target dev=‘vda‘ bus=‘virtio‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x0‘/> </disk> [ ~]# qemu-img info /data/images/vm01-centos6.8.img
1 [ ~]# qemu-img resize /data/images/vm01-centos6.8.img +1G
1 [ ~]# qemu-img info /data/images/vm01-centos6.8.img
1 [ ~]# virsh start vm01-centos6.8 2 [ ~]# fdisk -l
1 [ ~]# fdisk /dev/vda 2 …… 3 Command (m for help): p
Command (m for help): d Partition number (1-4): 3 Command (m for help): n p Partition number (1-4): 3
1 Command (m for help): w
1 [ ~]# resize2fs /dev/vda3 2 [ ~]# shutdown -r now
1 [ ~]# dd if=/dev/zero bs=1024M count=2 > /data/images/vm01-centos6.8-02.img 2 [ ~]# qemu-img info /data/images/vm01-centos6.8-02.img
1 [ ~]# qemu-img create -f qcow2 /data/images/vm01-centos6.8-02.img 1G 2 [ ~]# virsh attach-disk vm01-centos6.8 /data/images/vm01-centos6.8-02.img vdb --cache=none --subdriver=qcow2 3 [ ~]# virsh domblklist vm01-centos6.8