]>
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 [ -r /etc
/default
/lxc
] && .
/etc
/default
/lxc
33 MIRRORSRV
=${MIRRORSRV:-"ftp.ne.jp"}
34 MIRRORPATH
=${MIRRORPATH:-"/Linux/distributions/plamolinux"}
35 CATEGORY
[0]=${CATEGORY:-"00_base"}
36 PACKAGES
[0]=$
{PACKAGES
:-"aaa_base acl at attr bash btrfs_progs bzip2
37 coreutils cracklib dcron devs dhcp dialog dosfstools dump e2fsprogs
38 ed eject etc extipl file findutils gawk glibc grep groff grub gzip
39 hdsetup hibernate_script iproute2 iputils kbd kmod less libcap
40 libgcc libtirpc lilo linux_pam logrotate lvm2 man
41 mdadm microcode_ctl mlocate ncurses net_tools netkit_combo
42 network_configs nvi openbsd_inetd openssh openssl os_prober pciutils
43 pm_utils procinfo_ng procps_ng readline reiserfsprogs rsyslog sed
44 shadow sudo sysfsutils syslinux sysvinit tar tcp_wrappers tcsh
45 timezone traceroute udev unicon_tools util_linux xz zlib"}
46 CATEGORY
[1]="01_minimum"
47 PACKAGES
[1]="FDclone autofs bc berkeley_db bsd_games cpio cpufreqd
48 cpufrequtils fortune_mod gc gdbm gpm hddtemp hdparm keyutils libelf
49 libieee1284 libusb libusb_compat libxml2 libzip linux_howto lm_sensors
50 lshw lsof lv man_pages man_pages_ja nilfs_utils nkf pcre perl popt
51 psmisc python recode rpm2targz ruby screen sg3_utils sharutils sqlite
52 squashfs_lzma sysstat texinfo time tree unzip usbutils utempter which
54 CATEGORY
[2]="01_minimum/alsa.txz"
55 PACKAGES
[2]="alsa_lib alsa_plugins alsa_utils"
56 CATEGORY
[3]="01_minimum/aspell.txz"
57 PACKAGES
[3]="aspell aspell6_en"
58 CATEGORY
[4]="01_minimum/devel.txz"
59 PACKAGES
[4]="autoconf automake binutils bison cloog cvs diffutils flex
60 g++ gcc gdb gettext gmp indent intltool kernel_headers libc libtool
61 m4 make mpc mpfr onig patch pkg_config ppl pth slang strace yasm"
62 CATEGORY
[5]="01_minimum/gnupg_tls.txz"
63 PACKAGES
[5]="gnupg gnutls gpgme libassuan libgcrypt libgpg_error libksba
65 CATEGORY
[6]="01_minimum/network.txz"
66 PACKAGES
[6]="bind bridge_utils curl cyrus_sasl dnsmasq ethtool fetchmail
67 heimdal hostapd iptables iw libidn libiec61883 libnl3 libpcap
68 libraw1394 libssh2 mailx metamail ncftp ntrack parprouted postfix
69 ppp procmail rsync setserial uml_utilities w3m wget wireless_tools
71 CATEGORY
[7]="01_minimum/nfs.txz"
72 PACKAGES
[7]="libevent libnfsidmap nfs_utils rpcbind"
73 CATEGORY
[8]="01_minimum/tcl.txz"
74 PACKAGES
[8]="expect itcl tcl tclx"
77 # check the mini plamo was not already downloaded
78 if ! mkdir
-p $ptcache ; then
79 echo "Failed to create '$ptcache' directory."
82 # download a mini plamo into a cache
83 echo "Downloading Plamo-$release minimal..."
84 echo "open $MIRRORSRV" > /tmp
/getpkg
85 for i
in `seq 0 $((${#CATEGORY[@]} - 1))` ; do
86 for p
in ${PACKAGES[$i]} ; do
87 cat <<- EOF >> /tmp/getpkg
88 mget $MIRRORPATH/Plamo-$release/$arch/plamo/${CATEGORY[$i]}/$p-*.t?z
92 echo "close" >> /tmp
/getpkg
94 if ! lftp
-f /tmp
/getpkg
; 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 i
in `seq 0 $((${#CATEGORY[@]} - 1))` ; do
137 for p
in ${PACKAGES[$i]} ; do
138 installpkg
-root $rtcache -priority ADD
$dlcache/$p-*.t?z
142 echo "Copy $rtcache to $rootfs..."
143 if ! copy_plamo
; then
144 echo "Failed to copy rootfs."
148 ) 200> @LOCALSTATEDIR@
/lock
/subsys
/lxc
153 mknod
-m 666 $rootfs/dev
/zero c
1 5
154 chmod 666 $rootfs/dev
/random
155 mknod
-m 666 $rootfs/dev
/urandom c
1 9
156 mkdir
-m 755 $rootfs/dev
/pts
157 chmod 666 $rootfs/dev
/tty
158 chmod 600 $rootfs/dev
/console
159 mknod
-m 666 $rootfs/dev
/tty0 c
4 0
160 mknod
-m 666 $rootfs/dev
/tty1 c
4 1
161 mknod
-m 666 $rootfs/dev
/tty2 c
4 2
162 mknod
-m 666 $rootfs/dev
/tty3 c
4 3
163 mknod
-m 666 $rootfs/dev
/tty4 c
4 4
164 mknod
-m 666 $rootfs/dev
/full c
1 7
165 mknod
-m 600 $rootfs/dev
/initctl p
166 mknod
-m 666 $rootfs/dev
/ptmx c
5 2
167 # suppress log level output for udev
168 sed -i 's/="err"/=0/' $rootfs/etc
/udev
/udev.conf
170 cat <<- "EOF" > $rootfs/etc/fstab
171 none /proc proc defaults 0 0
172 none /sys sysfs defaults 0 0
173 none /dev tmpfs defaults 0 0
174 none /tmp tmpfs defaults 0 0
175 none /dev/pts devpts gid=5,mode=620 0 0
176 none /proc/bus/usb usbfs noauto 0 0
177 none /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0
180 cat <<- "EOF" |
patch $rootfs/etc/inittab
182 > 1:1235:respawn:/sbin/agetty 38400 console
184 < c5:1235:respawn:/sbin/agetty 38400 tty5 linux
185 < c6:12345:respawn:/sbin/agetty 38400 tty6 linux
188 echo "$name" > $rootfs/etc/HOSTNAME
190 echo "127.0.0.1 localhost $name" > $rootfs/etc/hosts
191 # configure the network using the dhcp
192 echo "DHCP" > $rootfs/var/run/inet1-scheme
194 ln -s ../usr/share/zoneinfo/Asia/Tokyo $rootfs/etc/localtime
195 # disable pam_loginuid.so in /etc/pam.d/login (for libvirt's lxc driver)
196 sed -i '/pam_loginuid/s/^/#/' $rootfs/etc/pam.d/login
198 cp $rootfs/etc/ld.so.conf.new $rootfs/etc/ld.so.conf
199 chroot $rootfs ldconfig
201 echo "Setting root password to 'root'..."
202 echo "root:root" | chroot $rootfs chpasswd
203 echo "Please change root password!"
205 ed - $rootfs/etc
/rc.d
/rc.S
<<- "EOF"
213 ed - $rootfs/etc
/rc.d
/rc.M
<<- "EOF"
219 # /etc/rc.d/rc.inet1.tradnet
220 head -n-93 $rootfs/sbin/netconfig.tradnet > /tmp/netconfig.rconly
221 cat <<- EOF >> /tmp/netconfig.rconly
223 RC=$rootfs/etc/rc.d/rc.inet1.tradnet
224 IFCONFIG=sbin/ifconfig
226 INET1SCHEME=var/run/inet1-scheme
229 DHCPCD=usr/sbin/dhclient
233 rm -f $rootfs/etc/rc.d/rc.inet1.tradnet
234 sh /tmp/netconfig.rconly
235 rm -f /tmp/netconfig.rconly
239 copy_configuration() {
240 if ! cat <<- EOF >> $path/config ; then
245 lxc.mount.auto = proc sys cgroup
247 lxc.cap.drop = sys_module mac_admin mac_override sys_time
249 lxc.cgroup.devices.deny = a
251 lxc.cgroup.devices.allow = c 1:3 rwm
252 lxc.cgroup.devices.allow = c 1:5 rwm
254 lxc.cgroup.devices.allow = c 5:0 rwm
255 lxc.cgroup.devices.allow = c 5:1 rwm
257 lxc.cgroup.devices.allow = c 1:8 rwm
258 lxc.cgroup.devices.allow = c 1:9 rwm
259 lxc.cgroup.devices.allow = c 5:2 rwm
260 lxc.cgroup.devices.allow = c 136:* rwm
262 lxc.cgroup.devices.allow = c 254:0 rm
264 lxc.cgroup.devices.allow = c 10:229 rwm
266 echo "Failed to add configuration."
273 # nothing do in Plamo Linux
278 # bind-mount the user's path into the container's /home
279 h=`getent passwd $bindhome | cut -d: -f6`
281 echo "$h $rootfs/$h none bind 0 0" >> $path/fstab
282 # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
283 if ! pwd=`getent passwd $bindhome` ; then
284 echo "Warning: failed to copy password entry for $bindhome."
286 echo $pwd >> $rootfs/etc/passwd
288 echo `getent shadow $bindhome` >> $rootfs/etc/shadow
292 [ -d $dlcache -a -d $rtcache ] || return 0
293 # lock, so we won't purge while someone is creating a repository
295 if ! flock -n 200 ; then
296 echo "Cache repository is busy."
299 echo "Purging the download cache..."
300 rm -rf --one-file-system $dlcache $rtcache || return 1
303 ) 200> @LOCALSTATEDIR@/lock/subsys/lxc
308 $prog [-h|--help] -p|--path=<path> -n|--name=<name> --rootfs=<rootfs>
309 [--clean] [-r|--release=<release>] [-b|--bindhome=<user>]
312 bindhome: bind <user>'s home into the container
313 arch: x86 or x86_64: defaults to host arch
318 path="" ; name="" ; rootfs=""
320 release=${release:-5.x}
322 arch=`uname -m | sed 's/i.86/x86/'` ; hostarch=$arch
324 lopts=help,path:,name:,rootfs:,clean,release:,bindhome:,arch:
325 if ! options=`getopt -o $sopts -l $lopts -- "$@"` ; then
329 eval set -- "$options"
332 -h|--help) usage && exit 0 ;;
333 -p|--path) path=$2 ; shift 2 ;;
334 -n|--name) name=$2 ; shift 2 ;;
335 --rootfs) rootfs=$2 ; shift 2 ;;
336 -c|--clean) clean=1 ; shift 1 ;;
337 -r|--release) release=$2 ; shift 2 ;;
338 -b|--bindhome) bindhome=$2 ; shift 2 ;;
339 -a|--arch) arch=$2 ; shift 2 ;;
340 --) shift 1 ; break ;;
344 if [ $clean -eq 1 -a -z "$path" ] ; then
348 if [ $hostarch == "x86" -a $arch == "x86_64" ] ; then
349 echo "Can't create x86_64 container on x86."
352 if [ -z "$path" ] ; then
353 echo "'path' parameter is required."
356 if [ -z "$name" ] ; then
357 echo "'name' parameter is required."
360 if [ `id -u` -ne 0 ] ; then
361 echo "This script should be run as 'root'."
364 cache=@LOCALSTATEDIR@/cache/lxc
365 ptcache=$cache/partial-${prog##*-}-$release-$arch
366 dlcache
=$cache/cache-
${prog##*-}-$release-$arch
367 rtcache
=$cache/rootfs-
${prog##*-}-$release-$arch
368 if [ -z "$rootfs" ] ; then
369 if grep -q "^lxc.rootfs" $path/config
; then
370 rootfs
=$
(awk -F= '/^lxc.rootfs =/{ print $2 }' $path/config
)
375 if ! install_plamo
; then
376 echo "Failed to install plamo $release."
379 if ! configure_plamo
; then
380 echo "Failed to configure plamo $release for a container."
383 if ! copy_configuration
; then
384 echo "Failed to write configuration file."
388 if [ -n "$bindhome" ] ; then
391 if [ $clean -eq 1 ] ; then