mkimage-busybox.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Generate a very minimal filesystem based on busybox-static,
  3. # and load it into the local docker under the name "busybox".
  4. echo >&2
  5. echo >&2 'warning: this script is deprecated - see mkimage.sh and mkimage/busybox-static'
  6. echo >&2
  7. BUSYBOX=$(which busybox)
  8. [ "$BUSYBOX" ] || {
  9. echo "Sorry, I could not locate busybox."
  10. echo "Try 'apt-get install busybox-static'?"
  11. exit 1
  12. }
  13. set -e
  14. ROOTFS=${TMPDIR:-/var/tmp}/rootfs-busybox-$$-$RANDOM
  15. mkdir $ROOTFS
  16. cd $ROOTFS
  17. mkdir bin etc dev dev/pts lib proc sys tmp
  18. touch etc/resolv.conf
  19. cp /etc/nsswitch.conf etc/nsswitch.conf
  20. echo root:x:0:0:root:/:/bin/sh > etc/passwd
  21. echo root:x:0: > etc/group
  22. ln -s lib lib64
  23. ln -s bin sbin
  24. cp $BUSYBOX bin
  25. for X in $(busybox --list)
  26. do
  27. ln -s busybox bin/$X
  28. done
  29. rm bin/init
  30. ln bin/busybox bin/init
  31. cp /lib/x86_64-linux-gnu/lib{pthread,c,dl,nsl,nss_*}.so.* lib
  32. cp /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 lib
  33. for X in console null ptmx random stdin stdout stderr tty urandom zero
  34. do
  35. cp -a /dev/$X dev
  36. done
  37. tar --numeric-owner -cf- . | docker import - busybox
  38. docker run -i -u root busybox /bin/echo Success.