Alpine Linux in a chroot: Difference between revisions

From Alpine Linux
m (updated)
m (updated)
Line 5: Line 5:


== Creating the installation ==
== Creating the installation ==
This example installation of Alpine Linux in a chroot will work with the lastest release. But it's also possible to make a chroot with '''[[Edge|edge]]''' or older releases of Alpine Linux to test backports.
'''Note:''' The variables below:  
'''Note:''' The variables below:  


Line 49: Line 51:
{{Cmd|echo 'nameserver 8.8.8.8' >/etc/resolv.conf}}
{{Cmd|echo 'nameserver 8.8.8.8' >/etc/resolv.conf}}


We are setting up apk mirrors:  
We are setting up APK mirrors:  


{{Cmd|sudo mkdir -p ./${build_dir}/etc/apk
{{Cmd|sudo mkdir -p ./${build_dir}/etc/apk
echo "${mirror}/v2.2/main" > ./${build_dir}/etc/apk/repositories}}
echo "${mirror}/v2.2/main" > ./${build_dir}/etc/apk/repositories}}


At this point you should be able to enter your chroot:  
== Entering your chroot ==
After the installation you should be able to enter your chroot:  


{{Cmd|sudo chroot ./${build_dir} /bin/sh -l}}
{{Cmd|sudo chroot ./${build_dir} /bin/sh -l}}

Revision as of 04:38, 8 December 2011

This document explains how to set up an Alpine build environment in a chroot under a "normal" Linux distro, such as Arch, Debian, Fedora, Gentoo, or Ubuntu. Once inside the chroot environment, you can build, debug, and run alpine packages.

Requirements

You will need a few gigabytes of free disk space to have enough space for kernel compiling and storing all the binary packages.

Creating the installation

This example installation of Alpine Linux in a chroot will work with the lastest release. But it's also possible to make a chroot with edge or older releases of Alpine Linux to test backports.

Note: The variables below:

  • ${build_dir} = You can name it whatever you like.
  • ${mirror} = Should be replaced with one of the available Alpine Linux mirrors.

Choose a mirror from the mirror list.

Let's start by getting the latest apk static package:

Tip: In the command below, replace x86_64 with x86 if running on a 32bit installation

wget http://dl-3.alpinelinux.org/alpine/v2.3/main/x86_64/apk-tools-static-2.2.1-r0.apk

Unpack the tarball

tar -xzf apk-tools-static-2.2.1-r0.apk

We are setting up a basic chroot:

mkdir ${build_dir} sudo ./sbin/apk.static -X ${mirror}/v2.2/main -U --allow-untrusted --root ${build_dir} --initdb add alpine-base alpine-sdk mkdir -p ./${build_dir}/proc sudo mount --bind /proc ./${build_dir}/proc

Lets setup our needed devices:

sudo mknod -m 666 ./${build_dir}/dev/full c 1 7 sudo mknod -m 666 ./${build_dir}/dev/ptmx c 5 2 sudo mknod -m 644 ./${build_dir}/dev/random c 1 8 sudo mknod -m 644 ./${build_dir}/dev/urandom c 1 9 sudo mknod -m 666 ./${build_dir}/dev/zero c 1 5 sudo mknod -m 666 ./${build_dir}/dev/tty c 5 0

seems as /dev/null is wrong

sudo rm -f ./${build_dir}/dev/null && sudo mknod -m 666 ./${build_dir}/dev/null c 1 3

We need a resolv.conf is needed for the DNS servers and the /root directory:

sudo cp /etc/resolv.conf ./${build_dir}/etc/ mkdir -p ./${build_dir}/root

If you don't want to copy the resolv.conf from the local machine, create this file with your DNS server entry.

echo 'nameserver 8.8.8.8' >/etc/resolv.conf

We are setting up APK mirrors:

sudo mkdir -p ./${build_dir}/etc/apk echo "${mirror}/v2.2/main" > ./${build_dir}/etc/apk/repositories

Entering your chroot

After the installation you should be able to enter your chroot:

sudo chroot ./${build_dir} /bin/sh -l

If you are using Alpine as a Native build system you will have to make sure that chroot can run chmod. Add following to /etc/sysctl.conf

kernel.grsecurity.chroot_deny_chmod = 0

Then run the following command

sysctl -p

Alpine Linux in a chroot on Fedora

If you want to generate a chroot on a Fedora based system, you can use this script.

Note: Maybe you are able to use this script on other distribution but this is not tested.