How to make a small Gentoo distro

First off, Gentoo is awesome for making small or custom linux distributions. It allows you (with emerge) to build little package tarballs and make your own image.

Now. to get started add this to your gentoo make.conf

FEATURES="buildpkg"

That will tell portage to create the tarball packages every time you emerge anything.

This next part is up for debate. The bare minimal packages in my opinion are bash, baselayout, busybox, openrc. So lets emerge them

emerge bash baselayout busybox openrc

After this is done. And it can take a while. You should have a nice directory struct in /usr/portage/packages. Look for the 4 that you just built. After you got them. create a directory to load build your minimal gentoo distro in.

mkdir -p /build/minimal

The -p just tells it to make all the parent directories too. so it will make /build and then make /build/minimal

now copy those tarballs into this path like so

cp sys-apps/baselayout-1.12.13.tbz2 /build/minimal/
cp sys-apps/busybox-1.16.0.tbz2 /build/minimal/
cp sys-apps/openrc-0.6.1-r1.tbz2 /build/minimal/
cp app-shells/bash-4.0_p37.tbz2 /build/minimal/

Untar them.

cd /build/minimal
tar -xjvf *

The next step you need to figure out what libraries bash needs to run. do this.

ldd bin/bash

Should give you something like this.

        linux-gate.so.1 =>  (0xb78b8000)
        libncurses.so.5 => /lib/libncurses.so.5 (0xb786a000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7866000)
        libc.so.6 => /lib/libc.so.6 (0xb771e000)
        /lib/ld-linux.so.2 (0xb78b9000)

Those are the libs you will need. Go ahead and copy them over.

cp /lib/libncurses.so.5 /build/minimal/lib/
cp /lib/libdl.so.2 /build/minimal/lib/
cp /lib/libc.so.6 /build/minimal/lib/
cp /lib/ld-linux.so.2 /build/minimal/lib/

And now you can chroot inside your minimal enviroment.

chroot /build/minimal/ /bin/bash --login
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s