layout 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. set -e
  3. source $(dirname $0)/version
  4. cd $(dirname $0)/..
  5. ARTIFACTS=$(pwd)/dist/artifacts
  6. BUILD=build
  7. INITRD_DIR=${BUILD}/initrd
  8. echo Create initrd layout in $INITRD_DIR
  9. rm -rf ${INITRD_DIR}
  10. mkdir -p ${INITRD_DIR}/usr/{etc,bin,share/ros,var/lib/cni/bin}
  11. ./scripts/template
  12. cp -rf assets/selinux ${INITRD_DIR}/usr/etc
  13. cp -rf assets/docker ${INITRD_DIR}/usr/etc
  14. cp build/images.tar ${INITRD_DIR}/usr/share/ros/
  15. cp bin/ros ${INITRD_DIR}/usr/bin/
  16. ln -s usr/bin/ros ${INITRD_DIR}/init
  17. ln -s bin ${INITRD_DIR}/usr/sbin
  18. ln -s usr/sbin ${INITRD_DIR}/sbin
  19. ln -s ros ${INITRD_DIR}/usr/bin/system-docker
  20. ln -s ros ${INITRD_DIR}/usr/bin/docker-runc
  21. ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/bridge
  22. ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/host-local
  23. cat <<HERE > ${INITRD_DIR}/usr/share/ros/os-release
  24. NAME="RancherOS"
  25. VERSION=${VERSION}
  26. ID=rancheros
  27. ID_LIKE=
  28. VERSION_ID=${VERSION}
  29. PRETTY_NAME="RancherOS ${VERSION}"
  30. HOME_URL="http://rancher.com/rancher-os/"
  31. SUPPORT_URL="https://forums.rancher.com/c/rancher-os"
  32. BUG_REPORT_URL="https://github.com/rancher/os/issues"
  33. BUILD_ID=
  34. HERE
  35. # Support upgrades from old persistent consoles that bind mount these
  36. touch ${INITRD_DIR}/usr/bin/docker-containerd
  37. touch ${INITRD_DIR}/usr/bin/docker-containerd-shim
  38. touch ${INITRD_DIR}/usr/bin/docker
  39. # Override using a local kernel build
  40. if [ -e ${DAPPER_SOURCE}/assets/kernel.tar.gz ]; then
  41. echo "copying ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz"
  42. cp ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz
  43. fi
  44. if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then
  45. mkdir -p ${BUILD}/kernel
  46. tar xf ${DOWNLOADS}/kernel.tar.gz -C ${BUILD}/kernel
  47. for i in vmlinuz vmlinux; do
  48. if [ -e ${BUILD}/kernel/boot/${i}-* ]; then
  49. mkdir -p ${ARTIFACTS}
  50. # frustratingly, the vmlinuz versioned filename != the tag name, so we need to do some guessing
  51. # for eg, 4.9-rc8-rancher2 is called vmlinuz-4.9.0-rc8-rancher
  52. echo "Copy ${BUILD}/kernel/boot/${i}-* to ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
  53. cp ${BUILD}/kernel/boot/${i}-* ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}
  54. # use an unversioned filename for `scripts/run`
  55. cp ${BUILD}/kernel/boot/${i}-* ${BUILD}/kernel/vmlinuz
  56. break
  57. fi
  58. done
  59. # TODO: move these into a separate tar.gz and add to the syslinux initrd line
  60. if [ -d ${BUILD}/kernel/lib ]; then
  61. rm -rf ${INITRD_DIR}/usr/lib
  62. cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
  63. depmod -b ${INITRD_DIR}/usr $(basename ${INITRD_DIR}/usr/lib/modules/*)
  64. #TODO:
  65. # new: put the kernel modules into their own initrd file
  66. #mkdir -p ${BUILD}/kernel-fs/usr/
  67. #pushd .
  68. #cp -rf ${BUILD}/kernel/lib ${BUILD}/kernel-fs/usr/
  69. #depmod -b ${BUILD}/kernel-fs/usr $(basename ${BUILD}/kernel-fs/usr/lib/modules/*)
  70. ## and then package it up cpio
  71. #cd ${BUILD}/kernel-fs/
  72. #echo Creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
  73. #if [ "$COMPRESS" == "" ]; then
  74. # COMPRESS="gzip -1"
  75. #fi
  76. #find | cpio -H newc -o | ${COMPRESS} > ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
  77. #popd
  78. #echo Done creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
  79. ## use an unversioned filename for `scripts/run`
  80. #cp ${ARTIFACTS}/linuxmods-${KERNEL_VERSION} ${BUILD}/kernel/linuxmods
  81. fi
  82. else
  83. if [ "$ARCH" == "amd64" ]; then
  84. echo "no ${DOWNLOADS}/kernel.tar.gz found"
  85. exit 1
  86. fi
  87. fi
  88. if [ "$ARCH" == "amd64" ]; then
  89. ls -lah ${ARTIFACTS}/vmlinuz-*
  90. if [ ! -e "${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}" ]; then
  91. echo "Can't find ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
  92. exit -1
  93. fi
  94. fi
  95. if [ -e ${DOWNLOADS}/policy.29 ]; then
  96. mkdir -p ${INITRD_DIR}/usr/etc/selinux/ros/policy/
  97. cp ${DOWNLOADS}/policy.29 ${INITRD_DIR}/usr/etc/selinux/ros/policy/
  98. fi
  99. DFS_ARCH=$(docker create ${DFS_IMAGE}${SUFFIX})
  100. trap "docker rm -fv ${DFS_ARCH} >/dev/null" EXIT
  101. docker export ${DFS_ARCH} | tar xf - -C ${INITRD_DIR} --exclude=usr/bin/docker* \
  102. --exclude=usr/share/git-core \
  103. --exclude=usr/bin/git \
  104. --exclude=usr/bin/ssh \
  105. --exclude=usr/libexec/git-core \
  106. usr
  107. ./scripts/hash-initrd