Building Zimbra on Gentoo

Revision as of 21:52, 26 January 2008 by Spcmnspff (talk | contribs) (Installing Zimbra in a Gentoo chroot)

Here's a howto that will get Zimbra going on a Gentoo install. This method basically leverages debootstrap to get a bare debain sarge install in a chroot environment. The open source zimbra 4.5 package for Debian can then be installed. This is working on Gentoo 2006.1 kernel 2.6.17-gentoo-r5. But you shouldn't have any issues running it on recent versions. At first this may seem like extra work and a waste of resources, but to the contrary running Zimbra in a chroot is a pretty good idea. People have been hosting chroot jails on *BSD's to run various internet services for quite some time. This can add a level of protection for the host system. I.e. if the unthinkable happens and an attacker does find a way to gain root through the host services on your Zimbra instance, (s)he will only have access to the chroot environment.

Stopping Apache on the Gentoo host

If you have a web server runing on your host Gentoo system you will need to stop it for now. Later you can change the ports Zimbra will listen on and run your host's web server and your Zimbra web server on the same machine.

# /etc/init.d/apache2 stop
# rc-update delete apahce2

Installing Zimbra in a Gentoo chroot

(Some of this was taken from

Emerge debootstrap

# echo "dev-util/debootstrap" >> /etc/portage/package.keywords
# emerge debootstrap

Create the chroot environment

# mkdir /zimbra

Run debootstrap

# debootstrap sarge /zimbra

If you are on amd64 you will need to use debootstrap --arch i386 sarge /zimbra so that it knows which architecture to bootstrap onto your machine.

Mount proc, dev and sys

# mount -o bind /proc /zimbra/proc
# mount -o bind /sys /zimbra/sys
# mount -o bind /dev /zimbra/dev
# mount -o bind /dev/pts /zimbra/dev/pts
# mount -o bind /dev/shm /zimbra/dev/shm

Chroot to the debian environment

# chroot /zimbra

Set a root password

# passwd

Adjust your hosts and hostname files

# nano -w /etc/hosts
# nano -w /etc/hostname

Add cache limit to apt.conf

# echo "APT::Cache-Limit 16777216" >> /etc/apt/apt.conf

Tell apt where to get all the repositories

This will execute an ncurses menu prompting you to choose a debian mirror pick http or ftp and select a (hopefully) fast mirror:

# apt-setup

Update the package listing

# apt-get update

Install some packages that we will need

# apt-get install sshd wget sudo libidn11 curl fetchmail libgmp3 libxml2 libstdc++6 openssl file perl libexpat1

Get the zimbra debian package and untar the archive

# CD ~
# wget
# tar -xvzf zcs-4.5.10_GA_1575.DEBIAN3.1.tgz

Run install script in the newly created zcs directory

# cd zcs
# ./

Follow the instructions. See the Zimbra documentation for help.

Configure sshd to run on a different port

(This is basically copied from the Zimbra forums at

sshd running on the Gentoo host conflicts with a service that Zimbra runs. It will hinder Zimbra's ability to monitor queues from the management console. So let's fix it:

# nano -w /etc/ssh/sshd_config

Find the line that reads:

port 22

and change it to:

port 23

Start sshd

# /etc/init.d/ssh start

Tell Zimbra to run sshd on port 23

# su - zimbra
$ zmprov ms MAIL.DOMAIN.COM zimbraRemoteManagementPort 23

substitute MAIL.DOMAIN.COM with the fqdn of your host name

Build and deploy new ssh keys

$ /opt/zimbra/bin/zmsshkeygen
$ /opt/zimbra/bin/zmupdateauthkeys

Test your Zimbra install

$ zmcontrol start

Creating the init scripts

It would be nice to get Zimbra to start at boot in the default run level. This requires an init script. Some of the init scripts that have been floating around for this are a little rough, raising job control issues while piping to the chroot command in the init shell. To avoid this we'll generate three scripts. Two scripts will live inside the chroot environment and will start and stop Zimbra. One script will live in /etc/init.d in the Gentoo host environment and will pass control to the start and stop scripts at the right time.

Exit chroot and create the gentoo init.d script

$ exit && exit
# nano -w /etc/init.d/zimbra
append init.d script from below


# nano -w /zimbra/usr/sbin/
append script from below


# nano -w /zimbra/usr/sbin/
append script from below

Make the scripts executable

# chmod +x /etc/init.d/zimbra
# chmod +x /zimbra/usr/sbin/
# chmod +x /zimbra/usr/sbin/

Test the init script

# /etc/init.d/zimbra stop
# /etc/init.d/zimbra start

Add it to the default run level

# rc-update add zimbra default

Now you should have a functioning Zimbra system installed in a chroot that you can manage from the host gentoo system at boot or otherwise. If you were running a web server on your host gentoo system you will need to configure Zimbra to listen on different port for web and ssl (try 81 and 1443). Search the zimbra forums there is some documentation for this already in place. You will then be able to cofigure a named based vitual host to link from you gentoo hosted site to zimbra.

Script: /etc/init.d/zimbra


depend() {
    need net
    after portmap
    after iptables
    after dnsmasq

start() {

ebegin "Starting Zimbra in chroot environment"

# Mount the dirs
   mount -o bind /proc /zimbra/proc > /dev/null
   mount -o bind /dev /zimbra/dev > /dev/null
   mount -o bind /dev/shm /zimbra/dev/shm > /dev/null
   mount -o bind /dev/pts /zimbra/dev/pts > /dev/null
   mount -o bind /dev/sys /zimbra/sys > /dev/null

# Start the services in chroot
   chroot /zimbra /usr/sbin/

eend $? "Errors were encountered while starting Zimbra in chroot environment"


stop() {

ebegin "Stopping Zimbra in chroot environment"

# Stop all the services in chroot
   chroot /zimbra /usr/sbin/

# Unmount the dirs
   umount -f /zimbra/proc > /dev/null
   umount -f /zimbra/dev > /dev/null
   umount -f /zimbra/dev/shm > /dev/null
   umount -f /zimbra/dev/pts > /dev/null
   umount -f /zimbra/sys > /dev/null

eend $? "Errors were encountered while stopping Zimbra in chroot environment"


Script: /zimbra/usr/sbin/


#Start all the services for zimbra
   rm -rf /var/run/*.pid
   /etc/init.d/sysklogd start
   /etc/init.d/cron start
   /etc/init.d/sshd start
   su - zimbra -c /opt/zimbra/bin/zmcontrol start

Script: /zimbra/usr/sbin/


#Stop all the services for zimbra
   su - zimbra -c /opt/zimbra/bin/zmcontrol stop
   /etc/init.d/sshd stop
   /etc/init.d/cron stop
   /etc/init.d/sysklogd stop

Building Zimbra from source on Gentoo

(needs to be documented)

Jump to: navigation, search