Previously, we create a configuration file for each DomU virtual machines in our cluster. Most of the content in these configuration files is the same. The differences are only the name, memory size and image file address. There are several disadvantages of this method: We must create and configure a new configuration file when creating a new virtual machines; We must change every configuration files when we want to change the parameters of the virtual machines such as change the raw image file driver from loopback to tap. So we change to using a unified Xen DomU configuration file. We creating DomUs, just use this unified Xen DomU configuration file and add some parameters to it.
For VM with id *vmid*: Name is: vm*vmid* Raw image file address is: /lhome/xen/vm*vmid*/vmdisk*vmid* The parameter for *vmid *is *vmid*. The parameter for memory size is *vmmem*. We force the memory size of the virtual machines to be at least 1G. We assume the virtual cpu number is 2 for all virtual machines. If the cpu number should be different from virtual machines, we can also add a parameter for it.
The configuration file vm.run
This is the unified configuration file /lhome/xen/vm.run:
# Called automatically by 'xm create'. # Checks that 'vmid' has been given a valid value. def vmid_check(var, val): val = int(val) if val <= 0: raise ValueError return val # Checks that 'vmmem' has been given a valid value # Make sure the vmmem is >= 1024 def vmmem_check(var, val): val = int(val) if val <= 1024: return 1024 return val # Define the 'vmid' variable so that 'xm create' knows about it. xm_vars.var('vmid', use="Virtual machine id. Integer greater than 0.", check=vmid_check) # Define the 'vmmem' variable xm_vars.var('vmmem', use="Virtual machine memory. Integer greater thatn 1024.", check=vmmem_check) # Check the defined variables have valid values.. xm_vars.check() # -------------------------------------------------------------- name="vm%d" % vmid memory="%d" % vmmem disk=["tap:aio:/lhome/xen/vm%d/vmdisk%d,xvda,w" % (vmid,vmid) ] vif=['bridge=eth0'] bootloader="/usr/bin/pygrub" vcpus=2 on_reboot='restart' on_crash='restart'
The meaning should be easy to understand with these comments.
How to use it
When we want to create vm*vmid* with *vmmem* kb memory, just follow these steps:
# cd /lhome/xen # xm create vm.run vmid=<em>vmid</em> vmmem=<em>vmmem</em>
Latest posts by Eric Zhiqiang Ma (see all)
- Vim Tutorial for Beginners: vimtutor - Dec 31, 2016
- Essential Gnome Shell Extensions for Gnome 3 Users - Oct 22, 2016
- How to Install 32-bit Wine 1.8 on CentOS 7 - Oct 16, 2016