Creating Solaris Containers (zones)

March 15, 07 by cjgibbs

So I know there is ample documentation on this in the Sun docs but if you’ve ever tried to read Sun docs then you know that someone giving an example is much easier to understand. The goal will be to create a container in the fewest number of steps. This should work on any release of Solaris 10 but I will be using u3.

Step 1. 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 create the following directory structure, which is pretty much self explanatory:

/zones/cfg
/zones/share
/zones/containers

Step 2. Create the config files

We’ll call this zone myzone. Create the file /zones/cfg/myzone.cfg and put the following in it:

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

Most of that is understandable 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.

Step 3. Configure the zone

This part’s easy:

# zonecfg -z myzone -f /zones/cfg/myzone.cfg

Now check that it was configured:

# zoneadm list -cv
ID NAME STATUS PATH
0 global running /
- myzone configured /zones/containers/myzone

Step 4. Install the zone

Nice and easy again:

# zoneadm -z myzone install

Go get a drink - it’s gonna take a while.

Preparing to install zone <myzone>.
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/myzone/root/var/sadm/system/logs/install_log> contains a log of the zone installation.

Whew, now that it’s done you can boot it:

# zoneadm -z myzone boot

Once the prompt returns you can log into it from the host system with:

# zlogin myzone

Alternatively you could enable the ssh service on the zone so you don’t always have to go through the host.

[UPDATE] The zone now needs to be configured, see part II.

This entry no have comments... but you can be first.

Leave a Reply