mk-initrd.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. set -ex
  3. TARGET=$(pwd)/${1}
  4. SUFFIX=${SUFFIX:-""}
  5. HOST_SUFFIX=${HOST_SUFFIX:-""}
  6. DFS_IMAGE=${DFS_IMAGE:?"DFS_IMAGE not set"}
  7. IS_ROOTFS=${IS_ROOTFS:-0}
  8. cd $(dirname $0)/..
  9. . scripts/build-common
  10. INITRD_DIR=${BUILD}/initrd
  11. rm -rf ${INITRD_DIR}/{usr,init}
  12. mkdir -p ${INITRD_DIR}/usr/{bin,share/ros}
  13. mkdir -p ${INITRD_DIR}/var/lib/system-docker
  14. mkdir -p ${INITRD_DIR}/usr/etc/selinux/ros/{policy,contexts}
  15. if [ "$IS_ROOTFS" == "0" ]; then
  16. cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
  17. fi
  18. cp assets/docker ${INITRD_DIR}/usr/bin/docker
  19. if [ "$IS_ROOTFS" == "0" ]; then
  20. cp ${BUILD}/images.tar ${INITRD_DIR}/usr/share/ros/
  21. fi
  22. cp build/os-config.yml ${INITRD_DIR}/usr/share/ros/
  23. cp bin/ros ${INITRD_DIR}/usr/bin/
  24. ln -s usr/bin/ros ${INITRD_DIR}/init
  25. ln -s bin ${INITRD_DIR}/usr/sbin
  26. ln -s usr/sbin ${INITRD_DIR}/sbin
  27. cp assets/selinux/config ${INITRD_DIR}/usr/etc/selinux/
  28. cp assets/selinux/policy.29 ${INITRD_DIR}/usr/etc/selinux/ros/policy/
  29. cp assets/selinux/seusers ${INITRD_DIR}/usr/etc/selinux/ros/
  30. cp assets/selinux/lxc_contexts ${INITRD_DIR}/usr/etc/selinux/ros/contexts/
  31. cp assets/selinux/failsafe_context ${INITRD_DIR}/usr/etc/selinux/ros/contexts/
  32. if [ "$ARCH" == "amd64" ]; then
  33. KERNEL_RELEASE=$(tar xvf assets/modules.tar.gz -C ${INITRD_DIR} | cut -f4 -d/ | cut -f1 -d ' ')
  34. depmod -a -b ${INITRD_DIR}/usr $KERNEL_RELEASE
  35. fi
  36. DFS_ARCH=$(docker create ${DFS_IMAGE}${SUFFIX})
  37. trap "docker rm -fv ${DFS_ARCH}" EXIT
  38. docker export ${DFS_ARCH} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerlaunch \
  39. --exclude=usr/bin/docker \
  40. --exclude=usr/share/git-core \
  41. --exclude=usr/bin/git \
  42. --exclude=usr/bin/ssh \
  43. --exclude=usr/libexec/git-core \
  44. usr
  45. if [ "$IS_ROOTFS" == "1" ]; then
  46. DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_IMAGE}${HOST_SUFFIX})
  47. trap "docker rm -fv ${DFS_ARCH} ${DFS}" EXIT
  48. docker exec -i ${DFS} docker load < ${BUILD}/images.tar
  49. docker stop ${DFS}
  50. docker run --rm --volumes-from=${DFS} rancher/os-dapper-base tar -c -C /var/lib/docker ./image | tar -x -C ${INITRD_DIR}/var/lib/system-docker
  51. docker run --rm --volumes-from=${DFS} rancher/os-dapper-base tar -c -C /var/lib/docker ./overlay | tar -x -C ${INITRD_DIR}/var/lib/system-docker
  52. cd ${INITRD_DIR}
  53. tar -czf ${TARGET} .
  54. else
  55. COMPRESS=lzma
  56. [ "$DEV_BUILD" == "1" ] && COMPRESS="gzip -1"
  57. cd ${INITRD_DIR}
  58. find | cpio -H newc -o | ${COMPRESS} > ${TARGET}
  59. fi