VMware tips
Fixing time-management in vm-instances on VMware
Install the VMware tools in the guest os, then in the .vmx-file set the following parameters to TRUE:
- tools.syncTime - sync periodically
- time.synchronize.continue - sync after snapshot
- time.synchronize.restore - sync after reverting to a snapshot
- time.synchronize.resume.disk - sync after resume
- time.synchronize.shrink - sync after defragmenting a virtual disk
Converting 'vmdk' to RAW disk for use in virtualbox/KVM
example:
$ cd /path/to/vmware/guestos $ for i in `ls *[0-9].vmdk`; do qemu-img convert -f vmdk $i -O raw {i/vmdk/raw} ; done $ cat *.raw >> guestos.img
Migration with vmware-vdiskmanager (from vmware to KVM)
vmware files
$ ls nvram opt-zimbra-s009.vmdk Zimbra-Training-VM-s004.vmdk opt-zimbra-s001.vmdk opt-zimbra-s010.vmdk Zimbra-Training-VM-s005.vmdk opt-zimbra-s002.vmdk opt-zimbra-s011.vmdk Zimbra-Training-VM-s006.vmdk opt-zimbra-s003.vmdk opt-zimbra.vmdk Zimbra-Training-VM-s007.vmdk opt-zimbra-s004.vmdk vmware-0.log Zimbra-Training-VM-s008.vmdk opt-zimbra-s005.vmdk vmware.log Zimbra-Training-VM.vmdk opt-zimbra-s006.vmdk Zimbra-Training-VM-s001.vmdk Zimbra-Training-VM.vmsd opt-zimbra-s007.vmdk Zimbra-Training-VM-s002.vmdk Zimbra-Training-VM.vmx opt-zimbra-s008.vmdk Zimbra-Training-VM-s003.vmdk
creating a temp disk and convert allocated - non-parted VMware disks
$ mkdir haha $ vmware-vdiskmanager -r Zimbra-Training-VM.vmdk -t 2 haha/Zimbra.vmdk $ vmware-vdiskmanager -r opt-zimbra.vmdk -t 2 haha/Zimbra-opt.vmdk
and get
$ ls haha/ Zimbra.vmdk Zimbra-flat.vmdk Zimbra-opt.vmdk Zimbra-opt-flat.vmdk
Converting ..
$ qemu-img convert -c -O qcow2 haha/Zimbra-flat.vmdk /var/lib/libvirt/images/Zimbra.img $ qemu-img convert -c -O qcow2 haha/Zimbra-opt-flat.vmdk /var/lib/libvirt/images/Zimbra-opt.img
after sucessful run under KVM (uinstall vmware-tools)
# vmware-uninstall-tools.pl # reboot
Backing up virtual machines on VMware Server 2.0
Because WMware's backup of running virtual machines is still in experimental stage, you have to shut down the virtual machines and then copy files from the datastore. That is - if you you want to avoid using that experimental feature.
You can create a user on a virtual machine and grant permission to shut down via sudo:
sudo adduser username admin
enables user username to run sudo- add
username hostname = NOPASSWD: /sbin/shutdown
to /etc/sudoers - Create a script, that will shut down virtual machines, check with ping after one minute if it is really shut down and then copy VM's files from datastore to TARGET location and after finishing that, power virtual machine back on. Of course you run it on your VMware Server host - where you have the datastore.
Here is an example of the script. You will have to modify at least usernames and paths, maybe more, but it will give you an idea of how it can be done.
f backup.sh
#!/bin/bash # # Backup virtual machines # # In file /home/user/vm_hostnames define hosts of virtual machines (as they appear in VMware Server). # DNS records for the same names must exist too! # TARGET=/mnt/backup # for VM in `cat /home/user/vm_hostnames` do ssh username@${VM} sudo /sbin/shutdown -h now sleep 60 ping -c 2 ${VM} TARGET_PATH=${TARGET}/${VM}.`/bin/date +%Y%m%d` mkdir $TARGET_PATH if [ $? -eq 1 ] then cp /vm/Virtual\ Machines/${VM}/* ${TARGET_PATH}/ /usr/local/vmware-server/bin/vmrun -T server -h https://VM_HOST_IP:8333/sdk -u vmuser -p vmpass start "[standard] ${VM}/${VM}.vmx" else echo Host $VM not shut down yet! >> /home/user/vm_backup.err fi done
vmuser
and vmpass
are username and password you use to login to VMware Server console. VM_HOST_IP
is the IP of your VMware Server host. The file vm_hostnames
in the script is a list of hostnames of virtual machines you wish to back up.