Skip to content

Instantly share code, notes, and snippets.

@mgax
Last active December 31, 2015 19:59
Show Gist options
  • Save mgax/8037389 to your computer and use it in GitHub Desktop.
Save mgax/8037389 to your computer and use it in GitHub Desktop.
Development VM setup

Rationale

This setup aims to create a clean development environment, by keeping development tools and libraries in a virtual machine, separate from the host computer. Separation has several advantages: you can back up the virtual machine, move it to a different host, keep multiple environments around (e.g. for wokring on projects with wildly different dependencies, or upgrading the development toolchain without risking downtime), and base the development environment on a different OS (hello Linux!). Last but not least, it keeps the host machine clean.

The downside is that you're running code inside a VM. You need to log in (we'll use SSH), make sure the code is available and in sync (we'll set up NFS). There's also some I/O overhead, and you need to decide on how much memory, CPU and disk space you allocate to the VM. You can change your mind later, but it's a bit of a hassle to resize virtual disks and partitions.

Set up the VM

We assume you're running MacOS and have VMware Fusion already installed. Also download the latest Debian installer ISO (the multiarch netinst version: download ISO or via BitTorrent. You can create a similar setup with another guest OS, virtualization solution, or host OS, but you'll have to adapt the instructions.

So let's create our virtual machine. Choose the option to install from a disk image (the Debian ISO you just downloaded) and then "create a custom virtual machine". For "Operating System" choose "Debian 7 64-bit". Feel free to change the disk size, amount of memory and number of cores. My settings are: 20GB disk, 2GB memory (the host machine has 8GB), and 6 cores (the host machine sees 8 hyperthreaded cores). Remember where you save the virtual machine, we'll use this path later.

Install Debian in the VM. The installer will offer to create a normal user account for you; enter the same username you use in the host OS to keep things simple.

SSH

Log in as root in the VM and run apt-get install openssh-server. Figure out the IP address of the VM by running ifconfig eth0 | grep 'inet addr', it should be similar to 192.168.67.131. Then, from the host, open Terminal and run ssh 192.168.67.131 (replace with your address). You should be logged into the VM.

To make logins faster, you can add UseDNS no to /etc/ssh/sshd_config, it will disable reverse DNS lookups. It also makes sense to log in via SSH key. And you can configure sudo to not ask for a password, by modifying /etc/sudoers so it contains this line: %sudo ALL=NOPASSWD: ALL.

At this point, we can access the VM via SSH, so we don't need the VMware window. Tell VMware to suspend the VM, open a Terminal window in the host, and start the VM in headless mode: '/Applications/VMware Fusion.app/Contents/Library/vmrun' start '/path/to/virtual/machine.vmwarevm nogui'. You can always open VMware and it will connect to running VMs and open windows for them.

NFS

You can share a folder between the host and guest machines. I like to keep all my work in a top-level folder on the host machine, and share the entire folder with the guest, so absolute paths are the same in both machines, and that's what I'll describe below. You can try to use VMware shared folders, but in my experience, they have bugs (files not being updated; kernel crashes), so I'm using NFS.

On the host machine, create or modify /etc/exports, to contain this line:

/ZeStuff -rw 192.168.67.131 -mapall=mgax

Change the following parts: /ZeStuff is the path to your shared folder; 192.168.67.131 is the IP address of the guest; mgax is your username. Then run sudo nfsd update.

Inside the VM, install NFS: apt-get install nfs-common. Then add the following line to /etc/fstab to mount the shared folder at boot:

192.168.67.1:/ZeStuff /ZeStuff nfs rw,sync,actimeo=1 0 0

Again, replace /ZeStuff with your folder path. Make sure to create an empty folder with the same path on the guest machine. Then mount the shared folder: mount /ZeStuff.

Custom terminals

If you're lazy like me, you want to open SSH sessions to the VM easily. From Terminal preferences, you can configure a separate profile, and in the "shell" tab, check "run command" and enter ssh 192.168.67.131 (replace with your VM's address). As a bonus, you can set a different color scheme for this profile, to distinguish sessions in the VM versus the host machine. You can also set up a shortcut for this profile, in System Preferences -> Keyboard -> Shortcuts -> App shortcuts, click "+", select Terminal, and enter a menu title and a shortcut.

@cristiroma
Copy link

On CentOS 6.5, alternatively to apt-get install nfs-common you can use

yum install nfs-utils
. Also, you need to enable the rpcbind service:
service rpcbind restart
Otherwise you get the error
mount.nfs: rpc.statd is not running but is required for remote locking
while trying to mount the fstab entry.

@MihaiTabara
Copy link

The Debian OS version has been bumped. The correct URL is now:
http://cdimage.debian.org/debian-cd/7.4.0/multi-arch/iso-cd/debian-7.4.0-amd64-i386-netinst.iso

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment