Creating Solaris Containers

Whilst there is an abundance of documentation on creating containers on the Sun documentation website, but somes it's not easy to read. The goal here is to create a container in the fewest number of steps. This should work on any release of Solaris 10, but I will be using Solaris 10u3.

Prepare the host system

We need a place for the zones to live, a place to keep the config files, and a place to share files between the zones. So I created the following directory structure, which is pretty much self explanatory:

  • /zones/cfg
  • /zones/share
  • /zones/containers
root@sol10# mkdir -p /zones/cfg /zones/share /zones/containers

Create the config files

We will call this zone alphaz. Create the file /zones/cfg/alphaz.cfg and add the following content:

create -b
set zonepath=/zones/containers/alphaz
set autoboot=true
add fs
   set dir=/zones/share
   set special=/zones/share
   set type=lofs
   add options ro
end
add net
   set address=10.10.0.21
   set physical=e1000g0
end

The above config should be self-explanitory, but I'll go over a few of them:

  • set zonepath is where the zone's files will be created - the container's root will begin at that path on the host system.
  • set dir specifies the directory within the zone where the share will be mounted.
  • set special specifies the directory on the host you want mounted in the zone.
  • set address is obviously the IP address of the zone.
  • set physical is the interface of the host you want the zone to listen on. It will create a virtual interface with the IP you specify on that physical interface.

Configure the zone

Use zonecfg to configure the zone:

root@sol10# zonecfg -z alphaz -f /zones/cfg/aplhaz.cfg

Check zone is configured:

root@sol10# zoneadm list -cv

Install the zone

Using the zoneadm command we can install the zone:

root@sol10# zoneadm -z alphaz install
Preparing to install zone <alphaz>
Creating list of files to copy from the global zone.
Copying <124447> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <979> packages on the zone.
Initialized <979> packages on zone.
Zone <myzone> is initialized.
The file <zones/containers/alphaz/root/var/sadm/system/logs/install_log> contains a log of the zone installation.

NOTE: Grab a coffee - it's gonna take a while :-)

Boot the zone

Again, using zoneadm lets boot the zone:

root@sol10# zoneadm -z alphaz boot

Login to the zones console, so we can finish the Solaris installation:

root@sol10# zlogin -C alphaz

You may not see anything immediately, simply hit Enter. You should now be presented with a terminal choice.

At this stage it should be pretty standard system configuration questions.

NOTE: This part of the process can be automated by creating a /etc/sysidcfg.