已经有两个答案建议使用chroot和绑定挂载,还有第三个紧密相关的选项:mount namespaces。使用该unshare
程序,您可以创建一个新的安装命名空间,并且该命名空间内的安装不会影响其他命名空间。
例如,在一个终端中,我这样做:
muru|[0] ~ sudo unshare -m /bin/bash
root@muru-1604:~# sudo mount --bind /bin/bash /bin/sh
root@muru-1604:~# /bin/sh --version
GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@muru-1604:~# sudo -iu muru
muru|[0] ~ /bin/sh --version # propagates
GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
而在另一个:
$ /bin/sh --version
/bin/sh: 0: Illegal option --
因此,您可以在其自己的安装名称空间中运行该不灵活的程序。