]>
git.proxmox.com Git - mirror_lxc.git/blob - templates/lxc-plamo.in
4 # template script for generating Plamo Linux container for LXC
8 # lxc: linux Container library
11 # KATOH Yasufumi <karma@jazz.email.ne.jp>
12 # TAMUKI Shoichi <tamuki@linet.gr.jp>
14 # This library is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU Lesser General Public
16 # License as published by the Free Software Foundation; either
17 # version 2.1 of the License, or (at your option) any later version.
19 # This library is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # Lesser General Public License for more details.
24 # You should have received a copy of the GNU Lesser General Public
25 # License along with this library; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 # ref. https://github.com/Ponce/lxc-slackware/blob/master/lxc-slackware
31 # Detect use under userns (unsupported)
33 [ "$arg" == "--" ] && break
34 if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
35 echo "This template can't be used for unprivileged containers." 1>&2
36 echo "You may want to try the \"download\" template instead." 1>&2
41 # Make sure the usual locations are in PATH
42 export PATH
=$PATH:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
44 [ -r /etc
/default
/lxc
] && .
/etc
/default
/lxc
46 DLSCHEME
=${DLSCHEME:-"http"}
47 MIRRORSRV
=${MIRRORSRV:-"www.ring.gr.jp"}
48 MIRRORPATH
=${MIRRORPATH:-"/pub/linux/Plamo"}
49 CATEGORIES
=${CATEGORIES-"00_base 01_minimum"}
50 EXTRACTGRS
=${EXTRACTGRS-""}
51 IGNOREPKGS
=$
{IGNOREPKGS-
"grub kernel lilo linux_firmware microcode_ctl
52 cpufreqd cpufrequtils gpm"}
53 ADDONPKGS
=${ADDONPKGS-"`echo contrib/Hamradio/{morse,qrq}`"}
56 # check the mini plamo was not already downloaded
57 if ! mkdir -p $ptcache ; then
58 echo "Failed to create '$ptcache' directory."
61 # download a mini plamo into a cache
62 echo "Downloading Plamo-$release minimal..."
64 case $DLSCHEME in http) depth=2 ;; ftp) depth=3 ;; esac
65 rej=${IGNOREPKGS%% *} ; [ -n "$rej" ] && rej="$rej-*"
66 if [ `echo $IGNOREPKGS |
wc -w` -gt 1 ] ; then
67 for p in ${IGNOREPKGS#* } ; do rej="$rej,$p-*" ; done
69 for i in $CATEGORIES ; do
70 wget -nv -e robots=off -r -l $depth -nd -A .tgz,.txz -R "$rej" \
71 -I $MIRRORPATH/Plamo-$release/$arch/plamo/$i \
72 -X $MIRRORPATH/Plamo-$release/$arch/plamo/$i/old \
73 $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/plamo/$i
74 if [ $? -ne 0 ] ; then
75 echo "Failed to download the rootfs, aborting."
79 for i in $EXTRACTGRS ; do
80 wget -nv -e robots=off -r -l $depth -nd -A .tgz,.txz -R "$rej" \
81 -I $MIRRORPATH/Plamo-$release/$arch/contrib/$i \
82 -X $MIRRORPATH/Plamo-$release/$arch/contrib/$i/old \
83 $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/contrib/$i
84 if [ $? -ne 0 ] ; then
85 echo "Failed to download the rootfs, aborting."
89 for p in $ADDONPKGS ; do
90 wget -nv -e robots=off -r -l $depth -nd -A "`basename $p`-*" \
91 -I $MIRRORPATH/Plamo-$release/$arch/`dirname $p` \
92 -X $MIRRORPATH/Plamo-$release/$arch/`dirname $p`/old \
93 $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/`dirname $p`
94 if [ $? -ne 0 ] ; then
95 echo "Failed to download the rootfs, aborting."
100 echo "Download complete."
105 # make a local copy of the mini plamo
106 echo "Copying $rtcache to $rootfs..."
108 find $rtcache -mindepth 1 -maxdepth 1 -exec cp -a {} $rootfs \; || return 1
113 mkdir -p @LOCALSTATEDIR@/lock/subsys
115 if ! flock -n 200 ; then
116 echo "Cache repository is busy."
119 echo "Checking cache download in $dlcache..."
120 if [ ! -d $dlcache ] ; then
121 if ! download_plamo ; then
122 echo "Failed to download plamo $release base packages."
126 if [ ! -x /sbin/installpkg ] ; then
127 echo "'installpkg' command is missing."
128 echo "Installing 'installpkg' command into $dlcache/sbin..."
129 ( cd $dlcache ; tar xpJf hdsetup-*.txz ; rm -rf tmp usr var )
130 sed -i "/ldconfig/!s@/sbin@$dlcache&@g" $dlcache/sbin/installpkg*
131 PATH=$dlcache/sbin:$PATH
133 echo "Installing packages to $rtcache..."
134 if [ ! -d $rtcache ] ; then
136 for p in `ls -cr $dlcache/*.t?z
` ; do
137 installpkg -root $rtcache -priority ADD $p
140 echo "Copy $rtcache to $rootfs..."
141 if ! copy_plamo ; then
142 echo "Failed to copy rootfs."
146 ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
151 mknod -m 666 $rootfs/dev/zero c 1 5
152 chmod 666 $rootfs/dev/random
153 mknod -m 666 $rootfs/dev/urandom c 1 9
154 mkdir -m 755 $rootfs/dev/pts
155 chmod 666 $rootfs/dev/tty
156 chmod 600 $rootfs/dev/console
157 mknod -m 666 $rootfs/dev/tty0 c 4 0
158 mknod -m 666 $rootfs/dev/tty1 c 4 1
159 mknod -m 666 $rootfs/dev/tty2 c 4 2
160 mknod -m 666 $rootfs/dev/tty3 c 4 3
161 mknod -m 666 $rootfs/dev/tty4 c 4 4
162 mknod -m 666 $rootfs/dev/full c 1 7
163 mknod -m 600 $rootfs/dev/initctl p
164 mknod -m 666 $rootfs/dev/ptmx c 5 2
165 # suppress log level output for udev
166 sed -i 's/="err"/=0/' $rootfs/etc/udev/udev.conf
168 cat <<- "EOF" > $rootfs/etc/fstab
169 none /proc proc defaults 0 0
170 none /sys sysfs defaults 0 0
171 none /dev tmpfs defaults 0 0
172 none /tmp tmpfs defaults 0 0
173 none /dev/pts devpts gid=5,mode=620 0 0
174 none /proc/bus/usb usbfs noauto 0 0
175 none /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0
178 cat <<- "EOF" | patch $rootfs/etc/inittab
180 < # What to do when power fails (shutdown to single user).
181 < pf::powerfail:/sbin/shutdown -f +5 "THE POWER IS FAILING"
183 > # What to do when power fails (shutdown).
184 > pf::powerfail:/sbin/shutdown -h +0 "THE POWER IS FAILING"
186 > 1:1235:respawn:/sbin/agetty 38400 console
188 < c5:1235:respawn:/sbin/agetty 38400 tty5 linux
189 < c6:12345:respawn:/sbin/agetty 38400 tty6 linux
192 echo "$name" > $rootfs/etc/HOSTNAME
194 echo "127.0.0.1 localhost $name" > $rootfs/etc/hosts
195 # configure the network using the dhcp
196 echo "DHCP" > $rootfs/var/run/inet1-scheme
198 ln -s ../usr/share/zoneinfo/Asia/Tokyo $rootfs/etc/localtime
199 # disable pam_loginuid.so in /etc/pam.d/login (for libvirt's lxc driver)
200 sed -i '/pam_loginuid/s/^/#/' $rootfs/etc/pam.d/login
202 mv $rootfs/etc/ld.so.conf{.new,}
203 chroot $rootfs ldconfig
205 echo "Setting root password to 'root'..."
206 echo "root:root" | chroot $rootfs chpasswd
207 echo "Please change root password!"
209 ed - $rootfs/etc/rc.d/rc.S <<- "EOF"
217 ed - $rootfs/etc/rc.d/rc.M <<- "EOF"
223 # /etc/rc.d/rc.inet1.tradnet
224 head -n-93 $rootfs/sbin/netconfig.tradnet > /tmp/netconfig.rconly
225 cat <<- EOF >> /tmp/netconfig.rconly
227 RC=$rootfs/etc/rc.d/rc.inet1.tradnet
228 IFCONFIG=sbin/ifconfig
230 INET1SCHEME=var/run/inet1-scheme
233 DHCPCD=usr/sbin/dhclient
237 rm -f $rootfs/etc/rc.d/rc.inet1.tradnet
238 sh /tmp/netconfig.rconly
239 rm -f /tmp/netconfig.rconly
243 copy_configuration() {
245 cat <<- EOF >> $path/config || let ret++
247 lxc.mount = $path/fstab
250 if [ -f "@LXCTEMPLATECONFIG@/plamo.common.conf" ] ; then
251 cat <<- "EOF" >> $path/config || let ret++
253 lxc.include = @LXCTEMPLATECONFIG@/plamo.common.conf
256 # create the fstab (empty by default)
257 touch $path/fstab || let ret++
258 if [ $ret -ne 0 ] ; then
259 echo "Failed to add configuration."
266 # nothing do in Plamo Linux
271 # bind-mount the user's path into the container's /home
272 h=`getent passwd
$bindhome | cut
-d: -f6`
274 echo "$h $rootfs/$h none bind 0 0" >> $path/fstab
275 # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
276 if ! pwd=`getent passwd
$bindhome` ; then
277 echo "Warning: failed to copy password entry for $bindhome."
279 echo $pwd >> $rootfs/etc/passwd
281 echo `getent shadow
$bindhome` >> $rootfs/etc/shadow
285 [ -d $dlcache -a -d $rtcache ] || return 0
286 # lock, so we won't purge while someone is creating a repository
288 if ! flock -n 200 ; then
289 echo "Cache repository is busy."
292 echo "Purging the download cache..."
293 rm -rf --one-file-system $dlcache $rtcache || return 1
296 ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
301 $prog [-h|--help] -p|--path=<path> -n|--name=<name> --rootfs=<rootfs>
302 [--clean] [-r|--release=<release>] [-b|--bindhome=<user>]
305 bindhome: bind <user>'s home into the container
306 arch: x86 or x86_64: defaults to host arch
311 path="" ; name="" ; rootfs=""
313 release=${release:-5.x}
315 arch=`uname
-m |
sed 's/i.86/x86/'` ; hostarch=$arch
317 lopts=help,path:,name:,rootfs:,clean,release:,bindhome:,arch:
318 if ! options=`getopt
-o $sopts -l $lopts -- "$@"` ; then
322 eval set -- "$options"
325 -h|--help) usage && exit 0 ;;
326 -p|--path) path=$2 ; shift 2 ;;
327 -n|--name) name=$2 ; shift 2 ;;
328 --rootfs) rootfs=$2 ; shift 2 ;;
329 -c|--clean) clean=1 ; shift 1 ;;
330 -r|--release) release=$2 ; shift 2 ;;
331 -b|--bindhome) bindhome=$2 ; shift 2 ;;
332 -a|--arch) arch=$2 ; shift 2 ;;
333 --) shift 1 ; break ;;
337 if [ $clean -eq 1 -a -z "$path" ] ; then
341 if [ $hostarch == "x86" -a $arch == "x86_64" ] ; then
342 echo "Can't create x86_64 container on x86."
345 if [ -z "$path" ] ; then
346 echo "'path' parameter is required."
349 if [ -z "$name" ] ; then
350 echo "'name' parameter is required."
353 if [ `id
-u` -ne 0 ] ; then
354 echo "This script should be run as 'root'."
357 cache=@LOCALSTATEDIR@/cache/lxc
358 ptcache=$cache/partial-${prog##*-}-$release-$arch
359 dlcache=$cache/cache-${prog##*-}-$release-$arch
360 rtcache=$cache/rootfs-${prog##*-}-$release-$arch
361 if [ -z "$rootfs" ] ; then
362 if grep -q "^lxc.rootfs" $path/config ; then
363 rootfs=`awk -F= '/^lxc.rootfs =/{ print $2 }' $path/config
`
368 if ! install_plamo ; then
369 echo "Failed to install plamo $release."
372 if ! configure_plamo ; then
373 echo "Failed to configure plamo $release for a container."
376 if ! copy_configuration ; then
377 echo "Failed to write configuration file."
381 if [ -n "$bindhome" ] ; then
384 if [ $clean -eq 1 ] ; then