chroot 笔记

                     

贡献者: addis

  • 本文处于草稿阶段。

   参考这篇文章。 以及docker 和 chroot 的区别(见 Docker 笔记)。

   一个便捷使用 chroot 的脚本(修改自这里

# 根目录
chr=test_root
# 要拷贝的命令
bins="bash touch ls rm mkdir rmdir pwd cp mv\
          cat vim tree find ln which sh ldd chmod"

# 拷贝可执行文件以及依赖库
copy_chroot () {
	if [ $# != 2 ] ; then
		echo "usage $0 PATH_TO_BINARY TARGET_FOLDER"
		exit 1
	fi

	PATH_TO_BINARY=`which $1`
	TARGET_FOLDER="$2"

	# if we cannot find the the binary we have to abort
	if [ ! -f "$PATH_TO_BINARY" ] ; then
		echo "The file '$PATH_TO_BINARY' was not found. Aborting!"
		exit 1
	fi

	# copy the binary to the target folder
	# create directories if required
	echo "---> copy binary itself"
	cp --parents -v "$PATH_TO_BINARY" "$TARGET_FOLDER"

	# copy the required shared libs to the target folder
	# create directories if required
	echo "---> copy libraries"
	for lib in `ldd "$PATH_TO_BINARY" | cut -d'>' -f2 \
            | awk '{print $1}'` ; do
	if [ -f "$lib" ] ; then
			cp -v --parents "$lib" "$TARGET_FOLDER"
	fi  
	done

	# I'm on a 64bit system at home. the following
    # code will be not required on a 32bit system.
	# however, I've not tested that yet
	# create lib64 - if required and link the content from lib to it
	if [ ! -d "$TARGET_FOLDER/lib64" ] ; then
		mkdir -v "$TARGET_FOLDER/lib64"
	fi
}

mkdir "$chr"

for bin in $bins; do
	echo; echo "====== $bin ======";
	copy_chroot $bin "$chr"
done

# 进入新环境
chroot $chr `which bash`


致读者: 小时百科一直以来坚持所有内容免费,这导致我们处于严重的亏损状态。 长此以往很可能会最终导致我们不得不选择大量广告以及内容付费等。 因此,我们请求广大读者热心打赏 ,使网站得以健康发展。 如果看到这条信息的每位读者能慷慨打赏 10 元,我们一个星期内就能脱离亏损, 并保证在接下来的一整年里向所有读者继续免费提供优质内容。 但遗憾的是只有不到 1% 的读者愿意捐款, 他们的付出帮助了 99% 的读者免费获取知识, 我们在此表示感谢。

                     

友情链接: 超理论坛 | ©小时科技 保留一切权利