starfry

Archlinux Linux Container ALSA configuration (pre-systemd)

Sep 7th, 2010
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.55 KB | None | 0 0
  1. #
  2. # Create a basic container (Arch Linux)
  3. #
  4.  
  5. cd /srv/lxc
  6. mkarchroot mycontainer base
  7. cat > /etc/lxc/mycontainer.conf << EOF
  8. # hostname
  9. lxc.utsname = mycontainer
  10. #
  11. # network
  12. #     if the network is not defined then the container
  13. #     will be able to use the host's network
  14. lxc.network.type = veth
  15. lxc.network.flags = up
  16. lxc.network.link = br0
  17. lxc.network.name = eth0
  18. lxc.network.mtu = 1500
  19. lxc.network.ipv4 = 10.0.200.3/8
  20. #
  21. # only explicit device access
  22. lxc.cgroup.devices.deny = a
  23. #
  24. # Memory Devices
  25. lxc.cgroup.devices.allow = c 1:3 rwm # /dev/null      null stream
  26. lxc.cgroup.devices.allow = c 1:5 rwm # /dev/zero      zero stream
  27. lxc.cgroup.devices.allow = c 1:7 rwm # /dev/full      full stream
  28. lxc.cgroup.devices.allow = c 1:8 rwm # /dev/urandom   blocking random stream
  29. lxc.cgroup.devices.allow = c 1:9 rwm # /dev/random    non blocking stream
  30. #
  31. # Terminals
  32. lxc.tty =1                           #                allow one tty
  33. lxc.cgroup.devices.allow = c 4:0 rwm # /dev/tty0      current virtual terminal
  34. lxc.cgroup.devices.allow = c 5:0 rwm # /dev/tty       current tty device    
  35. lxc.cgroup.devices.allow = c 5:1 rwm # /dev/console   system console
  36. lxc.cgroup.devices.allow = c 5:2 rwm   # /dev/ptmx    pseudo terminal creator
  37. lxc.cgroup.devices.allow = c 136:* rwm # /dev/pts/*   psuedo terminal slaves
  38. #
  39. # root filesystem
  40. lxc.rootfs = /srv/lxc/mycontainer
  41. #
  42. # mounts
  43. lxc.mount = /etc/lxc/mycontainer.fstab
  44. EOF
  45. cat > /etc/lxc/mycontainer.fstab << EOF
  46. none /srv/lxc/mycontainer/dev/pts devpts defaults 0 0
  47. none /srv/lxc/mycontainer/dev/shm tmpfs defaults 0 0
  48. none /srv/lxc/mycontainer/proc proc defaults 0 0
  49. none /srv/lxc/mycontainer/sys sysfs defaults 0 0
  50. EOF
  51. lxc-create -f /etc/lxc/mycontainer.conf -n mycontainer
  52. cd /srv/lxc/mycontainer/dev
  53. rm -rf *
  54. mknod -m 666 null c 1 3      # null stream
  55. mknod -m 666 zero c 1 5      # zero stream
  56. mknod -m 666 full c 1 7      # full stream
  57. mknod -m 666 random c 1 8    # blocking random stream
  58. mknod -m 666 urandom c 1 9   # non blocking stream
  59. mknod -m 600 tty0 c 4 0      # current virtual terminal    
  60. mknod -m 666 tty c 5 0       # process's current tty device
  61. mknod -m 600 console c 5 1   # system console aka tty0
  62. mknod -m 666 ptmx c 5 2      # pseudo terminal creator
  63. mkdir -m 755 pts             # psuedo terminal slaves
  64. mkdir -m 1777 shm            # shared memory
  65. mknod -m 600 initctl p       # init control channel
  66. mknod -m 600 tty1 c 4 1           # tty1 virtual console
  67. sed -i '/c[2-9]/d' /srv/lxc/mycontainer/etc/inittab
  68. cat > /srv/lxc/mycontainer/etc/rc.sysinit << EOF
  69. #!/bin/bash
  70.  
  71. # Clean out old daemon/service pids from the container
  72. rm -f $(find /var/run -name '*pid')
  73. rm -f /var/lock/subsys/*
  74.  
  75. # network (or use a DHCP client here)
  76. route add default gw 10.0.0.138
  77. echo > /etc/resolv.conf search your-domain
  78. echo >> /etc/resolv.conf nameserver 10.0.0.138
  79.  
  80.  
  81. # Initally we don't have any container originated mounts
  82. rm -f /etc/mtab
  83. touch /etc/mtab''
  84. EOF
  85. rm -f /srv/lxc/mycontainer/etc/localtime
  86. cp /usr/share/zoneinfo/GB /srv/lxc/mycontainer/etc/localtime
  87. cp /etc/pacman.d/mirrorlist /srv/lxc/mycontainer/etc/pacman.d/mirrorlist
  88.  
  89.  
  90. #
  91. # Setup mycontainer with Alsa. Do this on the host
  92. #
  93.  
  94. cat >> /etc/lxc/mycontainer.conf << EOF
  95. # For ALSA Sound
  96. lxc.cgroup.devices.allow = c 116:* rwm # dev/snd/
  97. EOF
  98.  
  99. #
  100. # Script to creae sound devices. You may need to hand paste this if it
  101. # doesn't work with cat.
  102. #
  103.  
  104. cat > /srv/lxc/make_sound_devices << EOF
  105. #!/bin/bash
  106. LXC_ROOT=/srv/lxc
  107. CONTAINERS="mycontainer"
  108.  
  109. for CONTAINER in $CONTAINERS
  110. do
  111.     rm -rf ${LXC_ROOT}/${CONTAINER}/dev/snd
  112.     mkdir -p ${LXC_ROOT}/${CONTAINER}/dev/snd
  113. done
  114.  
  115. ifs_char=$IFS
  116. IFS=$'\n'
  117. ifs_line=$IFS
  118. for i in $(ls -l /dev/snd | grep '^c' | awk -F "[ ,]" {'print "mknod -m 660 ${LX
  119. C_ROOT}/${CONTAINER}/dev/snd/"$12" c "$5" "$7" && chown root:audio ${LXC_ROOT}/$
  120. {CONTAINER}/dev/snd/"$12'})
  121. do
  122.     IFS=$ifs_char
  123.     for CONTAINER in $CONTAINERS
  124.     do
  125.       eval $i
  126.     done
  127.     IFS=$ifs_line
  128. done
  129. EOF
  130.  
  131. #
  132. # make the sound devices using above script
  133. #
  134. chmod +x /srv/lxc/make_sound_devices
  135. /srv/lxc/make_sound_devices
  136.  
  137. #
  138. # recreate and start the container
  139. #
  140.  
  141. lxc-destroy -n mycontainer
  142. lxc-create -f /etc/lxc/mycontainer.conf -n mycontainer
  143.  
  144. /usr/bin/screen -dmS screen-mycontainer /usr/bin/lxc-start -n mycontainer
  145.  
  146. #
  147. # enter the container
  148. #
  149.  
  150. lxc-console -n mycontainer
  151. root
  152.  
  153. #
  154. # setup locale and update
  155. #
  156. usr/sbin/locale-gen
  157. pacman -Syy
  158. pacman -Syu
  159.  
  160.  
  161. #
  162. # setup ALSA
  163. #
  164.  
  165. pacman -S alsa-utils
  166.  
  167.  
  168. #
  169. # test it works
  170. #
  171. aplay /usr/share/sounds/alsa/Front_Center.wav
Add Comment
Please, Sign In to add comment