在编写用于完全自动化虚拟机设置的perl脚本(Xen pv)时,我遇到了一个很小的问题.
使用perl的chroot函数我在guest文件系统上做我的事情,然后我需要回到我的初始真正的根.我到底怎么回事?
脚本示例:
`mount $disk_image $mount_point`;
chdir($mount_point);
chroot($mount_point);
#[Do my things...]
#<Exit chroot wanted here>
`umount $mount_point`;
#[Post install things...]
Run Code Online (Sandbox Code Playgroud)
我试过退出; 但显然退出整个脚本.
正在寻找一种退出chroot的方法我发现了许多旨在退出已经设置好的chroot 的脚本(权限提升).由于我在这里做chroot这些方法不适用.
试过一些疯狂的事情:
opendir REAL_ROOT, "/";
chdir($mount_point);
chroot($mount_point);
chdir(*REAL_ROOT);
Run Code Online (Sandbox Code Playgroud)
但是没有去.
更新 一些要考虑的要点:
chrooted process()不能通过退出(退出)退出"unchroot".
你必须生成一个子进程,它将chroot.
下面的内容应该可以解决问题:
if (fork())
{
# parent
wait;
}
else
{
# children
chroot("/path/to/somewhere/");
# do some Perl stuff inside the chroot...
exit;
}
# The parent can continue it's stuff after his chrooted children did some others stuff...
Run Code Online (Sandbox Code Playgroud)
它仍然缺乏一些错误检查的想法.
归档时间: |
|
查看次数: |
2539 次 |
最近记录: |