From Funtoo
Revision as of 03:18, August 23, 2018 by Oleg (talk | contribs)
Jump to navigation Jump to search
Other languages:
English • ‎Türkçe • ‎português do Brasil • ‎日本語

{{#layout:doc}}Metro is the build system for Funtoo Linux and Gentoo Linux stages. It automates the bootstrapping process.

This tutorial will take you through installing, setting up and running Metro.

Other Metro Documentation is available.



If you are unfamiliar with how metro works it is recommended that you continue reading this section so you can become familiar with it. If you are already familiar with it, you may wish to use the new autosetup script which uses a curses based menu and allows for quickly setting up and running builds base on your choices without requiring any manual steps. Please see the Metro AutoSetup page for more details

How Metro Works

Metro is the Funtoo Linux automated build system, and is used to build Funtoo Linux stage tarballs.

Metro cannot create a stage tarball out of thin air. To build a new stage tarball, Metro must use an existing, older stage tarball called a "seed" stage. This seed stage typically is used as the build environment for creating the stage we want.

Metro can use two kinds of seed stages. Traditionally, Metro has used a stage3 as a seed stage. This stage3 is then used to build a new stage1, which in turn is used to build a new stage2, and then a new stage3. This is generally the most reliable way to build Gentoo Linux or Funtoo Linux, so it's the recommended approach.

Seeds and Build Isolation

Another important concept to mention here is something called build isolation. Because Metro creates an isolated build environment, and the build environment is explicitly defined using existing, tangible entities -- a seed stage and a portage snapshot -- you will get consistent, repeatable results. In other words, the same seed stage, portage snapshot and build instructions will generate an essentially identical result, even if you perform the build a month later on someone else's workstation.

Local Build

Say you wanted to build a new pentium4 stage3 tarball. The recommended method of doing this would be to grab an existing pentium4 stage3 tarball to use as your seed stage. Metro will be told to use this existing pentium4 stage3 to build a new stage1 for the same pentium4. For this process, the generic pentium4 stage3 would provide the build environment for creating our new stage1. Then, the new stage1 would serve as the build environment for creating the new pentium4 stage2. And the new pentium4 stage2 would serve as the build environment for creating the new pentium4 stage3.

In the Metro terminology this is called a local build, which means a stage3 of a given architecture is used to seed a brand new build of the same architecture. Incidentally this will be the first exercise we are going to perform in this tutorial.

A week later, you may want to build a brand new pentium4 stage3 tarball. Rather than starting from the original pentium4 stage3 again, you'd probably configure Metro to use the most-recently-built pentium4 stage3 as the seed. Metro has built-in functionality to make this easy, allowing it to easily find and track the most recent stage3 seed available.

Remote Build

Metro can also perform remote build, where a stage3 of a different, but binary compatible, architecture is used as a seed to build a different architecture stage3. Consequentiality the second exercise we are going to perform in this tutorial will be to build a core2 32bit stage3 tarball from the pentium4 stage3 tarball we have just built.

TODO: add caveats about what archs can be seeded and what can be not (maybe a table?)

Tailored Build

Last, it's also worthy noting that both in local and remote builds, Metro can be configured to add and/or remove individual packages to the final tarball. Let's say you can't live without app-misc/screen, at the end of this tutorial, we will show how to have your tailored stage3 to include it.

Installing Metro

The recommended and supported method is to use the Git repository of Metro.

Ensure that dev-vcs/git, No results and No results (optional; required for EC2 support) are installed on your system.

root # emerge dev-vcs/git dev-python/requests dev-python/boto 

Next, clone the master git repository as follows:

root # cd /root
root # git clone git://
root # cp /root/metro/metro.conf ~/.metro

You will now have a directory called /root/metro that contains all the Metro source code.

Metro is now installed. It's time to customize it for your local system.

Configuring Metro


Metro is not currently able to build Gentoo stages. See FL-901.

Daniel Robbins maintains Metro, so it comes pre-configured to successfully build Funtoo Linux releases. Before reading further, you might want to customize some basic settings like the number of concurrent jobs to fit your hardware's capabilities or the directory to use for produced stage archives. This is accomplished by editing ~/.metro which is the Metro's master configuration file.

Please note that path/install must point to where metro was installed. Point path/distfiles to where your distfiles reside. Also set path/mirror/owner and path/mirror/group to the owner and group of all the files that will be written to the build repository directory, which by default (as per the configuration file) is at /home/mirror/funtoo. The cache directory normally resides inside the temp directory -- this can be modified as desired. The cache directory can end up holding many cached .tbz2 packages, and eat up a lot of storage. You may want to place the temp directory on faster storage, for faster compile times, and place the cache directory on slower, but more plentiful storage.

   .metro - Metro configuration
# Main metro configuration file - these settings need to be tailored to your install:

[section path]
install: /root/metro
tmp: /var/tmp/metro
cache: $[path/tmp]/cache
distfiles: /var/src/distfiles
work: $[path/tmp]/work/$[target/build]/$[target/name]

[section path/mirror]

: /home/mirror/funtoo
owner: root
group: repomgr
dirmode: 775

[section portage]


[section emerge]

options: --jobs=4 --load-average=4 --keep-going=n

# This line should not be modified:
[collect $[path/install]/etc/master.conf]

Arch and Subarch

In the following example we are creating a pentium4 stage 3 compiled for x86-32bit binary compatibility. Pentium4 is a subarch of the x86-32bit architecture. Once you have metro installed you may find a full list of each subarch in your /var/git/meta-repo/kits/core-kit/profiles/funtoo-1.0/linux-gnu/arch/x86-32bit/subarch directory: Example:

root # ls /var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-32bit/subarch/
amd64-k8+sse3_32  athlon-4      athlon-xp  core2_32    i486  k6-2       pentium      pentium2  pentiumpro
amd64-k8_32       athlon-mp     atom_32    generic_32  i686  k6-3       pentium-m    pentium3  prescott
athlon            athlon-tbird  btver1     geode       k6    native_32  pentium-mmx  pentium4  xen-pentium4+sse3

64-bit PC profiles can be found in the /var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-64bit/subarch/ directory:

root # ls /var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-64bit/subarch/
amd64-bulldozer  amd64-k8+sse3      btver1_64   generic_64         intel64-nehalem      native_64
amd64-jaguar     amd64-piledriver   core-avx-i  intel64-broadwell  intel64-sandybridge  nocona
amd64-k10        amd64-steamroller  core2_64    intel64-haswell    intel64-silvermont   opteron_64
amd64-k8         atom_64            corei7      intel64-ivybridge  intel64-westmere     xen-pentium4+sse3_64

First stages build (local build)

To get this all started, we need to bootstrap the process by downloading an initial seed stage3 to use for building and place it in its proper location in /home/mirror/funtoo, so that Metro can find it. We will also need to create some special "control" files in /home/mirror/funtoo, which will allow Metro to understand how it is supposed to proceed.

Step 1: Set up pentium4 repository (local build)

Assuming we're following the basic steps outlined in the previous section, and building funtoo-current build for the pentium4, using a generic pentium4 stage3 as a seed stage, then here the first set of steps we'd perform:

root # install -d /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4
root # install -d /home/mirror/funtoo/funtoo-current/snapshots
root # cd /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4
root # install -d 2017-10-01
root # cd 2017-10-01
root # wget -c
root # cd ..
root # install -d .control/version
root # echo "2017-10-01" > .control/version/stage3
root # install -d .control/strategy
root # echo local >  .control/strategy/build
root # echo stage3 > .control/strategy/seed

OK, let's review the steps above. First, we create the directory /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4, which is where Metro will expect to find funtoo-current pentium4 builds -- it is configured to look here by default. Then we create a specially-named directory to house our seed x86 stage3. Again, by default, Metro expects the directory to be named this way. We enter this directory, and download our seed x86 stage3 from Note that the 2017-10-01 version stamp matches. Make sure that your directory name matches the stage3 name too. Everything has been set up to match Metro's default filesystem layout.

Next, we go back to the /home/mirror/metro/funtoo-current/x86-32bit/pentium4 directory, and inside it, we create a .control directory. This directory and its subdirectories contain special files that Metro references to determine certain aspects of its behavior. The .control/version/stage3 file is used by Metro to track the most recently-built stage3 for this particular build and subarch. Metro will automatically update this file with a new version stamp after it successfully builds a new stage3. But because Metro didn't actually build this stage3, we need to set up the .control/version/stage3 file manually. This will allow Metro to find our downloaded stage3 when we set up our pentium4 build to use it as a seed. Also note that Metro will create a similar .control/version/stage1 file after it successfully builds an pentium4 funtoo-current stage1.

We also set up .control/strategy/build and .control/strategy/seed files with values of local and stage3 respectively. These files define the building strategy Metro will use when we build pentium4 funtoo-current stages. With a build strategy of local, Metro will source its seed stage from funtoo-current pentium4, the current directory. And with a seed strategy of stage3, Metro will use a stage3 as a seed, and use this seed to build a new stage1, stage2 and stage3.

Step 2: Building the pentium4 stages

Incidentally, if all you wanted to do at this point was to build a new pentium4 funtoo-current stage1/2/3 (plus openvz and vserver templates). You would begin the process by typing:

root # cd /root/metro
root # scripts/ funtoo-current x86-32bit pentium4

If you have a slow machine, it could take several hours to be completed because several "heavy" components like gcc or glibc have to be recompiled in each stage. Once a stage has been successfully completed, it is placed in the "${METRO_MIRROR}/funtoo-current/x32-bit/pentium4/YYYY-MM-DD" subdirectory, where YYYY-MM-DD is today's date at the time the script was started or the date you put on the command line.

Building for another binary compatible architecture (remote build)

As written above, Metro is able to perform remote build building different architecture stage3 from a binary compatible seeding stage3 (e.g. using a pentium4 stage3 to seed a Intel Core2 32bits stage3).

In the Metro terminology this is called a remote build (a stage 3 of a different, but binary compatible, architecture is used as a seed). What's not compatible? You can't use a Sparc architecture to generate an x86 or ARM based stage and vice-versa. If you use a 32bit stage then you don't want to seed a 64bit build from it. Be sure that you are using a stage from the same architecture that you are trying to seed. Check Funtoo-current FTP Mirror for a stage that is from the same Architecture that you will be building.


Often, one build (ie. funtoo-current) can be used as a seed for another build such as funtoo-stable. However, hardened builds require hardened stages as seeds in order for the build to complete successfully.

Step 1: Set up Core_2 32bit repository

In this example, we're going to use this pentium4 funtoo-current stage3 to seed a new Core_2 32bit funtoo-current build. To get that done, we need to set up the pentium4 build directory as follows:

root #  cd /home/mirror/funtoo/funtoo-current/x86-32bit
root # install -d core2_32
root # cd core2_32
root # install -d .control/strategy
root # echo remote > .control/strategy/build
root # echo stage3 > .control/strategy/seed
root # install -d .control/remote
root # echo funtoo-current > .control/remote/build
root # echo x86-32bit > .control/remote/arch_desc
root # echo pentium4 > .control/remote/subarch

The steps we follow are similar to those we performed for a local build to set up our pentium4 directory for local build. However, note the differences. We didn't download a stage, because we are going to use the pentium4 stage to build a new Core_2 32bit stage. We also didn't create the .control/version/stage{1,3} files because Metro will create them for us after it successfully builds a new stage1 and stage3. We are still using a stage3 seed strategy, but we've set the build strategy to remote, which means that we're going to use a seed stage that's not from this particular subdirectory. Where are we going to get it from? The .control/remote directory contains this information, and lets Metro know that it should look for its seed stage3 in the /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4 directory. Which one will it grab? You guessed it -- the most recently built stage3 (since our seed strategy was set to stage3) that has the version stamp of 2010-12-24, as recorded in /home/mirror/funtoo-current/x86-32bit/pentium4/.control/version/stage. Now you can see how all those control files come together to direct Metro to do the right thing.


arch_desc should be set to one of: x86-32bit, x86-64bit or pure64 for PC-compatible systems. You must use a 32-bit build as a seed for other 32-bit builds, and a 64-bit build as a seed for other 64-bit builds.

Step 2: Building the Core_2 32bit stages

Now, you could start building your new Core_2 32bit stage1/2/3 (plus openvz and vserver templates) by typing the following:

root # /root/metro/scripts/ funtoo-current x86-32bit core2_32

In that case, the produced stages are placed in the /home/mirror/funtoo/funtoo-current/x32-bit/core2_32/YYYY-MM-DD subdirectory.

Step 3: The Next Build

At this point, you now have a new Core_2 32bit stage3, built using a "remote" pentium4 stage3. Once the first remote build completes successfully, metro will automatically change .control/strategy/build to be local instead of remote, so it will use the most recently-built Core_2 32bit stage3 as a seed for any new Core_2 32bit builds from now on.

Build your own tailored stage3

Metro can be easily configured for building custom stage3 by including additional packages. You can find following directory /etc/builds/packages in your copy of metro repository and a corresponding arch configuration files inside:

[section emerge]

packages: [

Notice a debian-sources ebuild is added for all 64-bit stages. Modify the file to include (or exclude in case Funtoo add additional) packages of your choice. They will be included in your custom stage3 portage's world file.

Building Gentoo stages

Metro can also build Gentoo stages. After switching to Funtoo profile, see metro require additional steps for this. We have an open bug for this -- it is simply due to the fact that we focus on ensuring Funtoo Linux builds and building Gentoo is a lower priority. Historical note: Funtoo Linux originally started as a fork of Gentoo Linux so that metro could reliably build Gentoo stages.

Advanced Features

Metro also includes a number of advanced features that can be used to automate builds and set up distributed build servers. These features require you to emerge sqlalchemy, as SQLite is used as a dependency and also emerge dev-python/lxml as this is needed for index file generation.

Repository Management

Metro includes a script in the scripts directory called buildrepo. Buildrepo serves as the heart of Metro's advanced repository management features.

Initial Setup

To use buildrepo, you will first need to create a .buildbot configuration file. Here is the file I use on my AMD Jaguar build server:

   /root/.buildbot (python source code)
builds = (

arches = (

subarches = (

def map_build(build, subarch, full, full_date):
	# arguments refer to last build...
	if full == True:
		buildtype =  ( "freshen", )
		buildtype =  ("full", )
        # return value can be a string like "full+openvz" or a sequence type like [ "freshen", "openvz" ]
	return buildtype

This file is actually a python source file that defines the tuples builds, arches and subarches. These variables tell buildrepo which builds, arches and subarches it should manage. A map_build() function is also defined which buildbot uses to determine what kind of build to perform. The arguments passed to the function are based on the last successful build. The function can read these arguments and return a string to define the type of the next build. In the above example, the map_build() function will cause the next build after a freshen build to be a full build, and the next build after a full build to be a freshen build, so that the build will alternate between full and freshen.

Automated Builds

Once the .buildbot file has been created, the buildrepo and tools are ready to use. Here's how they work. These tools are designed to keep your repository (path/mirror in /root/.metro up-to-date by inspecting your repository and looking for stages that are out-of-date.

To list the next build that will be performed, do this -- this is from my ARM build server:

root # ./buildrepo nextbuild

If no output is displayed, then all your builds are up-to-date.

To actually run the next build, run

root # ./

If you're thinking that would be a good candidate for a cron job, you've got the right idea!

List Builds

To get a quick look at our repository, let's run the buildrepo fails command:

root # ./buildrepo fails
   0   2015-02-18 /home/mirror/funtoo/funtoo-current/x86-64bit/amd64-jaguar
   0   2015-02-18 /home/mirror/funtoo/funtoo-current/pure64/amd64-jaguar-pure64
   0   2015-02-18 /home/mirror/funtoo/funtoo-current-hardened/x86-64bit/amd64-jaguar
   0   2015-02-18 /home/mirror/funtoo/funtoo-current-hardened/pure64/amd64-jaguar-pure64

On my AMD Jaguar build server, on Feb 20, 2015, this lists all the builds that buildrepo has been configured to manage. The first number on each line is a failcount, which is the number of consecutive times that the build has failed. A zero value indicates that everything's okay. The failcount is an important feature of the advanced repository management features. Here are a number of behaviors that are implemented based on failcount:

  • If tries to build a stage and the build fails, the failcount is incremented.
  • If the build succeeds for a particular build, the failcount is reset to zero.
  • Builds with the lowest failcount are prioritized by Template:Buildrepo to build next, to steer towards builds that are more likely to complete successfully.
  • Once the failcount reaches 3 for a particular build, it is removed from the build rotation.

Resetting Failcount

If a build has issues, the failcount for a build will reach 3, at which point it will be pulled out of build rotation. To clear failcount, so that these builds are attempted again -- possibly fixed by new updates to the Portage tree -- use buildrepo zap:

root # /root/metro/scripts/buildrepo zap
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv7a_hardfp/.control/.failcount...
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv6j_hardfp/.control/.failcount...
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv5te/.control/.failcount...

Repository Maintenance

A couple of repository maintenance tools are provided:

  • buildrepo digestgen will generate hash files for the archives in your repository, and clean up stale hashes.
  • buildrepo index.xml will create an index.xml file at the root of your repository, listing all builds available.
  • buildrepo clean will output a shell script that will remove old stages. No more than the three most recent stage builds for each build/arch/subarch are kept.

Distributed Repositories

In many situation, you will have a number of build servers, and each will build a subset of your master repository, and then upload builds to the master repository. This is an area of Metro that is being actively developed. For now, automated upload functionality is not enabled, but is expected to be implemented in the relatively near future. However, it is possible to have your master repository differentiate between subarches that are built locally, and thus should be part of that system's buildbot build rotation, and those that are stored locally and built remotely. These builds should be cleaned when buildrepo clean is run, but should not enter the local build rotation. To set this up, modify /root/.buildbot and use the subarches and all_subarches variables:

   /root/.buildbot - Excerpt of .buildbot config for master repository
# subarches we are building locally:

subarches = ( 
# Things we need to clean, even if we may not be building:
all_subarches = subarches + (

Using binary cache

Metro has built-in feature which allows to use binary packages cache rather then building same list of packages from sources. For example, core packages, such as @system are updated at slower pace and it makes sense to enable binary cache to make stage building blazing fast. However, the real disadvantage with using binary cache could be a core package update that due to internal ABI changes require rebuilding of numerous packages from sources. Good example is sys-libs/ncurses-5 to sys-libs/ncurses-6 major update. This is the case when you would need to disable binary cache and use regular ebuild installation from sources. To enable binary cache edit, in your metro git repository copy,

   /etc/builds/common.conf - Excerpt of default common.conf
[section metro]

target: gentoo

and set cache/package

   /etc/builds/common.conf - Excerpt of common.conf with binary cache enabled
[section metro]

options/stage: cache/package
target: gentoo

During stage build metro will save package cache in /var/tmp/metro/cache/package-cache. With any next builds this binary package cache will be used.