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

Annotation of /recepies/lxc/ve2lxc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92 - (hide annotations)
Thu May 21 15:46:59 2009 UTC (14 years, 11 months ago) by dpavlin
File MIME type: application/x-sh
File size: 1233 byte(s)
configure /etc/network/interfaces in new lxc container

1 dpavlin 86 #!/bin/sh -x
2    
3 dpavlin 92 test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253]" && exit
4 dpavlin 86
5     dir=$1
6 dpavlin 92 ip=$2
7     netmask=255.255.254.0
8 dpavlin 86
9 dpavlin 92 test -z "$ip" && ip=10.60.0.253
10    
11 dpavlin 86 path=/$dir/etc/inittab
12     tmp=/tmp/inittab
13    
14     cp $path $tmp || exit
15    
16     function append() {
17     if ! grep "$1" $path ; then
18     echo "$1" >> $tmp
19     fi
20     }
21    
22     append "z6:6:respawn:/sbin/sulogin"
23     append "1:2345:respawn:/sbin/getty 38400 console"
24     append "c1:12345:respawn:/sbin/getty 38400 tty1 linux"
25     append "c2:12345:respawn:/sbin/getty 38400 tty2 linux"
26     append "c3:12345:respawn:/sbin/getty 38400 tty3 linux"
27     append "c4:12345:respawn:/sbin/getty 38400 tty4 linux"
28    
29     if ! diff -uw $path $tmp ; then
30     cp $path $path.old && mv $tmp $path
31     fi
32    
33     conf=/tmp/ve2lxc.conf
34     cp ve2lxc.conf $conf || exit
35     echo "lxc.rootfs = $dir" >> $conf
36    
37     lxc-stop -n ve2lxc
38     lxc-destroy -n ve2lxc
39    
40     test -d /cgroup || mkdir /cgroup
41     if ! grep /cgroup /etc/fstab ; then
42     echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab
43     fi
44    
45 dpavlin 92 grep eth0 $dir/etc/network/interfaces || cat << __interfaces__ > $dir/etc/network/interfaces
46     auto eth0 lo
47    
48     iface lo inet loopback
49    
50     iface eth0 inet static
51     address $ip
52     netmask $netmask
53    
54     __interfaces__
55    
56 dpavlin 86 mount | grep /cgroup || mount /cgroup || exit
57    
58 dpavlin 92 lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26