Mail archive
alpine-devel

[alpine-devel] Run Alpine linux in an openvz Container

From: Harry Lachanas <grharry_at_freemail.gr>
Date: Thu, 27 May 2010 10:58:56 +0300

Hi,

I've modified the setup-vs-template that creates a vsrerver template in
order to create an openvz that you can find attached to this.

My Env is openvz from Proxmox 1.5 ( based on debian lenny ) that
provides a web interface and makes some thinks a little easier when it
comes to setting up quotas for the container ( which in my opinion from
the command line is ridiculously complex from the command line ) .

These instructions hold for the above mentioned env and propably will
not work for others.

 
1st step required involves a little cheating
from ths HS env:

#cd /etc/vz/dists

#cat debian.conf | sed 's/debian/alpine/g' > alpine.conf
#cd /etc/vz/dists/scripts

#cp debian-add_up.sh alpine-add_ip.sh
#cp debian-del_ip.sh alpine-del_ip.sh
#cp debian-set_hostname.sh alpine-set_hostname.sh

That is since alpine looks and feels like debian in some ways, the
debian scripts ( should ) work in our alpine env.

from an alpine env we run the script provided.
#./setup-vz-template

that will create a tar.gz file ( if no name is provided
alpine-1.10-base-i386.tar.gz )
we move this tar.gz into
/var/lib/vz/template/cache

And we are set to go

 From the host
#vzctl create 111 --config pve.auto --hostname alpine --ipadd
192.168.1.12 --ostemplate alpine-1.10-base-i386


this will create the alpine CT.

#vzctl exec 111 /etc/init.d/devfs start

and

vzctl enter 111 should get you in the alpine CT.
done.

from the web env of the host you can setup the quotas etc ..
of your container ..

Cheers
Harry



#!/bin/sh

# create an openvz template
PROG=$0

usage() {
        echo "usage: $PROG [-fhq] [-o OUTFILE] [-X repository] [packages...]"
        exit $1
}

clean_exit() {
        rm -rf "$tmpdir"
        exit $1
}

outfile=alpine-1.10-base-i386.tar.gz
fakeroot=
repos=
while getopts "ho:qX:" opt; do
        case "$opt" in
        h) usage 0;;
        o) outfile="$OPTARG";;
        q) quiet=-q;;
        X) repos="$repos --repository $OPTARG";;
        esac
done
shift $(( $OPTIND - 1 ))

if [ "$(whoami)" != "root" ]; then
        echo "Warning: you need root permissions" >&2
fi

tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/setup-vz-template-XXXXXX)

apk add --root "$tmpdir" --initdb --keys-dir /etc/apk/keys -U \
        $quiet ${repos:---repositories-file /etc/apk/repositories} \
        alpine-base bash $@ \
        || clean_exit 1

sed -i -e 's/\/ash$/\/bash/' ${tmpdir}/etc/passwd
sed -i -e 's/^#\/bin\/bash/\/bin\/bash/' ${tmpdir}/etc/shells
sed -i -e 's/^tty[1-9]/#&/g' ${tmpdir}/etc/inittab
sed -i -e 's/^/#&/' ${tmpdir}/etc/fstab

rm -f ${tmpdir}/dev/null
mknod -m 666 ${tmpdir}/dev/null c 1 3
mknod -m 666 ${tmpdir}/dev/ptmx c 5 2
mknod -m 666 ${tmpdir}/dev/tty c 5 0
mknod -m 644 ${tmpdir}/dev/random c 1 8
mknod -m 644 ${tmpdir}/dev/urandom c 1 9
mknod -m 666 ${tmpdir}/dev/zero c 1 5
mknod -m 666 ${tmpdir}/dev/full c 1 7


tar -czf "$outfile" -C "$tmpdir" $(ls "$tmpdir") || clean_exit 1

[ -z "$quiet" ] && echo "Created $outfile"
clean_exit 0



---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Thu May 27 2010 - 10:58:56 UTC