Headless Virtual Guest Running under VMware (Fusion)

Site Section: 

Keywords: 

Headless guests are usually not the best company for conversation, no matter how fancy the moves they might pull off on the dance floor. However, a headless virtual guest machine running Linux makes for a fantastic development environment, serving as a back-end "under-the-hood" engine to crunch and execute code. This is especially useful if your primary host ecosystem has gradually become more and more irritating for development with every operating system release (yes, Apple, I am looking at you). The following post describes how to set up a headless virtual guest Linux box on your OS X system using VMware Fusion. The virtual machine will have relatively seamless access to your local filesystem, through a network share, while you will be able to interact with the virtual machine through an SSH session. This means that you can seamlessly edit code and projects using your IDE of choice (Vim, of course) within your native operating system, but execute/test the code on the virtual machine through an SSH session (with the current working directory being the project directory on your local system, as it is mounted as a networked drive on the virtual machine). This also means that, with all the IDE and associated desktop infrastructure on your host, you can keep the guest virtual machine lean and light, stripped down to the bare essentials for running/executing code and nothing else.

The following assumes that:

  • You are running VMware Fusion 4 on the host as the virtualization platform.
  • You have a working install of a Linux distribution on the virtual machine (I describe how to do this here, using Arch Linux).
  • You have set up Open VM Tools on the operating system and enabled your host home (and/or other) directories to be shared with the guest (also described here).
  • You have set up the guest for SSH logins (again, described here).

Virtualization Platform: Assign a Fixed IP Address to the Virtual Machine

  1. Shutdown all guest machines and VMare (though you may want to run "echo $HOSTNAME" and "ip addr" on them first to get and record the hostname and MAC address; see below).

  2. In the host machine, open "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf" (in VMware Fusion 3, this was "/Library/Application Support/VMware Fusion/vmnet8/dhcpd.conf") for editing.

  3. Find the section:

        subnet 144.133.103.0 netmask 255.255.255.0 {
            range 144.133.103.128 144.133.103.254;
            option broadcast-address 144.133.103.255;
            option domain-name-servers 144.133.103.2;
            option domain-name localdomain;
            default-lease-time 1800;                # default is 30 minutes
            max-lease-time 7200;                    # default is 2 hours
            option netbios-name-servers 144.133.103.2;
            option routers 144.133.103.2;
        }
    
  4. The line beginning with "range" specifies the range of the reserved IP numbers. In the above example, it is from "144.133.103.128" to "144.133.103.254". Select an IP number outside this range, e.g. "144.133.103.100". This will be "<GUESTIP>" in the snippet below.

  5. You will need to know the hostname of the guest virtual machine ("<GUESTHOSTNAME>") as well as its MAC address ("<GUESTMAC>"). The easiest way to get these if you do not already know them is to temporarily fire up the guest, and run "echo $HOSTNAME" and "ip addr", respectively.

  6. For each virtual machine, add the following entry to "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf":

            host <GUESTHOSTNAME> {
                hardware ethernet <GUESTMAC>;
                fixed-address <GUESTIP>;
            }
    

    For example:

            host archosaur {
                hardware ethernet ff:2f:19:11:4a:75;
                fixed-address 144.133.103.100;
            }
    
  7. In the host machine, restart the VMware networking services:

            $ sudo "/Applications/VMware Fusion.app/Contents/Library/services.sh" --stop
            $ sudo "/Applications/VMware Fusion.app/Contents/Library/services.sh" --start
    

    [Note that in VMware Fusion 3.0, this was "/Library/Application Support/VMware Fusion/boot.sh --restart".]

Some Sugar: Easily Starting and Stopping the Virtual Machine in Headless Mode

Add the aliases along the following lines to your "~/.bashrc", one set for each virtual machine (named "<VMNAME>"):

    alias <VMNAME>-start='/Applications/VMware\ Fusion.app/Contents/Library/vmrun -T fusion start /path/to/vmfile.vmwarevm nogui'
    alias <VMNAME>-stop='/Applications/VMware\ Fusion.app/Contents/Library/vmrun -T fusion stop /path/to/vmfile.vmwarevm'
    alias <VMNAME>='<VMNAME>-start && ssh <GUESTIP>'

For example:

    alias archosaur-start='/Applications/VMware\ Fusion.app/Contents/Library/vmrun -T fusion start /opt/vmware/Arch\ Linux\ 2001-08-19\ 64-bit.vmwarevm/ nogui'
    alias archosaur-stop='/Applications/VMware\ Fusion.app/Contents/Library/vmrun -T fusion stop /opt/vmware/Arch\ Linux\ 2001-08-19\ 64-bit.vmwarevm/'
    alias archosaur='archosaur-start && ssh 144.133.103.100'

2 Comments

However, when you then open

However, when you then open the VMWare VM Library ( for example, to start a different machine with a gui, or create a new vm, or edit config, etc ), a window for your nogui vm spawns, and I can't seem to close it without killing the VM :-/

Add new comment