/[sysadmin-cookbook]/recepies/lxc/ve2lxc.sh
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /recepies/lxc/ve2lxc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (show annotations)
Thu May 21 15:55:27 2009 UTC (14 years, 11 months ago) by dpavlin
File MIME type: application/x-sh
File size: 1944 byte(s)
put template lxc configuration inside script itself
change /etc/hostname

1 #!/bin/sh -x
2
3 test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253]" && exit
4
5 dir=$1
6 hostname=ve2lxc
7 ip=$2
8 netmask=255.255.254.0
9
10 test -z "$ip" && ip=10.60.0.253
11
12 path=/$dir/etc/inittab
13 tmp=/tmp/inittab
14
15 cp $path $tmp || exit
16
17 function append() {
18 if ! grep "$1" $path ; then
19 echo "$1" >> $tmp
20 fi
21 }
22
23 append "z6:6:respawn:/sbin/sulogin"
24 append "1:2345:respawn:/sbin/getty 38400 console"
25 append "c1:12345:respawn:/sbin/getty 38400 tty1 linux"
26 append "c2:12345:respawn:/sbin/getty 38400 tty2 linux"
27 append "c3:12345:respawn:/sbin/getty 38400 tty3 linux"
28 append "c4:12345:respawn:/sbin/getty 38400 tty4 linux"
29
30 if ! diff -uw $path $tmp ; then
31 cp $path $path.old && mv $tmp $path
32 fi
33
34 lxc-stop -n ve2lxc
35 lxc-destroy -n ve2lxc
36
37 test -d /cgroup || mkdir /cgroup
38 grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab
39
40 grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces
41 auto eth0 lo
42
43 iface lo inet loopback
44
45 iface eth0 inet static
46 address $ip
47 netmask $netmask
48
49 __interfaces__
50
51 echo $hostname > $dir/etc/hostname
52
53 conf=/tmp/ve2lxc.conf
54
55 cat << __lxc__ > $conf
56 lxc.utsname = $hostname
57 lxc.tty = 4
58 lxc.pts = 1024
59 lxc.network.type = veth
60 lxc.network.flags = up
61 lxc.network.link = br0
62 lxc.network.name = eth0
63 lxc.network.mtu = 1500
64 #lxc.mount = $MNTFILE
65 lxc.rootfs = $dir
66 lxc.cgroup.devices.deny = a
67 # /dev/null and zero
68 lxc.cgroup.devices.allow = c 1:3 rwm
69 lxc.cgroup.devices.allow = c 1:5 rwm
70 # consoles
71 lxc.cgroup.devices.allow = c 5:1 rwm
72 lxc.cgroup.devices.allow = c 5:0 rwm
73 lxc.cgroup.devices.allow = c 4:0 rwm
74 lxc.cgroup.devices.allow = c 4:1 rwm
75 # /dev/{,u}random
76 lxc.cgroup.devices.allow = c 1:9 rwm
77 lxc.cgroup.devices.allow = c 1:8 rwm
78 lxc.cgroup.devices.allow = c 136:* rwm
79 lxc.cgroup.devices.allow = c 5:2 rwm
80 # rtc
81 lxc.cgroup.devices.allow = c 254:0 rwm
82 __lxc__
83
84 mount | grep /cgroup || mount /cgroup || exit
85
86 lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26