Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Create a basic container (Arch Linux)
- #
- cd /srv/lxc
- mkarchroot mycontainer base
- cat > /etc/lxc/mycontainer.conf << EOF
- # hostname
- lxc.utsname = mycontainer
- #
- # network
- # if the network is not defined then the container
- # will be able to use the host's network
- lxc.network.type = veth
- lxc.network.flags = up
- lxc.network.link = br0
- lxc.network.name = eth0
- lxc.network.mtu = 1500
- lxc.network.ipv4 = 10.0.200.3/8
- #
- # only explicit device access
- lxc.cgroup.devices.deny = a
- #
- # Memory Devices
- lxc.cgroup.devices.allow = c 1:3 rwm # /dev/null null stream
- lxc.cgroup.devices.allow = c 1:5 rwm # /dev/zero zero stream
- lxc.cgroup.devices.allow = c 1:7 rwm # /dev/full full stream
- lxc.cgroup.devices.allow = c 1:8 rwm # /dev/urandom blocking random stream
- lxc.cgroup.devices.allow = c 1:9 rwm # /dev/random non blocking stream
- #
- # Terminals
- lxc.tty =1 # allow one tty
- lxc.cgroup.devices.allow = c 4:0 rwm # /dev/tty0 current virtual terminal
- lxc.cgroup.devices.allow = c 5:0 rwm # /dev/tty current tty device
- lxc.cgroup.devices.allow = c 5:1 rwm # /dev/console system console
- lxc.cgroup.devices.allow = c 5:2 rwm # /dev/ptmx pseudo terminal creator
- lxc.cgroup.devices.allow = c 136:* rwm # /dev/pts/* psuedo terminal slaves
- #
- # root filesystem
- lxc.rootfs = /srv/lxc/mycontainer
- #
- # mounts
- lxc.mount = /etc/lxc/mycontainer.fstab
- EOF
- cat > /etc/lxc/mycontainer.fstab << EOF
- none /srv/lxc/mycontainer/dev/pts devpts defaults 0 0
- none /srv/lxc/mycontainer/dev/shm tmpfs defaults 0 0
- none /srv/lxc/mycontainer/proc proc defaults 0 0
- none /srv/lxc/mycontainer/sys sysfs defaults 0 0
- EOF
- lxc-create -f /etc/lxc/mycontainer.conf -n mycontainer
- cd /srv/lxc/mycontainer/dev
- rm -rf *
- mknod -m 666 null c 1 3 # null stream
- mknod -m 666 zero c 1 5 # zero stream
- mknod -m 666 full c 1 7 # full stream
- mknod -m 666 random c 1 8 # blocking random stream
- mknod -m 666 urandom c 1 9 # non blocking stream
- mknod -m 600 tty0 c 4 0 # current virtual terminal
- mknod -m 666 tty c 5 0 # process's current tty device
- mknod -m 600 console c 5 1 # system console aka tty0
- mknod -m 666 ptmx c 5 2 # pseudo terminal creator
- mkdir -m 755 pts # psuedo terminal slaves
- mkdir -m 1777 shm # shared memory
- mknod -m 600 initctl p # init control channel
- mknod -m 600 tty1 c 4 1 # tty1 virtual console
- sed -i '/c[2-9]/d' /srv/lxc/mycontainer/etc/inittab
- cat > /srv/lxc/mycontainer/etc/rc.sysinit << EOF
- #!/bin/bash
- # Clean out old daemon/service pids from the container
- rm -f $(find /var/run -name '*pid')
- rm -f /var/lock/subsys/*
- # network (or use a DHCP client here)
- route add default gw 10.0.0.138
- echo > /etc/resolv.conf search your-domain
- echo >> /etc/resolv.conf nameserver 10.0.0.138
- # Initally we don't have any container originated mounts
- rm -f /etc/mtab
- touch /etc/mtab''
- EOF
- rm -f /srv/lxc/mycontainer/etc/localtime
- cp /usr/share/zoneinfo/GB /srv/lxc/mycontainer/etc/localtime
- cp /etc/pacman.d/mirrorlist /srv/lxc/mycontainer/etc/pacman.d/mirrorlist
- #
- # Setup mycontainer with Alsa. Do this on the host
- #
- cat >> /etc/lxc/mycontainer.conf << EOF
- # For ALSA Sound
- lxc.cgroup.devices.allow = c 116:* rwm # dev/snd/
- EOF
- #
- # Script to creae sound devices. You may need to hand paste this if it
- # doesn't work with cat.
- #
- cat > /srv/lxc/make_sound_devices << EOF
- #!/bin/bash
- LXC_ROOT=/srv/lxc
- CONTAINERS="mycontainer"
- for CONTAINER in $CONTAINERS
- do
- rm -rf ${LXC_ROOT}/${CONTAINER}/dev/snd
- mkdir -p ${LXC_ROOT}/${CONTAINER}/dev/snd
- done
- ifs_char=$IFS
- IFS=$'\n'
- ifs_line=$IFS
- for i in $(ls -l /dev/snd | grep '^c' | awk -F "[ ,]" {'print "mknod -m 660 ${LX
- C_ROOT}/${CONTAINER}/dev/snd/"$12" c "$5" "$7" && chown root:audio ${LXC_ROOT}/$
- {CONTAINER}/dev/snd/"$12'})
- do
- IFS=$ifs_char
- for CONTAINER in $CONTAINERS
- do
- eval $i
- done
- IFS=$ifs_line
- done
- EOF
- #
- # make the sound devices using above script
- #
- chmod +x /srv/lxc/make_sound_devices
- /srv/lxc/make_sound_devices
- #
- # recreate and start the container
- #
- lxc-destroy -n mycontainer
- lxc-create -f /etc/lxc/mycontainer.conf -n mycontainer
- /usr/bin/screen -dmS screen-mycontainer /usr/bin/lxc-start -n mycontainer
- #
- # enter the container
- #
- lxc-console -n mycontainer
- root
- #
- # setup locale and update
- #
- usr/sbin/locale-gen
- pacman -Syy
- pacman -Syu
- #
- # setup ALSA
- #
- pacman -S alsa-utils
- #
- # test it works
- #
- aplay /usr/share/sounds/alsa/Front_Center.wav
Add Comment
Please, Sign In to add comment