Metro Quick Start Tutorial

From Funtoo Linux
Revision as of 18:39, 8 February 2011 by Ferdy (Talk)

Jump to: navigation, search

Metro is the build system for Funtoo stages. It automates the bootstrapping process. This tutorial will take you through setting up and running Metro.

Contents

Installing

I now recommend always installing metro using git. First ensure that git is installed on your system. Next, clone the master git repository as follows:

# install -d /root/git
# cd /root/git
# git clone https://github.com/funtoo/metro.git

You will now have a directory called /root/git/metro that contains all the Metro source code. Next, install as follows:

# ln -s /root/git/metro/metro /usr/bin/metro
# ln -s /root/git/metro /usr/lib/metro

If you want to enable support for pbzip2, which is a parallel bzip2 implementation that offer some good performance improvements on multi-core processors, you can install it as follows (on a Gentoo/Funtoo system):

# emerge pbzip2

Installation complete!

Configuration

/usr/lib/metro/etc/metro.conf is Metro's master configuration file. The [path/mirror] section defines where Metro will look for things it needs and also dump things it creates. As initially configured, Metro is set up to build Funtoo and Gentoo stage tarballs and place them in the /home/mirror/linux directory:

# Mirror Paths - where to find required files and where to put created files

[section path/mirror]

: /home/mirror/linux
[collect /etc/metro/fslayouts/funtoo.conf]

If you want to change the location of your mirror on disk, then edit the /home/mirror/linux line (which defines the path/mirror variable) to point to another directory. For the purpose of the following steps, set an environment variable: export METRO_MIRROR=/home/mirror/linux. Of course, set the environment variable to whatever location you used in the configuration file.

Metro First Steps

Daniel Robbins maintains Metro, so it comes pre-configured to successfully build both Gentoo and Funtoo releases. The best way to get started with Metro is to mimic the steps used to build a new release of Gentoo or Funtoo. After this is working well for you, you can start looking at customizing, tweaking, and extending things.

Seeds and Build Isolation

At this point, you may be wondering how Metro creates its first stage tarball. As you may have guessed, 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 or Funtoo, so it's the recommended approach.

Let's quickly review how this might work. Say you wanted to build a new pentium4 stage3 tarball. The recommended method of doing this would be to grab an existing generic x86 stage3 tarball to use as your seed stage. We would configure Metro to use this generic x86 stage3 to build a new stage1 for the Pentium 4. For this process, the generic x86 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 Pentium 4 stage2. And the new Pentium 4 stage2 would serve as the build environment for creating the new Pentium 4 stage3.

A week later, you may want to build a brand new Pentium 4 stage3 tarball. Rather than starting from the original x86 stage3 again, you'd probably configure Metro to use the most-recently-built Pentium 4 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.

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.

Trying a Real 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 is proper location in /home/mirror/linux, so that Metro can find it. We will also need to create some special "control" files in /home/mirror/linux, which will allow Metro to understand how it is supposed to proceed.

Step 1: Set up x86 repository

Assuming we're following the basic steps outlined in the previous section, and building an unstable funtoo (funtoo-curent) build for the Intel Pentium 4, using a generic x86 stage3 as a seed stage, then here the first set of steps we'd perform:

# install -d "${METRO_MIRROR}/funtoo-current/x86"
# cd "${METRO_MIRROR}/funtoo-current/x86"
# install -d funtoo-current-x86-2009.06.22
# cd funtoo-current-x86-2009.06.22
# wget http://www.funtoo.org/linux/funtoo-current/x86/funtoo-current-x86-2009.06.22/stage3-x86-2009.06.22.tar.bz2
# cd ..
# install -d .control/version
# echo "2009.06.22" > .control/version/stage3
# install -d .control/strategy
# echo "local" > .control/strategy/build
# echo "stage3" > .control/strategy/seed

OK, let's review the steps above. First, we create the directory "${METRO_MIRROR}/funtoo-current/x86", which is where Metro will expect to find unstable funtoo-current x86 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 funtoo.org. Note that the 2009.06.22 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 "${METRO_MIRROR}/funtoo-current/x86" 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 x86 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 x86 funtoo-current stages. With a build strategy of local, Metro will source its seed stage from funtoo-current x86, 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: Set up Pentium 4 Repository

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

# /usr/lib/metro/scripts/ezbuild.sh funtoo-current x86

But, in this example, we're doing something a bit more complex -- using this x86 funtoo-current stage3 to seed a new pentium4 funtoo-current build. To get that done, we need to set up the pentium4 build directory as follows:

# cd "${METRO_MIRROR}/funtoo-current"
# install -d pentium4
# cd pentium4
# install -d .control/strategy
# echo "remote" > .control/strategy/build
# echo "stage3" > .control/strategy/seed
# install -d .control/remote
# echo "funtoo-current" > .control/remote/build
# echo "x86" > .control/remote/subarch

The steps we follow are similar to those we performed for the x86 directory. However, note the differences. We didn't download a stage, because we are going to use the x86 stage to build a new pentium4 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 "${METRO_MIRROR}/home/mirror/linux/funtoo-current/x86" 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 2009.06.22, as recorded in "${METRO_MIRROR}/funtoo-current/x86/.control/version/stage3". Now you can see how all those control files come together to direct Metro to do the right thing.

At this point, you could start building your new pentium4 stage1/2/3 (plus openvz and vserver templates) by typing the following:

# /usr/lib/metro/scripts/ezbuild.sh funtoo-current pentium4

After each stage is created, it will be placed in the "${METRO_MIRROR}/funtoo-current/pentium4/funtoo-current-pentium4-YYYY.MM.DD" subdirectory, where YYYY.MM.DD is today's date at the time the ezbuild.sh script was started.

Step 3: The Next Build

At this point, you now have a new pentium4 stage3. If you'd like, you can reconfigure Metro to use the most recently-built pentium4 stage3 as a seed for any new pentium4 builds. To do this, simply type:

# echo "local" > /home/mirror/linux/~funtoo/pentium4/.control/strategy/build

Now, Metro will use the most recent pentium4 stage3 as a seed. The .control/remote files you created will be ignored by Metro, since it's no longer going to perform a remote build.

Personal tools
Namespaces

Variants
Actions
Categories
Toolbox
Stuff