LXC Tipps&Tricks

screen -dmS init-login lxc-start -n login2

root@dione:/usr/lib/lxc# lxc-create -n login2 -t ubuntu — -p /lxc/login2

No config file specified, using the default config
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/precise/rootfs-i386 …
Copy /var/cache/lxc/precise/rootfs-i386 to /lxc/login2/rootfs …
Copying rootfs to /lxc/login2/rootfs …
grep: /lxc/login2/config: No such file or directory

##
# The default user is ‚ubuntu‘ with password ‚ubuntu‘!
# Use the ’sudo‘ command to run tasks as root in the container.
##

‚ubuntu‘ template installed
‚login2‘ created

 

root@dione:~# lxc-create -n bind2 -f /lxc/bind2/conf -t ubuntu — -p /lxc/bind2

LXC Tipps&Tricks

screen -dmS init-login lxc-start -n login2

root@dione:/usr/lib/lxc# lxc-create -n login2 -t ubuntu — -p /lxc/login2

No config file specified, using the default config
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/precise/rootfs-i386 …
Copy /var/cache/lxc/precise/rootfs-i386 to /lxc/login2/rootfs …
Copying rootfs to /lxc/login2/rootfs …
grep: /lxc/login2/config: No such file or directory

##
# The default user is ‚ubuntu‘ with password ‚ubuntu‘!
# Use the ’sudo‘ command to run tasks as root in the container.
##

‚ubuntu‘ template installed
‚login2‘ created

 

root@dione:~# lxc-create -n bind2 -f /lxc/bind2/conf -t ubuntu — -p /lxc/bind2

Linux Containervirtualisierung mit LXC

Root-Verzeichnis anlegen

# mkdir -p /lxc/guest/rootfs

Minimales Linux (Ubuntu) installieren

# debootstrap --arch i386 lucid /lxc/guest/rootfs http://archive.ubuntu.com/ubuntu
...

In der Datei /lxc/guest/rootfs/lib/init/fstab die folgenden Zeilen auskommentieren:

/proc
/dev
/dev/pts

Hostname setzen

# echo "guest" > /lxc/guest/rootfs/etc/hostname

Host-Datei anpassen

# cat <<EOF > /lxc/guest/rootfs/etc/hosts
127.0.0.1        localhost guest
EOF

Mittels chroot weitere Anpassungen durchführen

# chroot /lxc/guest/rootfs /bin/bash
# adduser admin
# echo "%admin ALL=(ALL) ALL" >> /etc/sudousers
# aptitude install ...
# exit

Mountpoints in /lxc/guest/fstab anlegen

# cat <<EOF > /lxc/guest/fstab
none   /lxc/guest/rootfs/dev/pts  devpts  defaults 0 0
none   /lxc/guest/rootfs/var/run  tmpfs    defaults 0 0
none   /lxc/guest/rootfs/dev/shm tmpfs  defaults  0 0
EOF

Konfigurationsdatei anlegen

cat <<EOF > /lxc/guest/conf
lxc.utsname = guest # name of your guest container
lxc.tty = 4
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.ipv4 = 192.168.0.20
lxc.network.name = eth0
lxc.mount = /lxc/guest/fstab
lxc.rootfs = /lxc/guest/rootfs
lxc.pts = 1024
#
lxc.cgroup.devices.deny = a
# /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
# console
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
lxc.cgroup.devices.allow = c 4:0 rwm
lxc.cgroup.devices.allow = c 4:1 rwm
# dev/{,u}ranom
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 136:* rwm
lxc.cgroup.devices.allow = c 5:2 rwm
# rtc
lxc.cgroup.devices.allow = c 254:0 rwm
EOF

Link nach /etc/lxc legen

# ln -sf /lxc/guest/conf /etc/lxc/guest.conf

Name des Containers in die Datei /etc/default/lxc (autostart) eintragen

CONTAINERS="guest1 guest2"

Container erzeugen

# lxc-create -n guest -f /etc/lxc/guest.conf

System starten

# lxc-start -n guest -d

Zugriff über die Console

# lxc-console -n guest

Siehe auch: LXC HOWTO


chroot /lxc/login/rootfs /bin/bash