lxc-fedora.in revision 431fdc427247ab1a6189c46d0743e38f30f9e1e9
252N/A# template script for generating fedora container for LXC 252N/A# lxc: linux Container library 252N/A# Daniel Lezcano <daniel.lezcano@free.fr> 252N/A# Ramez Hanna <rhanna@informatiq.org> 252N/A# This library is free software; you can redistribute it and/or 252N/A# modify it under the terms of the GNU Lesser General Public 252N/A# License as published by the Free Software Foundation; either 252N/A# version 2.1 of the License, or (at your option) any later version. 252N/A# This library is distributed in the hope that it will be useful, 252N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 252N/A # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 252N/A# Lesser General Public License for more details. 252N/A# You should have received a copy of the GNU Lesser General Public 252N/A# License along with this library; if not, write to the Free Software 252N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 252N/A# Alow for weird remixes like the Raspberry Pi 252N/A# Use the Mitre standard CPE identifier for the release ID if possible... 252N/A# This is a shell friendly configuration file. We can just source it. 252N/A# What we're looking for in here is the ID, VERSION_ID and the CPE_NAME 252N/A if [
"${CPE_URI}" !=
"cpe:/o" ]
252N/A # Probably a better way to do this but sill remain posix 252N/A # compatible but this works, shrug... 252N/A # Must be nice and not introduce convenient bashisms here. 252N/Aif [
"${CPE_NAME}" !=
"" -a
"${ID}" =
"fedora" -a
"${VERSION_ID}" !=
"" ]
252N/A # Only if all other methods fail, try to parse the redhat-release file. # Map a few architectures to their generic Fedora repository archs. # The two ARM archs are a bit of a guesstimate for the v5 and v6 # archs. V6 should have hardware floating point (Rasberry Pi). # The "arm" arch is safer (no hardware floating point). So # there may be cases where we "get it wrong" for some v6 other # disable selinux in fedora # configure the network using the dhcp cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0 cat <<EOF > ${rootfs_path}/etc/sysconfig/network # set hostname on systemd Fedora systems cat <<EOF > $rootfs_path/etc/hosts 127.0.0.1 localhost.localdomain localhost $utsname ::1 localhost6.localdomain6 localhost6 # specifying this in the initial packages doesn't always work. echo "installing fedora-release package" # silence some needless startup errors # don't mount devpts, for pete's sake #dependency on a device unit fails it specially that we disabled udev # Actually, the After=dev-%i.device line does not appear in the # Fedora 17 or Fedora 18 systemd getty\@.service file. It may be left # over from an earlier version and it's not doing any harm. We do need # to disable the "ConditionalPathExists=/dev/tty0" line or no gettys are # started on the ttys in the container. Lets do it in an override copy of # the service so it can still pass rpm verifies and not be automatically # updated by a new systemd version. -- mhw /\/\|=mhw=|\/\/ sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \ # Setup getty service on the 4 ttys we are going to allow in the # default config. Number should match lxc.tty # check the mini fedora was not already downloaded # download a mini fedora into a cache echo "Downloading fedora minimal ..." PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig rootfiles policycoreutils fedora-release" # We're splitting the old loop into two loops plus a directory retrival. # First loop... Try and retrive a mirror list with retries and a slight # delay between attempts... # This code is mildly "brittle" in that it assumes a certain # page format and parsing HTML. I've done worse. :-P # This will fall through if we didn't get any URLS above # This code is mildly "brittle" in that it assumes a certain directory # page format and parsing HTML. I've done worse. :-P if [ $? -ne 0 -o "${RELEASE_RPM}" = "" ]; then echo "Failed to identify fedora release rpm." echo "Fetching fedora release rpm from ${RELEASE_URL}/${RELEASE_RPM}......" echo "Failed to download fedora release rpm ${RELEASE_RPM}." echo "Failed to download the rootfs, aborting." echo "Download complete." # make a local copy of the minifedora # i prefer rsync (no reason really) YUM="yum --installroot $cache/rootfs -y --nogpgcheck" echo "Cache repository is busy." echo "Checking cache download in $cache/rootfs ... " if [ ! -e "$cache/rootfs" ]; then echo "Failed to download 'fedora base'" echo "Cache found. Updating..." echo "Failed to update 'fedora base', continuing with last known good cache" echo "Failed to copy rootfs" cat <<EOF >> $config_path/config lxc.mount = $config_path/fstab lxc.cap.drop = sys_module mac_admin mac_override sys_time # When using LXC with apparmor, uncomment the next line to run unconfined: #lxc.aa_profile = unconfined lxc.cgroup.devices.deny = a lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:5 rwm lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm lxc.cgroup.devices.allow = c 4:0 rwm lxc.cgroup.devices.allow = c 4:1 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 5:2 rwm lxc.cgroup.devices.allow = c 254:0 rm cat <<EOF > $config_path/fstab proc proc proc nodev,noexec,nosuid 0 0 sysfs sys sysfs defaults 0 0 echo "Failed to add configuration" # lock, so we won't purge while someone is creating a repository echo "Cache repository is busy." echo -n "Purging the download cache for Fedora-$release..." $1 -n|--name=<container_name> [-p|--path=<path>] [-c|--clean] [-R|--release=<Fedora_release>] [--fqdn=<network name of container>] [-A|--arch=<arch of the container>] -n,--name container name, used to as an identifier for that container from now on -p,--path path to where the container will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case --rootfs path for actual rootfs. -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. --fqdn fully qualified domain name (FQDN) for DNS and system naming -A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64] -h,--help print this help if [ -z
"${utsname}" ];
then # This follows a standard "resolver" convention that an FQDN must have # at least two dots or it is considered a local relative host name. # If it doesn't, append the dns domain name of the host system. # This changes one significant behavior when running # "lxc_create -n Container_Name" without using the # utsname and hostname = Container_Name echo "Please install these using \"sudo yum install $needed_pkgs\"" echo "This is not a fedora host and release missing, defaulting to 18. use -R|--release to specify release" # Fedora 15 and above run systemd. We need autodev enabled to keep # systemd from causing problems. if [
"$(id -u)" !=
"0" ];
then echo "This script should be run as 'root'" # check for 'lxc.rootfs' passed in through default config by lxc-create echo "Interrupted, so cleaning up" # maybe was interrupted before copy config echo "failed write configuration file" echo "failed to install fedora" echo "failed to configure fedora for a container" # If the systemd configuration directory exists - set it up for what we need. # This configuration (rc.sysinit) is not inconsistent with the systemd stuff # above and may actually coexist on some upgraded systems. Let's just make # sure that, if it exists, we update this file, even if it's not used... echo "container rootfs and config created"