-
Notifications
You must be signed in to change notification settings - Fork 2
/
lxc-goodies-mkdebian
executable file
·119 lines (94 loc) · 2.65 KB
/
lxc-goodies-mkdebian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
#
# lxc-goodies
# Copyright © 2010 Mikhail Gusarov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
set -e
#
# Creates new debian instance, fixes LXC-incompatible stuff, installs SSH
# server, provides public SSH key and sets up networking and Zeroconf.
#
# Usage:
#
# user@host $ sudo lxc-goodies-mkdebian vm1 sid
# ...
# user@host $ sudo lxc-start -n vm1 -d
# user@host $ ssh [email protected]
# ...
# root@vm1 #
#
PATH=$PATH:/usr/share/lxc-goodies
. lxc-goodies-config
if [ $# -lt 1 -o $# -gt 3 ]; then
echo "Usage: $0 <name> [<distribution>]"
exit 1
fi
if [ ! -f /usr/sbin/debootstrap ]; then
echo "Please install debootstrap first."
exit 1
fi
NAME="$1"
if [ "x$2" = x ]; then
DISTRO=sid
else
DISTRO="$2"
fi
LXC_ROOT=/var/lib/lxc
if [ -e "$LXC_ROOT/$1" ]; then
echo "$1 already exists."
exit 1
fi
ROOTFS=$LXC_ROOT/$1/rootfs
mkdir -p "$LXC_ROOT/$1"
MAC=$(echo -n '02:'; hexdump -n5 /dev/urandom -e '6/1 "%02X:"' | sed -e 's/:$//')
cat <<EOF > "$LXC_ROOT/$1/config"
lxc.utsname=$1
lxc.network.type=veth
lxc.network.flags=up
lxc.network.link=$BRIDGE_IFACE
lxc.network.hwaddr=$MAC
lxc.network.veth.pair=veth-$1
lxc.pts=256
lxc.tty=4
lxc.rootfs=$ROOTFS
EOF
debootstrap --include openssh-server,avahi-daemon,libnss-mdns --exclude udev $DISTRO $ROOTFS $DEBIAN_MIRROR
#
# Create ttyX for everything after lenny
#
if [ $DISTRO != lenny ]; then
for i in 1 2 3 4 5 6; do
mknod -m 666 $ROOTFS/dev/tty$i c 4 $i
done
fi
echo $NAME > $ROOTFS/etc/hostname
cat <<EOF > $ROOTFS/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
sed -i -e 's/^root:\*:/root::/' $ROOTFS/etc/shadow
touch $ROOTFS/root/.hushlogin
mkdir -m 700 $ROOTFS/root/.ssh
echo "$ROOT_SSH_KEY" > $ROOTFS/root/.ssh/authorized_keys
chmod 600 $ROOTFS/root/.ssh/authorized_keys
#
# FIXME: rlimits are not virtualized in LXC. Disable using RLIMIT_NPROC until it
# is fixed.
#
# echo "DAEMON='/usr/sbin/avahi-daemon --no-rlimits'" >> $ROOTFS/etc/default/avahi-daemon