Building Zimbra on Gentoo

Revision as of 22:29, 13 December 2007 by Spcmnspff (talk | contribs) (Installing Zimbra on Gentoo using the provided Debian package)

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 older 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 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 hosts web server and your zimbra webserve on the same machine.

# /ect/ini.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 inside the chroot:

sshd running on the Gentoo host is one of those conflicting services mentioned earlier. 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/sshd start

Test your Zimbra install

# su - zimbra
$ 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 for this floating around are a little rough, having job control issues while piping to the chroot command in the init shell. To avoid this we'll generate 3 scripts. Two scripts will live inside the chroot environment and will start and stop Zimbra. And one will be a gentoo init script that passes control to these 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 alrady in place. You will then be able to cofigure a named based vitual host to link from you gentoo hosted site to zimbra.

init.d script


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

start() {

bind_directories="proc dev dev/pts dev/shm sys"

for directory in $bind_directories ; do
 mount --bind /$directory $chroot/$directory

echo "rm -rf /var/run/*.pid" | chroot $chroot
echo "/etc/init.d/cron start" | chroot $chroot
echo "/etc/init.d/sysklogd start" | chroot $chroot
echo 'su - zimbra -c "/opt/zimbra/bin/zmcontrol start"' | chroot $chroot


stop() {


echo 'su - zimbra -c "/opt/zimbra/bin/zmcontrol stop"' | chroot $chroot
echo "/etc/init.d/cron stop" | chroot $chroot
echo "/etc/init.d/sysklogd stop" | chroot $chroot

bind_directories="proc dev/pts dev/shm dev sys"

for directory in $bind_directories ; do
  umount $chroot/$directory

Your debian environment needs less than 200 MB (without zimbra) which isn’t too much overhead.

Building Zimbra from source on Gentoo

(needs to be documented)

Jump to: navigation, search