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 |
ip=$2 |
7 |
netmask=255.255.254.0 |
8 |
|
9 |
test -z "$ip" && ip=10.60.0.253 |
10 |
|
11 |
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 |
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 |
mount | grep /cgroup || mount /cgroup || exit |
57 |
|
58 |
lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc |