/[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 112 by dpavlin, Mon Jun 15 20:22:52 2009 UTC
# Line 3  Line 3 
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]" && exit
4    
5  dir=$1  dir=$1
6    hostname=ve2lxc
7  ip=$2  ip=$2
8  netmask=255.255.254.0  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.253
12    
# Line 30  if ! diff -uw $path $tmp ; then Line 32  if ! diff -uw $path $tmp ; then
32          cp $path $path.old && mv $tmp $path          cp $path $path.old && mv $tmp $path
33  fi  fi
34    
 conf=/tmp/ve2lxc.conf  
 cp ve2lxc.conf $conf || exit  
 echo "lxc.rootfs = $dir" >> $conf  
   
35  lxc-stop -n ve2lxc  lxc-stop -n ve2lxc
36  lxc-destroy -n ve2lxc  lxc-destroy -n ve2lxc
37    
38  test -d /cgroup || mkdir /cgroup  test -d /cgroup || mkdir /cgroup
39  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  
40    
41  grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces  grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces
42  auto eth0 lo  auto eth0 lo
# Line 50  iface lo inet loopback Line 46  iface lo inet loopback
46  iface eth0 inet static  iface eth0 inet static
47          address $ip          address $ip
48          netmask $netmask          netmask $netmask
49            gateway $gateway
50    
51  __interfaces__  __interfaces__
52    
53    echo $hostname > $dir/etc/hostname
54    
55    echo "$ip $hostname" >> $dir/etc/hosts
56    
57    conf=/tmp/ve2lxc.conf
58    
59    cat << __lxc__ > $conf
60    lxc.utsname = $hostname
61    lxc.tty = 4
62    lxc.pts = 1024
63    lxc.network.type = veth
64    lxc.network.flags = up
65    lxc.network.link = br0
66    lxc.network.name = eth0
67    lxc.network.mtu = 1500
68    #lxc.mount = $MNTFILE
69    lxc.rootfs = $dir
70    lxc.cgroup.devices.deny = a
71    # /dev/null and zero
72    lxc.cgroup.devices.allow = c 1:3 rwm
73    lxc.cgroup.devices.allow = c 1:5 rwm
74    # consoles
75    lxc.cgroup.devices.allow = c 5:1 rwm
76    lxc.cgroup.devices.allow = c 5:0 rwm
77    lxc.cgroup.devices.allow = c 4:0 rwm
78    lxc.cgroup.devices.allow = c 4:1 rwm
79    # /dev/{,u}random
80    lxc.cgroup.devices.allow = c 1:9 rwm
81    lxc.cgroup.devices.allow = c 1:8 rwm
82    lxc.cgroup.devices.allow = c 136:* rwm
83    lxc.cgroup.devices.allow = c 5:2 rwm
84    # rtc
85    lxc.cgroup.devices.allow = c 254:0 rwm
86    __lxc__
87    
88    cp -v /etc/resolv.conf /$dir/etc/resolv.conf
89    
90  mount | grep /cgroup || mount /cgroup || exit  mount | grep /cgroup || mount /cgroup || exit
91    
92  lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc  lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc

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

  ViewVC Help
Powered by ViewVC 1.1.26