--- recepies/lxc/ve2lxc.sh 2009/05/21 15:55:27 93 +++ recepies/lxc/ve2lxc.sh 2010/05/10 12:50:50 206 @@ -1,20 +1,22 @@ #!/bin/sh -x -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 dir=$1 -hostname=ve2lxc ip=$2 -netmask=255.255.254.0 +hostname=$3 +netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'` +gateway=`grep gateway /etc/network/interfaces | head -1 | sed 's/^.*gateway *//'` -test -z "$ip" && ip=10.60.0.253 +test -z "$ip" && ip=10.60.0.252 +test -z "$hostname" && hostname=ve2lxc path=/$dir/etc/inittab tmp=/tmp/inittab cp $path $tmp || exit -function append() { +append() { if ! grep "$1" $path ; then echo "$1" >> $tmp fi @@ -31,8 +33,8 @@ cp $path $path.old && mv $tmp $path fi -lxc-stop -n ve2lxc -lxc-destroy -n ve2lxc +lxc-stop -n $hostname +lxc-destroy -n $hostname test -d /cgroup || mkdir /cgroup grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab @@ -45,24 +47,34 @@ iface eth0 inet static address $ip netmask $netmask + gateway $gateway __interfaces__ echo $hostname > $dir/etc/hostname -conf=/tmp/ve2lxc.conf +echo "$ip $hostname" >> $dir/etc/hosts + +conf=/tmp/$hostname.conf cat << __lxc__ > $conf lxc.utsname = $hostname lxc.tty = 4 lxc.pts = 1024 + lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.name = eth0 lxc.network.mtu = 1500 +#lxc.network.hwaddr = AC:DE:48:00:00:01 +# interface visible on host, part of bridge +#lxc.network.veth.pair = veth0 + #lxc.mount = $MNTFILE lxc.rootfs = $dir +# lxc.mount.entry=/opt /virtual/lxc/rootfs/opt none ro,bind 0 0 + lxc.cgroup.devices.deny = a # /dev/null and zero lxc.cgroup.devices.allow = c 1:3 rwm @@ -81,6 +93,8 @@ lxc.cgroup.devices.allow = c 254:0 rwm __lxc__ +cp -v /etc/resolv.conf /$dir/etc/resolv.conf + mount | grep /cgroup || mount /cgroup || exit -lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc +lxc-create -n $hostname -f $conf && lxc-start -n $hostname