I’m in the process of setting up a machine to host several SAMP (Solaris-Apache-MySQL-PHP) containers. I decided that it would be very efficient to create a generic zone and clone it over and over again. From reading up on the subject it seemed more than possible, after all, what is a zone besides a config file and a filesystem?
I googled for “Cloning Solaris Zones” and found lots of documentation on the zoneadm clone feature. I started to follow the howtos and hit a brick wall… my zoneadm doesn’t know how to clone. Deeper digging shows that the documentation on Sun’s site was for Solaris Express- Sun’s bleeding edge version of OpenSolaris- Can I say “How useless!”
I continued to google, after all I was very close I have the configuration and the filesystem, I just need to connect the two. I found the zoneadm attach/detach commands. This sounds perfect to me but alas my zoneadm doesn’t support attach/detach. Apparently, this feature is only available from Solaris 11/06- Can someone tell me when Sun started releasing new OS versions every 6 months!
I had no intention of giving up and here is the process which evolved:
- Setup the “Gold Master” zone including all the services, users, passwords, etc. (I’m assuming that your zonepath is a ZFS filesystem- this has it’s pluses and minuses so don’t take my word on it.)
- Halt the Master zone and export the config file to your zone template file:
zoneadm -z master halt
zonecfg -z master export -f /root/template
- It should look something like this: (edit with values for new zone)
add value (priv=privileged,limit=10,action=none)
- Configure a new zone using the new config file:
zonecfg -z zoneclone -f zoneclone.cfg
- Create a ZFS snapshot of the master zone:
zfs snapshot zfspool/[email protected]
- Clone the ZFS snapshot
zfs clone zfspool/[email protected] zfspool/zoneclone
- Mount the new ZFS filesystem at the correct zonepath
zfs setmountpoint=/zfszones/zoneclone/ zfspool/zoneclone
- Change the zone state to “installed” –WARNING: I have no idea if this is a good idea but it seems to work.
Find a line that looks like:
Replace it with:
- Boot the new zone:
zoneadm -z zoneclone boot