lxc-plamo.in revision a1e4c206d5373b8ecd7906bff37f2601d65f022c
0N/A# template script for generating Plamo Linux container for LXC 0N/A# lxc: linux Container library 0N/A# KATOH Yasufumi <karma@jazz.email.ne.jp> 0N/A# TAMUKI Shoichi <tamuki@linet.gr.jp> 0N/A# This library is free software; you can redistribute it and/or 0N/A# modify it under the terms of the GNU Lesser General Public 0N/A# License as published by the Free Software Foundation; either 0N/A# version 2.1 of the License, or (at your option) any later version. 0N/A# This library is distributed in the hope that it will be useful, 0N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 1164N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1186N/A# Lesser General Public License for more details. 1186N/A# You should have received a copy of the GNU Lesser General Public 1186N/A# License along with this library; if not, write to the Free Software 1186N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1281N/A coreutils cracklib dcron devs dhcp dialog dosfstools dump e2fsprogs 1281N/A ed eject etc extipl file findutils gawk glibc grep groff grub gzip 1281N/A hdsetup hibernate_script iproute2 iputils kbd kmod less libcap 1281N/A libgcc libtirpc lilo linux_pam logrotate lvm2 man 1281N/A mdadm microcode_ctl mlocate ncurses net_tools netkit_combo 1281N/A network_configs nvi openbsd_inetd openssh openssl os_prober pciutils 1281N/A pm_utils procinfo_ng procps_ng readline reiserfsprogs rsyslog sed 1281N/A shadow sudo sysfsutils syslinux sysvinit tar tcp_wrappers tcsh 1281N/A timezone traceroute udev unicon_tools util_linux xz zlib"}
1281N/A cpufrequtils fortune_mod gc gdbm gpm hddtemp hdparm keyutils libelf 1281N/A libieee1284 libusb libusb_compat libxml2 libzip linux_howto lm_sensors 1281N/A lshw lsof lv man_pages man_pages_ja nilfs_utils nkf pcre perl popt 1281N/A psmisc python recode rpm2targz ruby screen sg3_utils sharutils sqlite 1281N/A squashfs_lzma sysstat texinfo time tree unzip usbutils utempter which 1281N/APACKAGES[
4]=
"autoconf automake binutils bison cloog cvs diffutils flex 207N/A g++ gcc gdb gettext gmp indent intltool kernel_headers libc libtool 1281N/A m4 make mpc mpfr onig patch pkg_config ppl pth slang strace yasm" 1281N/APACKAGES[
5]=
"gnupg gnutls gpgme libassuan libgcrypt libgpg_error libksba 1281N/APACKAGES[
6]=
"bind bridge_utils curl cyrus_sasl dnsmasq ethtool fetchmail 1281N/A heimdal hostapd iptables iw libidn libiec61883 libnl3 libpcap 1281N/A libraw1394 libssh2 mailx metamail ncftp ntrack parprouted postfix 1281N/A ppp procmail rsync setserial uml_utilities w3m wget wireless_tools 1281N/A # check the mini plamo was not already downloaded 1281N/A # download a mini plamo into a cache 0N/A mget $MIRRORPATH/Plamo-$release/$arch/plamo/${CATEGORY[$i]}/$p-*.t?z 1186N/A echo "close" >> /tmp/getpkg 1186N/A if ! lftp -f /tmp/getpkg ; then 1281N/A echo "Failed to download the rootfs, aborting." 1281N/A # make a local copy of the mini plamo 1281N/A echo "Copying $rtcache to $rootfs..." 1281N/A find $rtcache -mindepth 1 -maxdepth 1 -exec cp -a {} $rootfs \; || return 1 1281N/A mkdir -p @LOCALSTATEDIR@/lock/subsys 1281N/A echo "Cache repository is busy." 1186N/A echo "Checking cache download in $dlcache..." 99N/A if [ ! -d $dlcache ] ; then 1281N/A echo "Failed to download plamo $release base packages." 1281N/A if [ ! -x /sbin/installpkg ] ; then 1281N/A echo "'installpkg' command is missing." 1281N/A echo "Installing 'installpkg' command into $dlcache/sbin..." 1281N/A ( cd $dlcache ; tar xpJf hdsetup-*.txz ; rm -rf tmp usr var ) 1281N/A sed -i "/ldconfig/!s@/sbin@$dlcache&@g" $dlcache/sbin/installpkg* 1281N/A echo "Installing packages to $rtcache..." 1281N/A if [ ! -d $rtcache ] ; then 1281N/A for i in `seq 0 $((${#CATEGORY[@]} - 1))` ; do 1281N/A for p in ${PACKAGES[$i]} ; do 1281N/A installpkg -root $rtcache -priority ADD $dlcache/$p-*.t?z 1281N/A echo "Copy $rtcache to $rootfs..." 1281N/A echo "Failed to copy rootfs." 1281N/A ) 200> @LOCALSTATEDIR@/lock/subsys/lxc 1281N/A mknod -m 666 $rootfs/dev/zero c 1 5 1281N/A chmod 666 $rootfs/dev/random 1281N/A mknod -m 666 $rootfs/dev/urandom c 1 9 1281N/A mkdir -m 755 $rootfs/dev/pts 1281N/A chmod 600 $rootfs/dev/console 1281N/A mknod -m 666 $rootfs/dev/tty0 c 4 0 1281N/A mknod -m 666 $rootfs/dev/tty1 c 4 1 1281N/A mknod -m 666 $rootfs/dev/tty2 c 4 2 1281N/A mknod -m 666 $rootfs/dev/tty3 c 4 3 1281N/A mknod -m 666 $rootfs/dev/tty4 c 4 4 1281N/A mknod -m 666 $rootfs/dev/full c 1 7 1281N/A mknod -m 600 $rootfs/dev/initctl p 1281N/A mknod -m 666 $rootfs/dev/ptmx c 5 2 1281N/A # suppress log level output for udev 1281N/A sed -i 's/="err"/=0/' $rootfs/etc/udev/udev.conf 1281N/A cat <<- "EOF" > $rootfs/etc/fstab 1281N/A none /proc proc defaults 0 0 1281N/A none /sys sysfs defaults 0 0 1281N/A none /dev tmpfs defaults 0 0 1281N/A none /tmp tmpfs defaults 0 0 1281N/A none /dev/pts devpts gid=5,mode=620 0 0 1281N/A none /proc/bus/usb usbfs noauto 0 0 1281N/A none /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0 1281N/A cat <<- "EOF" | patch $rootfs/etc/inittab 1281N/A > 1:1235:respawn:/sbin/agetty 38400 console 1281N/A < c5:1235:respawn:/sbin/agetty 38400 tty5 linux 1281N/A < c6:12345:respawn:/sbin/agetty 38400 tty6 linux 1281N/A echo "$name" > $rootfs/etc/HOSTNAME 1281N/A echo "127.0.0.1 localhost $name" > $rootfs/etc/hosts 1281N/A # configure the network using the dhcp 1281N/A echo "DHCP" > $rootfs/var/run/inet1-scheme 1281N/A ln -s ../usr/share/zoneinfo/Asia/Tokyo $rootfs/etc/localtime 1281N/A # disable pam_loginuid.so in /etc/pam.d/login (for libvirt's lxc driver) 1281N/A sed -i '/pam_loginuid/s/^/#/' $rootfs/etc/pam.d/login 1281N/A cp $rootfs/etc/ld.so.conf.new $rootfs/etc/ld.so.conf 1281N/A echo "Setting root password to 'root'..." 1281N/A echo "root:root" | chroot $rootfs chpasswd 1281N/A echo "Please change root password!" 1281N/A ed - $rootfs/etc/rc.d/rc.S <<- "EOF" 1281N/A ed - $rootfs/etc/rc.d/rc.M <<- "EOF" 1281N/A # /etc/rc.d/rc.inet1.tradnet 1281N/A head -n-93 $rootfs/sbin/netconfig.tradnet > /tmp/netconfig.rconly 1281N/A cat <<- EOF >> /tmp/netconfig.rconly 1281N/A RC=$rootfs/etc/rc.d/rc.inet1.tradnet 1186N/A INET1SCHEME=var/run/inet1-scheme rm -f $rootfs/etc/rc.d/rc.inet1.tradnet rm -f /tmp/netconfig.rconly if ! cat <<- EOF >> $path/config ; then lxc.mount.auto = proc sys cgroup lxc.cap.drop = sys_module mac_admin mac_override sys_time 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:0 rwm lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 5:2 rwm lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 254:0 rm lxc.cgroup.devices.allow = c 10:229 rwm echo "Failed to add configuration." # nothing do in Plamo Linux # bind-mount the user's path into the container's /home h=`getent passwd $bindhome | cut -d: -f6` echo "$h $rootfs/$h none bind 0 0" >> $path/fstab # copy /etc/passwd, /etc/shadow, and /etc/group entries into container if ! pwd=`getent passwd $bindhome` ; then echo "Warning: failed to copy password entry for $bindhome." echo $pwd >> $rootfs/etc/passwd echo `getent shadow $bindhome` >> $rootfs/etc/shadow [ -d $dlcache -a -d $rtcache ] || return 0 # lock, so we won't purge while someone is creating a repository echo "Cache repository is busy." echo "Purging the download cache..." rm -rf --one-file-system $dlcache $rtcache || return 1 ) 200> @LOCALSTATEDIR@/lock/subsys/lxc $prog [-h|--help] -p|--path=<path> -n|--name=<name> --rootfs=<rootfs> [--clean] [-r|--release=<release>] [-b|--bindhome=<user>] bindhome: bind <user>'s home into the container arch: x86 or x86_64: defaults to host arch path="" ; name="" ; rootfs="" arch=`uname -m | sed 's/i.86/x86/'` ; hostarch=$arch lopts=help,path:,name:,rootfs:,clean,release:,bindhome:,arch: if ! options=`getopt -o $sopts -l $lopts -- "$@"` ; then -h|--help) usage && exit 0 ;; -p|--path) path=$2 ; shift 2 ;; -n|--name) name=$2 ; shift 2 ;; --rootfs) rootfs=$2 ; shift 2 ;; -c|--clean) clean=1 ; shift 1 ;; -r|--release) release=$2 ; shift 2 ;; -b|--bindhome) bindhome=$2 ; shift 2 ;; -a|--arch) arch=$2 ; shift 2 ;; if [ $clean -eq 1 -a -z "$path" ] ; then if [ $hostarch == "x86" -a $arch == "x86_64" ] ; then echo "Can't create x86_64 container on x86." echo "'path' parameter is required." echo "'name' parameter is required." if [ `id -u` -ne 0 ] ; then echo "This script should be run as 'root'." cache=@LOCALSTATEDIR@/cache/lxc ptcache=$cache/partial-${prog##*-}-$release-$arch dlcache=$cache/cache-${prog##*-}-$release-$arch rtcache=$cache/rootfs-${prog##*-}-$release-$arch if [ -z "$rootfs" ] ; then if grep -q "^lxc.rootfs" $path/config ; then rootfs=`grep "^lxc.rootfs" $path/config | awk -F= '{print $2}'` if ! install_plamo ; then echo "Failed to install plamo $release." if ! configure_plamo ; then echo "Failed to configure plamo $release for a container." if ! copy_configuration ; then echo "Failed to write configuration file." if [ -n "$bindhome" ] ; then if [ $clean -eq 1 ] ; then