First-time kvm experience: Adjust the vm's vcpu, memory, disk size, and kvmvcpu

Source: Internet
Author: User

First-time kvm experience: Adjust the vm's vcpu, memory, disk size, and kvmvcpu

Assume that the vm created on the host is named vm1.

1.ViewVm1OfDomain information

[Root @ tanghuimin 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.6 s

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: s0000_t: s0: c790, c799 (enforcing)


2.ModifyVm1OfVcpu, memory

1) Modify vcpu and memory in real time

Virsh setvcpus vm1 xxx # The value cannot exceed the vcpu value configured in vm1.xml

Virsh setmaxmem vm1 xxx # vm1 can be set successfully only when it is in the shutoff state.

Virsh setmem vm1 xxx # The value cannot exceed maxmem


2) modify the vcpu and memory in the configuration file

Modify the vm1 configuration file

Virsh edit vm1

<Memory> corresponds to Maxmemory in dominfo

<CurrentMemory> corresponds to Usedmemory in dominfo

<Vcpu> CPU (s) in dominfo)

<Memory unit = 'kiib '> 1048576 </memory>

<CurrentMemory unit = 'kiib '> 1048576 </currentMemory>

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

Shutdown vm1 and then start it to take effect.

Virsh destroy vm1

Virsh start vm1


3.IsVm1Expand one10GOfDisk

Generate a 10 GB disk file/vm/vm1-add

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

Modify the vm1 configuration file

Virsh edit vm1

The current disk file of vm1 is/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>

Append the following lines

<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>

Shutdown vm1 and then start it to take effect.

Virsh destroy vm1

Virsh start vm1

View the disk information of 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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.