Advertisement
Guest User

qemu user

a guest
Jul 24th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. #!/sbin/runscript
  2. # Copyright 1999-2012 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Header: /var/cvsroot/gentoo-x86/app-emulation/qemu-user/files/qemu-binfmt.initd,v 1.2 2012/02/28 22:06:57 lu_zero Exp $
  5.  
  6. # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
  7.  
  8. depend() {
  9. after procfs
  10. }
  11.  
  12. start() {
  13. ebegin "Registering qemu-user binaries"
  14.  
  15. if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
  16. eerror "You need support for \"misc binaries\" in your kernel!"
  17. eend 1
  18. fi
  19.  
  20. if [[ $(mount | grep -c binfmt_misc) -eq 0 ]] ; then
  21. mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &> /dev/null
  22. local result=$?
  23.  
  24. if [[ $result -ne 0 ]] ; then
  25. eend $result
  26. fi
  27. fi
  28.  
  29. # probe cpu type
  30. cpu=`uname -m`
  31. case "$cpu" in
  32. i386|i486|i586|i686|i86pc|BePC|x86_64)
  33. cpu="i386"
  34. ;;
  35. m68k)
  36. cpu="m68k"
  37. ;;
  38. mips*)
  39. cpu="mips"
  40. ;;
  41. "Power Macintosh"|ppc|ppc64)
  42. cpu="ppc"
  43. ;;
  44. armv[4-9]*)
  45. cpu="arm"
  46. ;;
  47. sparc*)
  48. cpu="sparc"
  49. ;;
  50. esac
  51.  
  52. # register the interpreter for each cpu except for the native one
  53. if [ $cpu != "i386" -a -x "/usr/bin/qemu-static-i386-binfmt" ] ; then
  54. echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-i386-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  55. echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-i386-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  56. fi
  57. if [ $cpu != "alpha" -a -x "/usr/bin/qemu-static-alpha-binfmt" ] ; then
  58. echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-alpha-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  59. fi
  60. if [ $cpu != "arm" -a -x "/usr/bin/qemu-static-arm-binfmt" ] ; then
  61. echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-arm-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  62. fi
  63. if [ $cpu != "arm" -a -x "/usr/bin/qemu-static-armeb-binfmt" ] ; then
  64. echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-armeb-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  65. fi
  66. if [ $cpu != "sparc" -a -x "/usr/bin/qemu-static-sparc-binfmt" ] ; then
  67. echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-sparc-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  68. fi
  69. if [ $cpu != "ppc" -a -x "/usr/bin/qemu-static-ppc-binfmt" ] ; then
  70. echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-ppc-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  71. fi
  72. if [ $cpu != "m68k" -a -x "/usr/bin/qemu-static-m68k-binfmt" ] ; then
  73. echo 'Please check cpu value and header information for m68k!'
  74. echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-m68k-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  75. fi
  76. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mips-binfmt" ] ; then
  77. # FIXME: We could use the other endianness on a MIPS host.
  78. echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-mips-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  79. fi
  80. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mipsel-binfmt" ] ; then
  81. echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-mipsel-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  82. fi
  83. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mipsn32-binfmt" ] ; then
  84. echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-mipsn32-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  85. fi
  86. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mipsn32el-binfmt" ] ; then
  87. echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-mipsn32el-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  88. fi
  89. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mips64-binfmt" ] ; then
  90. echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-mips64-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  91. fi
  92. if [ $cpu != "mips" -a -x "/usr/bin/qemu-static-mips64el-binfmt" ] ; then
  93. echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-mips64el-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  94. fi
  95. if [ $cpu != "sh" -a -x "/usr/bin/qemu-static-sh4-binfmt" ] ; then
  96. echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-static-sh4-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  97. fi
  98. if [ $cpu != "sh" -a -x "/usr/bin/qemu-static-sh4eb-binfmt" ] ; then
  99. echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-static-sh4eb-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  100. fi
  101. if [ $cpu != "s390x" -a -x "/usr/local/bin/qemu-static-s390x-binfmt" ] ; then
  102. echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-static-s390x-binfmt:P' > /proc/sys/fs/binfmt_misc/register
  103. fi
  104. eend $?
  105. }
  106.  
  107. stop() {
  108. ebegin "Unregistering qemu-user binaries"
  109. local arches
  110.  
  111. arches="${arches} i386 i486"
  112. arches="${arches} alpha"
  113. arches="${arches} arm armeb"
  114. arches="${arches} sparc"
  115. arches="${arches} ppc"
  116. arches="${arches} m68k"
  117. arches="${arches} mips mipsel mipsn32 mipsn32el mips64 mips64el"
  118. arches="${arches} sh4 sh4eb"
  119. arches="${arches} s390x"
  120.  
  121. for a in ${arches}; do
  122. if [[ -f /proc/sys/fs/binfmt_misc/$a ]] ; then
  123. echo '-1' > /proc/sys/fs/binfmt_misc/$a
  124. fi
  125. done
  126.  
  127. eend $?
  128. }
  129.  
  130. # vim: ts=4 :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement