github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/scripts/debug/stage1_install_busybox.sh (about) 1 #!/bin/bash 2 3 function usage_and_exit { 4 echo "Usage: stage1_install_busybox.sh UUID" 5 exit 1 6 } 7 8 ARGC=$# 9 10 if [ ${ARGC} -lt 1 ]; then 11 usage_and_exit 12 fi 13 14 while test $# -gt 0 15 do 16 case "${1}" in 17 --*) 18 usage_and_exit 19 ;; 20 *) UUID="${1}" 21 ;; 22 esac 23 shift 24 done 25 26 BUSYBOX=${BUSYBOX_BINARY:-$(which busybox 2> /dev/null)} 27 28 if [ ! -x "${BUSYBOX}" ]; then 29 echo "error: busybox binary is not executable: Install it or set BUSYBOX_BINARY env variable" 30 exit 1 31 fi 32 33 IS_STATIC=$(file ${BUSYBOX} | grep static) 34 35 if [ -z "${IS_STATIC}" ]; then 36 echo "error: busybox binary is not statically linked" 37 exit 1 38 fi 39 40 RKT_RUN_DIR="/var/lib/rkt/pods/run" 41 POD_DIR="${RKT_RUN_DIR}/${UUID}" 42 43 BUSYBOX_LINKS="ls cp cat mount vi awk chmod chown mv df ps rm tar top tr wc which ping" 44 45 NSPAWN_PID=$(ps aux | grep "[u]uid=$UUID" | awk '{print $2}') 46 47 sudo nsenter -m -t "${NSPAWN_PID}" cp ${BUSYBOX} ${POD_DIR}/stage1/rootfs/bin 48 sudo nsenter -m -t "${NSPAWN_PID}" chmod +x "${POD_DIR}/stage1/rootfs/bin/busybox" 49 50 for link in ${BUSYBOX_LINKS}; do 51 sudo nsenter -m -t "${NSPAWN_PID}" ln -sf busybox "${POD_DIR}/stage1/rootfs/bin/${link}" 52 done 53 54 echo "Busybox installed. Use the following command to enter pod's stage1:" 55 SYSTEMD_PPID=$(sudo cat "${RKT_RUN_DIR}/${UUID}/ppid") 56 SYSTEMD_PID=$(sudo cat /proc/$SYSTEMD_PPID/task/$SYSTEMD_PPID/children) 57 echo sudo nsenter -m -u -i -p -t ${SYSTEMD_PID}