/[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

Diff of /recepies/lxc/ve2lxc.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 92 by dpavlin, Thu May 21 15:46:59 2009 UTC revision 206 by dpavlin, Mon May 10 12:50:50 2010 UTC
# Line 1  Line 1 
1  #!/bin/sh -x  #!/bin/sh -x
2    
3  test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253]" && exit  test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253 [hostname]]" && exit
4    
5  dir=$1  dir=$1
6  ip=$2  ip=$2
7  netmask=255.255.254.0  hostname=$3
8    netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'`
9    gateway=`grep gateway /etc/network/interfaces | head -1 | sed 's/^.*gateway *//'`
10    
11  test -z "$ip" && ip=10.60.0.253  test -z "$ip" && ip=10.60.0.252
12    test -z "$hostname" && hostname=ve2lxc
13    
14  path=/$dir/etc/inittab  path=/$dir/etc/inittab
15  tmp=/tmp/inittab  tmp=/tmp/inittab
16    
17  cp $path $tmp || exit  cp $path $tmp || exit
18    
19  function append() {  append() {
20          if ! grep "$1" $path ; then          if ! grep "$1" $path ; then
21                  echo "$1" >> $tmp                  echo "$1" >> $tmp
22          fi          fi
# Line 30  if ! diff -uw $path $tmp ; then Line 33  if ! diff -uw $path $tmp ; then
33          cp $path $path.old && mv $tmp $path          cp $path $path.old && mv $tmp $path
34  fi  fi
35    
36  conf=/tmp/ve2lxc.conf  lxc-stop -n $hostname
37  cp ve2lxc.conf $conf || exit  lxc-destroy -n $hostname
 echo "lxc.rootfs = $dir" >> $conf  
   
 lxc-stop -n ve2lxc  
 lxc-destroy -n ve2lxc  
38    
39  test -d /cgroup || mkdir /cgroup  test -d /cgroup || mkdir /cgroup
40  if ! grep /cgroup /etc/fstab ; then  grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab
         echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab  
 fi  
41    
42  grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces  grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces
43  auto eth0 lo  auto eth0 lo
# Line 50  iface lo inet loopback Line 47  iface lo inet loopback
47  iface eth0 inet static  iface eth0 inet static
48          address $ip          address $ip
49          netmask $netmask          netmask $netmask
50            gateway $gateway
51    
52  __interfaces__  __interfaces__
53    
54    echo $hostname > $dir/etc/hostname
55    
56    echo "$ip $hostname" >> $dir/etc/hosts
57    
58    conf=/tmp/$hostname.conf
59    
60    cat << __lxc__ > $conf
61    lxc.utsname = $hostname
62    lxc.tty = 4
63    lxc.pts = 1024
64    
65    lxc.network.type = veth
66    lxc.network.flags = up
67    lxc.network.link = br0
68    lxc.network.name = eth0
69    lxc.network.mtu = 1500
70    #lxc.network.hwaddr = AC:DE:48:00:00:01
71    # interface visible on host, part of bridge
72    #lxc.network.veth.pair = veth0
73    
74    #lxc.mount = $MNTFILE
75    lxc.rootfs = $dir
76    # lxc.mount.entry=/opt /virtual/lxc/rootfs/opt none ro,bind 0 0
77    
78    lxc.cgroup.devices.deny = a
79    # /dev/null and zero
80    lxc.cgroup.devices.allow = c 1:3 rwm
81    lxc.cgroup.devices.allow = c 1:5 rwm
82    # consoles
83    lxc.cgroup.devices.allow = c 5:1 rwm
84    lxc.cgroup.devices.allow = c 5:0 rwm
85    lxc.cgroup.devices.allow = c 4:0 rwm
86    lxc.cgroup.devices.allow = c 4:1 rwm
87    # /dev/{,u}random
88    lxc.cgroup.devices.allow = c 1:9 rwm
89    lxc.cgroup.devices.allow = c 1:8 rwm
90    lxc.cgroup.devices.allow = c 136:* rwm
91    lxc.cgroup.devices.allow = c 5:2 rwm
92    # rtc
93    lxc.cgroup.devices.allow = c 254:0 rwm
94    __lxc__
95    
96    cp -v /etc/resolv.conf /$dir/etc/resolv.conf
97    
98  mount | grep /cgroup || mount /cgroup || exit  mount | grep /cgroup || mount /cgroup || exit
99    
100  lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc  lxc-create -n $hostname -f $conf && lxc-start -n $hostname

Legend:
Removed from v.92  
changed lines
  Added in v.206

  ViewVC Help
Powered by ViewVC 1.1.26