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 |
|
hostname=ve2lxc |
|
6 |
ip=$2 |
ip=$2 |
7 |
|
hostname=$3 |
8 |
netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'` |
netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'` |
9 |
gateway=`grep gateway /etc/network/interfaces | head -1 | sed 's/^.*gateway *//'` |
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 |
33 |
cp $path $path.old && mv $tmp $path |
cp $path $path.old && mv $tmp $path |
34 |
fi |
fi |
35 |
|
|
36 |
lxc-stop -n ve2lxc |
lxc-stop -n $hostname |
37 |
lxc-destroy -n ve2lxc |
lxc-destroy -n $hostname |
38 |
|
|
39 |
test -d /cgroup || mkdir /cgroup |
test -d /cgroup || mkdir /cgroup |
40 |
grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab |
grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab |
55 |
|
|
56 |
echo "$ip $hostname" >> $dir/etc/hosts |
echo "$ip $hostname" >> $dir/etc/hosts |
57 |
|
|
58 |
conf=/tmp/ve2lxc.conf |
conf=/tmp/$hostname.conf |
59 |
|
|
60 |
cat << __lxc__ > $conf |
cat << __lxc__ > $conf |
61 |
lxc.utsname = $hostname |
lxc.utsname = $hostname |
90 |
|
|
91 |
mount | grep /cgroup || mount /cgroup || exit |
mount | grep /cgroup || mount /cgroup || exit |
92 |
|
|
93 |
lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc |
lxc-create -n $hostname -f $conf && lxc-start -n $hostname |