lxc-fedora.in revision 5266cf0a640f93d3784ed3ea121de4ada1feb127
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# template script for generating fedora container for LXC
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# lxc: linux Container library
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Daniel Lezcano <daniel.lezcano@free.fr>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Ramez Hanna <rhanna@informatiq.org>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Michael H. Warfield <mhw@WittsEnd.com>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This library is free software; you can redistribute it and/or
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# modify it under the terms of the GNU Lesser General Public
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# License as published by the Free Software Foundation; either
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# version 2.1 of the License, or (at your option) any later version.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This library is distributed in the hope that it will be useful,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# but WITHOUT ANY WARRANTY; without even the implied warranty of
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Lesser General Public License for more details.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# You should have received a copy of the GNU Lesser General Public
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# License along with this library; if not, write to the Free Software
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
faefa7f8584a7d1567df2e6f1f9240a28a6466abStéphane Graber#Configurations
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumicache_base=@LOCALSTATEDIR@/cache/lxc/fedora/$arch
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# We really need something better here!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# is this fedora?
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Alow for weird remixes like the Raspberry Pi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Use the Mitre standard CPE identifier for the release ID if possible...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This may be in /etc/os-release or /etc/system-release-cpe. We
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# should be able to use EITHER. Give preference to /etc/os-release for now.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This is a shell friendly configuration file. We can just source it.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# What we're looking for in here is the ID, VERSION_ID and the CPE_NAME
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Host CPE ID from /etc/os-release: ${CPE_NAME}"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif [ "${CPE_NAME}" = "" -a -e /etc/system-release-cpe ]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi CPE_URI=$(expr ${CPE_NAME} : '\([^:]*:[^:*]\)')
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Host CPE ID from /etc/system-release-cpe: ${CPE_NAME}"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Probably a better way to do this but sill remain posix
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # compatible but this works, shrug...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Must be nice and not introduce convenient bashisms here.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ID=$(expr ${CPE_NAME} : '[^:]*:[^:]*:[^:]*:\([^:]*\)')
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi VERSION_ID=$(expr ${CPE_NAME} : '[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\)')
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif [ "${CPE_NAME}" != "" -a "${ID}" = "fedora" -a "${VERSION_ID}" != "" ]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Only if all other methods fail, try to parse the redhat-release file.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi fedora_host_ver=$( sed -e '/^Fedora /!d' -e 's/Fedora.*\srelease\s*\([0-9][0-9]*\)\s.*/\1/' < /etc/redhat-release )
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Map a few architectures to their generic Fedora repository archs.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# The two ARM archs are a bit of a guesstimate for the v5 and v6
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# archs. V6 should have hardware floating point (Rasberry Pi).
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# The "arm" arch is safer (no hardware floating point). So
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# there may be cases where we "get it wrong" for some v6 other
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Also kill it in the /etc/selinux/config file if it's there...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i '/^SELINUX=/s/.*/SELINUX=disabled/' $rootfs_path/etc/selinux/config
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Nice catch from Dwight Engen in the Oracle template.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Wantonly plagerized here with much appreciation.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ -f $rootfs_path/usr/sbin/selinuxenabled ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mv $rootfs_path/usr/sbin/selinuxenabled $rootfs_path/usr/sbin/selinuxenabled.lxcorig
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ln -s /bin/false $rootfs_path/usr/sbin/selinuxenabled
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This is a known problem and documented in RedHat bugzilla as relating
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # to a problem with auditing enabled. This prevents an error in
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # the container "Cannot make/remove an entry for the specified session"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i '/^session.*pam_loginuid.so/s/^session/# session/' ${rootfs_path}/etc/pam.d/login
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i '/^session.*pam_loginuid.so/s/^session/# session/' ${rootfs_path}/etc/pam.d/sshd
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiBOOTPROTO=dhcp
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiHOSTNAME=${utsname}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiNM_CONTROLLED=no
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi cat <<EOF > ${rootfs_path}/etc/sysconfig/network
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiNETWORKING=yes
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiHOSTNAME=${utsname}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $release -gt 14 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "${utsname}" > ${rootfs_path}/etc/hostname
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi127.0.0.1 localhost.localdomain localhost $utsname
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi::1 localhost6.localdomain6 localhost6
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # These mknod's really don't make any sense with modern releases of
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Fedora with systemd, devtmpfs, and autodev enabled. They are left
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # here for legacy reasons and older releases with upstart and sysv init.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/null c 1 3
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/zero c 1 5
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/random c 1 8
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/urandom c 1 9
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty c 5 0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty0 c 4 0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty1 c 4 1
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty2 c 4 2
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty3 c 4 3
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/tty4 c 4 4
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 600 ${dev_path}/console c 5 1
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/full c 1 7
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mknod -m 666 ${dev_path}/ptmx c 5 2
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "root:$root_password" | chroot $rootfs_path chpasswd
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # specifying this in the initial packages doesn't always work.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Rebuild the rpm database based on the target rpm version...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot ${rootfs_path} yum -y install fedora-release
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ! -e ${rootfs_path}/sbin/NetworkManager ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # NetworkManager has not been installed. Use the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # legacy chkconfig command to enable the network startup
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's/ACTIVE_CONSOLES=.*$/ACTIVE_CONSOLES="\/dev\/console \/dev\/tty[1-4]"/' \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.sysinit
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.d/rc.sysinit
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.sysinit
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot ${rootfs_path} chkconfig udev-post off
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi unlink ${rootfs_path}/etc/systemd/system/default.target
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/udev.service
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi #dependency on a device unit fails it specially that we disabled udev
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # sed -i 's/After=dev-%i.device/After=/' ${rootfs_path}/lib/systemd/system/getty\@.service
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Actually, the After=dev-%i.device line does not appear in the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Fedora 17 or Fedora 18 systemd getty\@.service file. It may be left
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # over from an earlier version and it's not doing any harm. We do need
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # to disable the "ConditionalPathExists=/dev/tty0" line or no gettys are
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # started on the ttys in the container. Lets do it in an override copy of
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # the service so it can still pass rpm verifies and not be automatically
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # updated by a new systemd version. -- mhw /\/\|=mhw=|\/\/
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi < ${rootfs_path}/lib/systemd/system/getty\@.service \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi > ${rootfs_path}/etc/systemd/system/getty\@.service
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Setup getty service on the 4 ttys we are going to allow in the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # default config. Number should match lxc.tty
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ( cd ${rootfs_path}/etc/systemd/system/getty.target.wants
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for i in 1 2 3 4 ; do ln -sf ../getty\@.service getty@tty${i}.service; done )
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi### BEGIN Bootstrap Environment Code... Michael H. Warfield /\/\|=mhw=|\/\/
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Ok... Heads up. If you're reading these comments, you're either a
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# template owner or someone wondering how the hell I did this (or, worse,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# someone in the future trying to maintain it). This code is slightly
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# "evil coding bastard" code with one significant hack / dirty trick
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# that you would probably miss just reading the code below. I'll mark
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# it out with comments.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Because of what this code does, it deserves a lot of comments so people
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# can understand WHY I did it this way...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Ultimate Objective - Build a Fedora container on a host system which does
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# not have a (complete compatible) version of rpm and/or yum. That basically
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# means damn near any distro other than Fedora and Ubuntu (which has rpm and
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# yum available). Only requirements for this function are rsync and
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# squashfs available to the kernel. If you don't have those, why are you
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# even attempting to build containers?
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Challenge for this function - Bootstrap a Fedora install bootstrap
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# run time environment which has all the pieces to run rpm and yum and
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# from which we can build targets containers even where the host system
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# has no support for rpm, yum, or fedora.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Stage 0 - Download a Fedora LiveOS squashfs core (netinst core).
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Stage 1 - Extract filesystem from Stage 0 and update to full rpm & yum
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Stage 2 - Use Stage 1 to build a rootfs with python, rpm, and yum.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Stage 2 becomes our bootstrap file system which can be cached
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# and then used to build other arbitrary vesions of Fedora of a
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# given architecture. Not that this only has to run once for
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Fedora on a given architecture since rpm and yum can build other
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# versions. We'll arbitrarily pick Fedora 19 to build this. This
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# will need to change as time goes on.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Programmers Note... A future fall back may be to download the netinst
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# iso image instead of the LiveOS squasfs image and work from that.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# That may be more general but will introduce another substep
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# (mounting the iso) to the stage0 setup.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This system is designed to be as autonomous as possible so all whitelists
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# and controlls are self-contained.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Initial testing - Whitelist nobody. Build for everybody...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Initial deployment - Whitelist Fedora.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Long term - Whitelist Fedora, Debian, Ubuntu, CentOs, Scientific, and NST.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# List of distros which do not (should not) need a bootstrap (but we will test
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# for rpm and yum none the less... OS SHOULD be taken from CPE values but
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Debian / Ubuntu doesn't support CPE yet.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# BOOTSTRAP_WHITE_LIST=""
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# BOOTSTRAP_WHITE_LIST="fedora debian ubuntu centos scientific sl nst"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We need rpm. No rpm - not possible to white list...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We need yum No yum - not possible to white list...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${WHITE_LISTED} != 0 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${ID} = ${OS} ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiOS ${ID} is whitelisted. Installation Bootstrap Environment not required.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiFedora Installation Bootstrap Build..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiUnable to locate rsync. Cravely bailing out before even attempting to build
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumian Installation Bootstrap Please install rsync and then rerun this process.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi [[ -d ${cache_base} ]] || mkdir -p ${cache_base}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We know we don't have a cache directory of this version or we
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # would have never reached this code to begin with. But we may
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # have another Fedora cache directory from which we could run...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We'll give a preference for close matches prefering higher over
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # lower - which makes for really ugly code...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Is this a "bashism" that will need cleaning up????
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi BOOTSTRAP_LIST="$(( $release + 1 ))/rootfs $(( $release - 1 ))/rootfs \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi$(( $release + 2 ))/rootfs $(( $release - 2 ))/rootfs \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi$(( $release + 3 ))/rootfs $(( $release - 3 ))/rootfs \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ -d ${bootstrap} ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiExisting Bootstrap found. Testing..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ 0 == ${RC} ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiFunctional Installation Bootstrap exists and appears to be completed.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiWill use existing Bootstrap: ${BOOTSTRAP_DIR}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiInstallation Bootstrap in ${BOOTSTRAP_DIR} exists
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumibut appears to be non-functional. Skipping... It should be removed.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi TMP_BOOTSTRAP_DIR=$( mktemp -d --tmpdir=${cache_base} bootstrap_XXXXXX )
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi### Stage 0 setup.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Download the LiveOS squashfs image
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# mount image to "squashfs"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# mount contained LiveOS to stage0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# We're going to use the kernel.org mirror for the initial stages...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# 1 - It's generally up to date and comnplete
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# 2 - It's has high bandwidth access
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# 3 - It supports rsync and wildcarding (and we need both)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# 4 - Not all the mirrors carry the LiveOS images
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ! -f ../LiveOS/squashfs.img ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiDownloading stage 0 LiveOS squashfs file system from mirrors.kernel.org...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiHave a beer or a cup of coffee. This will take a bit (~300MB).
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Right now, we are using Fedora 19 for the inial bootstrap.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We could make this the "current" Fedora rev (F > 15).
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi rsync -av mirrors.kernel.org::fedora/releases/19/Fedora/$arch/os/LiveOS .
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ 0 == $? ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiDownload of squashfs image failed.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Using cached stage 0 LiveOS squashfs file system."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mount -o loop ../LiveOS/squashfs.img squashfs
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ $? != 0 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiMount of LiveOS squashfs image failed! You mush have squashfs support
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiavailable to mount image. Unable to continue. Correct and retry
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiprocess later! LiveOS image not removed. Process may be rerun
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiwithout penalty of downloading LiveOS again. If LiveOS is corrupt,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiremove ${cache_base}/LiveOS before rerunning to redownload.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mount -o loop squashfs/LiveOS/rootfs.img stage0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ $? != 0 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiMount of LiveOS stage0 rootfs image failed! LiveOS download may be corrupt.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiRemove ${cache_base}/LiveOS to force a new download or
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumitroubleshoot cached image and then rerun process.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi### Stage 1 setup.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Copy stage0 (which is ro) to stage1 area (rw) for modification.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Unmount stage0 mounts - we're done with stage 0 at this point.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Download our rpm and yum rpm packages.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Force install of rpm and yum into stage1 image (dirty hack!)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Stage 0 complete, building Stage 1 image...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiThis will take a couple of minutes. Patience..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Creating Stage 1 r/w copy of r/o Stage 0 squashfs image from LiveOS."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Setup stage1 image with pieces to run installs...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Updating Stage 1 image with full rpm and yum packages"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Retrieve our 2 rpm packages we need to force down the throat
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # of this LiveOS image we're camped out on. This is the beginning
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # of the butt ugly hack. Look close or you may missing it...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi rsync -av mirrors.kernel.org::fedora/releases/19/Fedora/$arch/os/Packages/r/rpm-[0-9]* \
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mirrors.kernel.org::fedora/releases/19/Fedora/$arch/os/Packages/y/yum-[0-9]* .
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # The --nodeps is STUPID but F15 had a bogus dependency on RawHide?!?!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # The LiveOS image contains rpm (but not rpmdb) and yum (but not
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # yummain.py - What the hell good does yum do with no
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # yummain.py?!?! - Sigh...). It contains all the supporting
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # pieces but the rpm database has not be initialized and it
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # doesn't know all the dependences (seem to) have been met.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # So we do a "--nodeps" rpm install in the chrooted environment
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # to force the installation of the full rpm and yum packages.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # For the purists - Yes, I know the rpm database is wildly out
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # of whack now. That's why this is a butt ugly hack / dirty trick.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # But, this is just the stage1 image that we are going to discard as
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # soon as the stage2 image is built, so we don't care. All we care
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # is that the stage2 image ends up with all the pieces it need to
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # run yum and rpm and that the stage2 rpm database is coherent.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi### Stage 2 setup.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Download our Fedora Release rpm packages.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Install fedora-release into bootstrap to initialize fs and databases.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Install rpm, and yum into bootstrap image using yum
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Stage 1 creation complete. Building stage 2 Installation Bootstrap"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi rsync -av mirrors.kernel.org::fedora/releases/19/Fedora/$arch/os/Packages/f/fedora-release-19* .
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # The --nodeps is STUPID but F15 had a bogus dependency on RawHide?!?!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot . rpm --root /run/install --nodeps -ivh fedora-release-*
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi chroot . yum -y --nogpgcheck --installroot /run/install install python rpm yum
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# That's it! We should now have a viable installation BOOTSTRAP in
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# bootstrap We'll do a yum update in that to verify and then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# move it to the cache location before cleaning up.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${RC} != 0 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiBuild of Installation Bootstrap failed. Temp directory
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufuminot removed so it can be investigated.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We know have a working run time environment in rootfs...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiBuild of Installation Bootstrap complete! We now return you to your
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufuminormally scheduled template creation.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${BOOTSTRAP} -ne 1 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi [[ -d ${BOOTSTRAP_DIR}/run/install ]] || mkdir -p ${BOOTSTRAP_DIR}/run/install
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi mount -o bind ${INSTALL_ROOT} ${BOOTSTRAP_DIR}/run/install
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${BOOTSTRAP} -ne 1 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This is the code to create the initial roofs for Fedora. It may
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# require a run time environment by calling the routines above...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # check the mini fedora was not already downloaded
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to create '$INSTALL_ROOT' directory"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # These will get changed if it's decided that we need a
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # boostrap environment (can not build natively)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi PKG_LIST="yum initscripts passwd rsyslog vim-minimal openssh-server openssh-clients dhclient chkconfig rootfiles policycoreutils fedora-release"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi MIRRORLIST_URL="http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$release&arch=$arch"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${release} -lt 17 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # The reflects the move of db_dump and db_load from db4_utils to
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # libdb_utils in Fedora 17 and above and it's inclusion as a dep...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Prior to Fedora 11, we need to explicitly include it!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # We're splitting the old loop into two loops plus a directory retrival.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # First loop... Try and retrive a mirror list with retries and a slight
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for trynumber in 1 2 3 4; do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi [ $trynumber != 1 ] && echo "Trying again..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This code is mildly "brittle" in that it assumes a certain
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # page format and parsing HTML. I've done worse. :-P
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi MIRROR_URLS=$(curl -s -S -f "$MIRRORLIST_URL" | sed -e '/^http:/!d' -e '2,6!d')
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to get a mirror on try $trynumber"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This will fall through if we didn't get any URLS above
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Fetching rpm name from $RELEASE_URL..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This code is mildly "brittle" in that it assumes a certain directory
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # page format and parsing HTML. I've done worse. :-P
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi RELEASE_RPM=$(curl -L -f "$RELEASE_URL" | sed -e "/fedora-release-${release}-/!d" -e 's/.*<a href=\"//' -e 's/\">.*//' )
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 -o "${RELEASE_RPM}" = "" ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to identify fedora release rpm."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Fetching fedora release rpm from ${RELEASE_URL}/${RELEASE_RPM}......"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi curl -L -f "${RELEASE_URL}/${RELEASE_RPM}" > ${INSTALL_ROOT}/${RELEASE_RPM}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to download fedora release rpm ${RELEASE_RPM}."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $DOWNLOAD_OK != yes ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ${BOOTSTRAP_CHROOT}rpm --root ${BOOTSTRAP_INSTALL_ROOT} --initdb
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # The --nodeps is STUPID but F15 had a bogus dependency on RawHide?!?!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ${BOOTSTRAP_CHROOT}rpm --root ${BOOTSTRAP_INSTALL_ROOT} --nodeps -ivh ${BOOTSTRAP_INSTALL_ROOT}/${RELEASE_RPM}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ${BOOTSTRAP_CHROOT}yum --installroot ${BOOTSTRAP_INSTALL_ROOT} -y --nogpgcheck install ${PKG_LIST}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [[ ${BOOTSTRAP} -eq 1 ]]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Here we have a bit of a sticky problem. We MIGHT have just installed
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # this template cache using versions of yum and rpm in the bootstrap
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # chroot that use a different database version than the target version.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # That can be a very big problem. Solution is to rebuild the rpmdatabase
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # with the target database now that we are done building the cache. In the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # vast majority of cases, this is a do-not-care with no harm done if we
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # didn't do it. But it catches several corner cases with older unsupported
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # releases and it really doesn't cost us a lot of time for a one shot
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # install that will never be done again for this rev.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Thanks and appreciation to Dwight Engen and the Oracle template for the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Change to our target install directory (if we're not already
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # there) just to simplify some of the logic to follow...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Pay careful attention to the following commands! It
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # crosses TWO chroot boundaries linked by a bind mount!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # In the bootstrap case, that's the bind mount of ${INSTALL_ROOT}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # to the ${BOOTSTRAP_CHROOT}/run/install directory! This is
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # a deliberate hack across that bind mount to do a database
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # translation between two environments, neither of which may
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # be the host environment! It's ugly and hard to follow but,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # if you don't understand it, don't mess with it! The pipe
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # is in host space between the two chrooted environments!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This is also why we cd'ed into the INSTALL_ROOT directory
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # in advance of this loop, so everything is relative to the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # current working directory and congruent with the same working
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # space in both chrooted environments. The output into the new
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # db is also done in INSTALL_ROOT space but works in either host
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # space or INSTALL_ROOT space for the mv, so we don't care. It's
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # just not obvious what's happening in the db_dump and db_load
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ${BOOTSTRAP_CHROOT} db_dump ${BOOTSTRAP_INSTALL_ROOT}/$db | chroot . db_load $db.new
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # This should be redundant but we do it for completeness and
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ ${RC} -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to download the rootfs, aborting."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi #cp -a $cache/rootfs-$arch $rootfs_path || return 1
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # Always make sure /etc/resolv.conf is up to date in the target!
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Checking cache download in $cache/rootfs ... "
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Failed to update 'fedora base', continuing with last known good cache"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "Copy $cache/rootfs to $rootfs_path ... "
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.utsname = $utsname
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.pts = 1024
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.mount = $config_path/fstab
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cap.drop = sys_module mac_admin mac_override sys_time
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.autodev = $auto_dev
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# When using LXC with apparmor, uncomment the next line to run unconfined:
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi#lxc.aa_profile = unconfined
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.deny = a
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# /dev/null and zero
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 1:3 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 1:5 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 5:1 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 5:0 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# /dev/{,u}random
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 1:9 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 1:8 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 136:* rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 5:2 rwm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilxc.cgroup.devices.allow = c 254:0 rm
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiproc proc proc nodev,noexec,nosuid 0 0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumisysfs sys sysfs defaults 0 0
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? -ne 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ ! -e $cache ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # lock, so we won't purge while someone is creating a repository
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ $? != 0 ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo -n "Purging the download cache for Fedora-$release..."
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi $1 -n|--name=<container_name>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi [-p|--path=<path>] [-c|--clean] [-R|--release=<Fedora_release>] [--fqdn=<network name of container>] [-A|--arch=<arch of the container>]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiMandatory args:
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi -n,--name container name, used to as an identifier for that container from now on
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiOptional args:
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi -p,--path path to where the container will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi --rootfs path for actual rootfs.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi -c,--clean clean the cache
-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