kvm初体验之八:调整vm的vcpu, memory, disk大小

假设host上创建的vm的名字为vm1。

1. 查看vm1domain information

[root@tang* thm]# virsh dominfo vm1

Id: 10

Name: vm1

UUID: e2597379-5cc5-4ffa-0531-a073a81c5811

OS Type: hvm

State: running

CPU(s): 1

CPU time: 52.6s

Max memory: 1048576 KiB

Used memory: 1048576 KiB

Persistent: yes

Autostart: disable

Managed save: no

Security model: selinux

Security DOI: 0

Security label: system_u:system_r:svirt_t:s0:c790,c799 (enforcing)

2. 修改vm1vcpu,
memory

1)实时修改vcpu,memory

virsh setvcpus vm1 xxx #数值不能超过vm1.xml中配置的vcpu值

virsh setmaxmem vm1 xxx #vm1处于shut
off状态时才能设置成功

virsh setmem vm1 xxx #数值不能超过maxmem

2)配置文件修改vcpu,
memory

修改vm1的配置文件

virsh edit vm1

<memory>对应dominfo中的Max
memory

<currentMemory>对应dominfo中的Used
memory

<vcpu>对应dominfo中的CPU(s)

<memory unit='KiB'></memory>

<currentMemory unit='KiB'></currentMemory>

<vcpu placement='static'></vcpu>

将vm1先关机再启动即可生效

virsh destroy vm1

virsh start vm1

3. vm1扩展一个10Gdisk

生成一个大小为10G的磁盘文件/vm/vm1-add

dd if=/dev/zero of=/vm/vm1-add bs=1M count=10240

修改vm1的配置文件

virsh edit vm1

vm1现有的磁盘文件为/vm/vm1

<disk type='file' device='disk'>

<driver name='qemu' type='raw' cache='none'/>

<source file='/vm/vm1'/>

<target dev='hda' bus='ide'/>

<address type='drive' controller='0' bus='0'
target='0' unit='0'/>

</disk>

在后面追加如下几行

<disk type='file' device='disk'>

<driver name='qemu' type='raw' cache='none'/>

<source file='/vm/vm1-add'/>

<target dev='hdb'
bus='ide'/>

<address type='drive' controller='0' bus='0'
target='0' unit='1'/>

</disk>

将vm1先关机再启动即可生效

virsh destroy vm1

virsh start vm1

查看vm1的磁盘信息

root@localhost ~]# fdisk -l| grep Disk

Disk /dev/sda: 2147 MB, 2147483648 bytes

Disk identifier: 0x000e3e47

Disk /dev/sdb: 10.7 GB, 10737418240
bytes

Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_root: 1405 MB, 1405091840 bytes

Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 213 MB, 213909504 bytes

Disk identifier: 0x00000000

上一篇:第三届蓝桥杯 c/c++真题


下一篇:[转]Eclipse 的快捷键以及文档注释、多行注释的快捷键