Devzones: Simple Use-and-throw Developer Environments

Devzones, short for development zones, is a type of virtualization found in the Nexenta distribution. It can be used to define a base developer environment, which can be easily cloned many times. These copies can easily be destroyed and recreated.

Devzones are built upon Opensolaris Zones, which are extensions of a chroot-like environment for the entire installed system. In other words, it allows for virtualization of an Opensolaris environment (and variants of Linux), without the performance hit that is generally associated with virtualization.

This article gives a practical introduction into using Devzones.

Devzone

John is a developer on project X, and wants to involve A, B, C and D from around the world to the project. However, project X requires that the environment variables be set, certain packages be installed, and source code be setup. It also requires build machines be installed with an operating system, accounts be created with the right permissions, and care taken to see that the users cannot inadvertently bring down the machine. How can John create such a setup, and reduce the time required to initiate A, B, C and D to project X close to 0?

One way is to setup a build machine, setup all the relevant packages, and hope A, B, C and D use the resources and privileges given to them correctly. Setting this up takes the initial time. If the system is corrupted, taken down for any reason by user A, the others would be hit, and time is also lost with setting up the environment again.

Another solution is to create a virtual machine, and install relevant packages, and set them up so A, B, C and D can pick it up immediately and start working. This however involves playing with big VM files, and takes up disk space 4 times. Another downside is that virtualization takes a performance hit.

What if there was a method where:

  • You can easily create and destroy an installed system.
  • Lose no disk space when you create copies of a system.
  • The creation and deletion of these systems took under 3 seconds.
  • You have access to Ubuntu’s stack of server and other applications

Devzones, short for development zones, is a type of virtualization found in the Nexenta distribution. It can be used to define a base developer environment, which can be easily cloned many times. These copies can easily be destroyed and recreated.

Devzones are built upon Opensolaris Zones, which are extensions of a chroot-like environment for the entire installed system. In other words, it allows for virtualization of an Opensolaris environment (and variants of Linux), without the performance hit that is generally associated with virtualization. For a detailed look at Nexenta, take a look at an earlier article on Nexenta here. For more information on Zones, take a look at it’s community page.

Nexenta is a FOSS distribution that combines the Opensolaris kernel with Ubuntu’s userland. It contains packages from Ubuntu LTS 8.04 (hardy). More information at the Nexenta homepage.

In this article we’ll take a step-by-step look at how we can setup Devzones on Nexenta.

Installation

Devzones are simple to install, simply run:

sudo apt-get install Devzones

NOTE: The latest NCP2 beta1 distribution includes Devzones by default.

Devzones consists of a set of applications that interact with the lower-level Opensolaris Zone commands.

For the administrator

  • Devzone_adm
    • Devzone_adm init
    • Devzone_adm add
    • Devzone_adm del
    • Devzone_adm list
    • Devzone_adm create
    • Devzone_adm free
    • Devzone_adm uninit

For the user

  • Devzone_create
  • Devzone_enter
  • Devzone_free

Zones

To understand how Devzones work, lets understand how zones work on Opensolaris. A zone is a virtualized environment where you can run applications. The application run in this sand-boxed environment, and as far as it is concerned, it is running in a brand new install of the operating system. Devzones configures one such base zone as a template to create other Devzones. Thus, you can customize this base environment to your needs (Ex: installing build tools, custom apps, etc).

Devzone System Thumbnail

Setting up the base zone

If you’re already familiar with Opensolaris zones, you can generate a zone manually for your needs. If you aren’t, run the following in the Nexenta shell. If you want to setup base zone on a different IP address, change the “set address=” line. Also change bge0 to reflect your network interface (can be found by running the ‘ifconfig -a’ command )

sudo zonecfg -z base_zone << EOD
create -b
set zonepath=/zones/base_zone
set ip-type=shared
add net
set address=172.24.101.56
set physical=bge0
end
commit
verify
EOD

You’ve now created the configuration for your base zone, named base_zone. The next step is to install it, which can be done by the following command:

#installing the zone. This will take a little while
sudo zoneadm -z base_zone install

NOTE: the first line of output should say:

A ZFS file system has been created for this zone.

This means the zone is ready for use with ZFS snapshots and clones. If this message is missing, the zone is not setup properly with ZFS and would be duplicated by copying which is slow and uses more disk space than ZFS snapshots and clones.

The final step is to add your special magic to the base zone, and configuring the environment for your needs. This is done by booting the zone, and logging in:

#boot the zone so you can login.
sudo zoneadm -z base_zone boot

#Once done, login normally
sudo zlogin base_zone

Customizations

Once you run zlogin, you are dropped into the zone as a root user. Go ahead and customize the environment to your taste. Various tasks you might do are:

  • Installing compilers and build tools: apt-get install build-essential
  • Installing your favourite tools: apt-get install screen irssi
  • Customizing rc files (.vimrc, .bashrc, .screenrc)
  • Etc..

Once you’ve made your changes, run logout to go back to the global zone

Setting up the Devzones

We now move to the final step: stopping the zone, and creating Devzones. The Devzone has to be stopped before it can be cloned. To stop the base zone, run:

sudo zoneadm -z base_zone halt

Initialize the Devzone database

sudo Devzone_adm init

You will now have to decide how many Devzones the machine can support (i.e, how many users can be logged in at the same time working in their own Devzone). A good rule of thumb is to give 512 MB of RAM to a zone, and thus the number of zones you can have

Number of Devzones = Free memory / 512

You can modify the memory usage number depending on the amount of resources you think your typical Devzone tasks will require. Also decide on a name and IP address for each zone and run:

sudo Devzone_adm add zonename

show the text of a created zone

Do this for each zone. Devzones are now setup!

The User

A normal user, to create a Devzone, runs:

Devzone_create
anilg@mybox:~$ Devzone_create 
Reserving zone: lanai
setting up zone: lanai
Cloning snapshot tank/zones/base_zone@SUNWzone4
Instead of copying, a ZFS clone has been created for this zone.

This will reserve a Devzone for the user. He can then enter and exit the zone using the following:

#Entering the Devzone
Devzone_enter

#Coming out of a Devzone, run the following when inside
logout

A user can also run a command inside the Devzone

Devzone_enter command

anilg@mybox:~$ Devzone_enter hostname   
Zone state: running
Entering zone...
lanai
anilg@mybox:~$

Once a user is done using the zone, he simply runs the following to destroy his zone, and free it up for someone else:

Devzone_free

If an administrator wants to free a Devzone, he can free it using the Devzone_adm free command:

sudo Devzone_adm list
Zone    User  UID
global  root  0
lanai   anil  1001
fiji          -1
kauai         -1
maui          -1
midway        -1
oahu          -1
tahiti        -1

sudo Devzone_adm free zonename
anil@gnusolaris:~$ sudo Devzone_adm free lanai
Running Releasing zone...
taking down zone: lanai
halting...
uninstalling...
The ZFS file system for this zone has been destroyed.
deleting configuration...
Releasing zone completed

Try it

This was a simple guide to Devzones on Nexenta. To recount the advantages of Devzones

  • Easily deployable environment: create and delete instances of a devzone in a jiffy
  • Resource efficient: if you have 50 developers, with a maximum of 10 actually developing at any given time, invest only on the resources of 10.
  • Space efficient: creation of a new instance of a devzone does not take up space. It is only consumned for new content created.
  • Instant update: changes made to the base zone are reflected to all devzones.
  • Peace of mind: Your users can run an rm -rf *, in their devzone, without affecting the others. Also setting up after a screw-up takes an instant.

Give it a shot, and reduce the time required for your developers setup the working environment. You can grab Nexenta from:

To try out a live demo of Devzone, join our IRC channel below and ask for our build machine’s community login/pass. Devzone is primarily developed and maintained by Tim Spriggs and he can be found
on the Nexenta IRC channel on freenode for any questions/comments/suggestions you have.

7 Comments

  1. 2008-12-22 5:20 pm
    • 2008-12-22 5:24 pm
      • 2008-12-22 6:03 pm
  2. 2008-12-22 6:59 pm
    • 2008-12-22 7:10 pm
  3. 2008-12-23 3:50 pm
    • 2008-12-23 8:13 pm