lxc-fedora.in revision 0655a606dad52725eedd8af18a15f246627091f9
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# template script for generating fedora container for LXC
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# lxc: linux Container library
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Daniel Lezcano <daniel.lezcano@free.fr>
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Ramez Hanna <rhanna@informatiq.org>
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Michael H. Warfield <mhw@WittsEnd.com>
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# This library is free software; you can redistribute it and/or
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# modify it under the terms of the GNU Lesser General Public
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# License as published by the Free Software Foundation; either
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# version 2.1 of the License, or (at your option) any later version.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# This library is distributed in the hope that it will be useful,
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# but WITHOUT ANY WARRANTY; without even the implied warranty of
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Lesser General Public License for more details.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# You should have received a copy of the GNU Lesser General Public
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# License along with this library; if not, write to the Free Software
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk#Configurations
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkcache_base=@LOCALSTATEDIR@/cache/lxc/fedora/$arch
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# We really need something better here!
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# is this fedora?
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Alow for weird remixes like the Raspberry Pi
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Use the Mitre standard CPE identifier for the release ID if possible...
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# This may be in /etc/os-release or /etc/system-release-cpe. We
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# should be able to use EITHER. Give preference to /etc/os-release for now.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# This is a shell friendly configuration file. We can just source it.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# What we're looking for in here is the ID, VERSION_ID and the CPE_NAME
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk echo "Host CPE ID from /etc/os-release: ${CPE_NAME}"
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkif [ "${CPE_NAME}" = "" -a -e /etc/system-release-cpe ]
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk echo "Host CPE ID from /etc/system-release-cpe: ${CPE_NAME}"
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk # Probably a better way to do this but sill remain posix
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk # compatible but this works, shrug...
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk # Must be nice and not introduce convenient bashisms here.
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk ID=$(expr ${CPE_NAME} : '[^:]*:[^:]*:[^:]*:\([^:]*\)')
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk VERSION_ID=$(expr ${CPE_NAME} : '[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\)')
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkif [ "${CPE_NAME}" != "" -a "${ID}" = "fedora" -a "${VERSION_ID}" != "" ]
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk # Only if all other methods fail, try to parse the redhat-release file.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk fedora_host_ver=$( sed -e '/^Fedora /!d' -e 's/Fedora.*\srelease\s*\([0-9][0-9]*\)\s.*/\1/' < /etc/redhat-release )
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# Map a few architectures to their generic Fedora repository archs.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# The two ARM archs are a bit of a guesstimate for the v5 and v6
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# archs. V6 should have hardware floating point (Rasberry Pi).
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk# The "arm" arch is safer (no hardware floating point). So
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk# there may be cases where we "get it wrong" for some v6 other
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkBOOTPROTO=dhcp
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenkHOSTNAME=${utsname}
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkNM_CONTROLLED=no
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenkTYPE=Ethernet
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk cat <<EOF > ${rootfs_path}/etc/sysconfig/network
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkNETWORKING=yes
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenkHOSTNAME=${utsname}
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk if [ $release -gt 14 ]; then
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk127.0.0.1 localhost.localdomain localhost $utsname
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk::1 localhost6.localdomain6 localhost6
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk mknod -m 666 ${dev_path}/null c 1 3
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk mknod -m 666 ${dev_path}/zero c 1 5
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk mknod -m 666 ${dev_path}/random c 1 8
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk mknod -m 666 ${dev_path}/urandom c 1 9
mount -o bind /dev ${rootfs_path}/dev
mount -t proc proc ${rootfs_path}/proc
cp /etc/resolv.conf ${rootfs_path}/etc/
chroot ${rootfs_path} rpm --rebuilddb
umount ${rootfs_path}/dev
touch ${rootfs_path}/etc/fstab
touch ${rootfs_path}/etc/fstab
chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/udev.service
chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
if [[ ${WHITE_LISTED} != 0 ]]
for OS in ${BOOTSTRAP_WHITE_LIST}
[[ -d ${cache_base} ]] || mkdir -p ${cache_base}
cd ${cache_base}
for bootstrap in ${BOOTSTRAP_LIST}
if [[ -d ${bootstrap} ]]
cp /etc/resolv.conf ${bootstrap}/etc/
RC=$?
if [[ 0 == ${RC} ]]
cd ${TMP_BOOTSTRAP_DIR}
# We're going to use the kernel.org mirror for the initial stages...
if [[ ! -f ../LiveOS/squashfs.img ]]
Downloading stage 0 LiveOS squashfs file system from mirrors.kernel.org...
mount -o loop ../LiveOS/squashfs.img squashfs
cd stage1
cp /etc/resolv.conf etc/
chroot . yum -y --nogpgcheck --installroot /run/install install python rpm yum
cd ../bootstrap
cp /etc/resolv.conf etc/
RC=$?
if [[ ${RC} != 0 ]]
rm -rf ${TMP_BOOTSTRAP_DIR}
[[ -d ${BOOTSTRAP_DIR}/run/install ]] || mkdir -p ${BOOTSTRAP_DIR}/run/install
mount -o bind ${INSTALL_ROOT} ${BOOTSTRAP_DIR}/run/install
mount -o bind /dev ${BOOTSTRAP_DIR}/dev
mount -t proc proc ${BOOTSTRAP_DIR}/proc
cp /etc/resolv.conf ${BOOTSTRAP_DIR}/etc/
if [ $? -ne 0 ]; then
PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig rootfiles policycoreutils fedora-release"
sleep 3
for MIRROR_URL in ${MIRROR_URLS}
RELEASE_RPM=$(curl -L -f "$RELEASE_URL" | sed -e "/fedora-release-${release}-/!d" -e 's/.*<a href=\"//' -e 's/\">.*//' )
if [ $? -ne 0 ]; then
if [ $DOWNLOAD_OK != yes ]; then
mkdir -p ${INSTALL_ROOT}/var/lib/rpm
if ! fedora_get_bootstrap
${BOOTSTRAP_CHROOT}rpm --root ${BOOTSTRAP_INSTALL_ROOT} --initdb
${BOOTSTRAP_CHROOT}rpm --root ${BOOTSTRAP_INSTALL_ROOT} --nodeps -ivh ${BOOTSTRAP_INSTALL_ROOT}/${RELEASE_RPM}
${BOOTSTRAP_CHROOT}yum --installroot ${BOOTSTRAP_INSTALL_ROOT} -y --nogpgcheck install ${PKG_LIST}
RC=$?
cd ${INSTALL_ROOT}
${BOOTSTRAP_CHROOT} db_dump ${BOOTSTRAP_INSTALL_ROOT}/$db | chroot . db_load $db.new
mkdir -p @LOCALSTATEDIR@/lock/subsys/
flock -x 200
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config
if [ $? -ne 0 ]; then
if [ ! -e $cache ]; then
flock -x 200
cat <<EOF
[-p|--path=<path>] [-c|--clean] [-R|--release=<Fedora_release>] [--fqdn=<network name of container>] [-A|--arch=<arch of the container>]
-p,--path path to where the container will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case
-R,--release Fedora release for the new container. if the host is Fedora, then it will default to the host's release.
eval set -- "$options"
# utsname and hostname = Container_Name.Domain_Name
if [ -n "$needed_pkgs" ]; then
echo "Missing commands: $needed_pkgs"
echo "Please install these using \"sudo yum install $needed_pkgs\""
if [ -z "$path" ]; then
if [ -z "$release" ]; then
echo "This is not a fedora host and release missing, defaulting to 18. use -R|--release to specify release"
if [ -z "$rootfs_path" ]; then
# check for 'lxc.rootfs' passed in through default config by lxc-create
# This configuration (rc.sysinit) is not inconsistent with the systemd stuff
if [ ! -z $clean ]; then