Vagrant: custom virtual environment

vagrant_compPreconfigured virtual machines always come in handy and save the pain and time of manually setting them up from scratch. Vagrant is a community based service that works like a repository of preconfigured virtual machines of diverse configuration. Need an Ubuntu 14.04 server with LAMP or a Red Hat server with chef configuration? Vagrant has those! Vagrant supports both VMware and VirtualBox VMs.

Whether you are a developer or a system administrator, Vagrant is always at your beck and call to create an isolated development environment or a dedicated server.

Here’s how easy it is to use Vagrant. It is multiplatform and supports Linux, Windows and Mac. Download Vagrant from its website (link below) and install it on you machine. You need to have either VMware or VirtualBox installed on your box to install VMs from Vagrant.

Initialize and start a 32-bit Precise VM:

$ vagrant init hashicorp/precise32
$ vagrant up

In case you are wondering how to get the container for precise32, you can search VMs and use the container that matches your needs. There are a number of criteria to filter the results. Find more community provided boxes (standard templates) here.

Vagrant is very flexible and has many options. Vagrant docs is the best place to get started.

Webpage: Vagrant

VMware Player 6.0.2, Ubuntu 14.04, kernel 3.15.0-rc7 patch

vmware_compVMware Player throws errors while compiling the vmci and vsock modules with just-released kernel 3.15.0 rc7 on Ubuntu 14.04 (Trust Tahr) x86_64. Instead of Ubuntu kernel-ppa mainline this time I have compiled the kernel from Linus’s Git tree and using it.

The errors in vmci module are:

...
/tmp/modconfig-5Nq5Lx/vmci-only/linux/driver.c:740:12: error: incompatible types when assigning to type ‘VMCIHostUser’ from type ‘kuid_t’
user = current_uid();
^
make[2]: *** [/tmp/modconfig-5Nq5Lx/vmci-only/linux/driver.o] Error 1
...

In addition to similar errors as above, other errors in vsock module are:

...
/tmp/modconfig-KpbL9l/vsock-only/linux/notify.c:519:4: error: too many arguments to function ‘sk->sk_data_ready’
sk->sk_data_ready(sk, 0);
^
...

The above are happening due to introduction of a structure kuid_t and change in signature of sk_data_ready(). I have uploaded the patches for both the modules here.

Once you download the patches, run the following as root:

# cd /usr/lib/vmware/modules/source
# mv /path/to/kernel_3.15.0-rc7-patch.tar.gz .
# tar -zxvf kernel_3.15.0-rc7-patch.tar.gz
# tar -xf vmci.tar
# tar -xf vsock.tar
# mv vmci.patch vmci-only/
# mv vsock.patch vsock-only/
# cd vmci-only/
# patch -p1 < vmci.patch
# cd ../vsock-only/
# patch -p1 < vsock.patch
# cd ..
# tar -cf vmci.tar vmci-only/
# tar -cf vsock.tar vsock-only/
# vmware-modconfig --console --install-all

All the modules should compile without any issues now.

VMware-Player 6.0.1, Ubuntu 13.10, kernel 3.13.5 patch

vmware_compI didn’t upgrade my kernel for a while since 3.12. After upgrading the Linux kernel to version 3.13.5-031305-generic (published today in the Ubuntu mainline kernel PPA) on Ubuntu Saucy, vmplayer 6.0.1 build-1379776 (x86_64) threw the following error while compiling the vmnet module:

# vmware-modconfig --console --install-all
...
/tmp/modconfig-OEBtR5/vmnet-only/filter.c:206:1: error: conflicting types for ‘VNetFilterHookFn’
 VNetFilterHookFn(unsigned int hooknum,                 // IN:
 ^
/tmp/modconfig-OEBtR5/vmnet-only/filter.c:64:18: note: previous declaration of ‘VNetFilterHookFn’ was here
 static nf_hookfn VNetFilterHookFn;
...

NetFilter is enabled and compiled in with the generic mainline kernel. I wanted to keep the change localized to the vmnet driver code and used the same signature from filter.c that  VNetFilterHookFn uses. I have uploaded the patch here.

To apply the patch and recompile the modules run the following as root:

# cd /usr/lib/vmware/modules/source
# tar -xf vmnet.tar
# cd vmnet-only
# patch < filter.patch
# cd ..
# tar -cf vmnet.tar vmnet-only/
# vmware-modconfig --console --install-all

After applying the patch vmplayer compiled without any further issues and the network works fine on my VMs.

Mount VMware disk images (vmdk) on Linux

vmware_compThere is a trivial way to mount vmware disk images (*.vmdk files) from the GUI using VM settings. However, to do that remotely from the cmdline, VMware provides a specific tool vmware-mount which can be used as a regular user. Usage:

  1. Create the directory to mount the virtual disk:
    $ mkdir vmmnt
  2. Mount the virtual disk:
    $ vmware-mount myVM/myVM.vmdk vmmnt/
  3. Now any changes you make under vmmnt directory will be saved when you unmount:
    $ vmware-mount -k myVM/myVM.vmd

To mount vdi files on Ubuntu, download the right virtualbox-fuse package for your release and architecture from Launchpad. Then run:

//Install
$ sudo dpkg -i --force-depends virtualbox-fuse_$version_$arch.deb
//Mount vdi and volume
$ mkdir ~/vdisk
$ mkdir ~/vol1
$ sudo vdfuse -f Machine.vdi ~/vdisk
$ sudo mount ~/vdisk/Partition1 ~/vol1

Install VMware tools manually on Ubuntu

vmware_compIf your VM is not network connected or the network speed is slow you might need to install vmware-tools manually on your guest OS. VMware-tools can be downloaded for different VMware versions, host and guest OS from the following location:
http://softwareupdate.vmware.com/cds/vmw-desktop/player

Navigate to the correct directory corresponding to your vmplayer version and host OS. For example, the path to vmware-tools package for vmplayer 5.0.2 and Linux is:
http://softwareupdate.vmware.com/cds/vmw-desktop/player/5.0.2/1031769/linux/packages/

The package file name should have the name of your guest OS. For example, if your guest VM is Windows XP and youst host OS architecture is 64-bit, you should download the following file:
vmware-tools-windows-9.2.3-1031769.x86_64.component.tar

To install, extract the downloaded package and install on Ubuntu using the following command:

# vmware-installer --install-component=xxx.component

Boot from USB on VMware

The default BIOS on VMware doesn’t support booting from USB in VMs (at least not yet). However, it is possible to do that using the Plop boot manager easily. Download the latest version and extract the files (I tried version 5.0.15-test). We need the plpbt.iso file to boot the VM.

Create a new VM and use the plpbt.iso to boot it.

plpbt

USB Controller should be present with following settings –

usbcontroller

On boot, use the USB option in bootloader menu. In case of any issues, check that the USB pen drive is connected in the VM settings.

boot

Plop works with VirtualBox. It is useful for booting older machines with no USB boot capability as well.