为什么 util-linux 中没有 nsenter?

zer*_*iel 20 command-line networking 14.04

我经常nsenter在 Arch Linux 下的主系统中使用命令来达到我的目的。现在我必须在 Ubuntu 上工作来测试我的应用程序,但nsenter在 util-linux 中没有。也许它是一个单独的包?

更新。好的,我检查util-linux了 Ubuntu中的版本仍然比 2.23 旧得多。如何在 Ubuntu 上安装新版本的软件包而不会出现任何问题?

Syl*_*eau 19

更新

从 14.10 开始,util-linux提供了nsenter命令。下面的解决方案已经用 14.04 测试过。


Debian/Ubuntu 版本就像你说的那样现在已经很老了,即使在 Trusty 中也是如此。

有一个打开的错误,不幸的是到目前为止没有任何进展。

您可以尝试从源代码构建它:

wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -qO - | tar -xz -C ~/Downloads
Run Code Online (Sandbox Code Playgroud)

确保安装以下构建依赖项:

sudo apt-get install libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool
Run Code Online (Sandbox Code Playgroud)

只需在源目录 ( ~/Downloads/util-linux-2.24.1) 中运行:

./autogen.sh

./configure && make
Run Code Online (Sandbox Code Playgroud)

重要的

难道不是 sudo make install这个软件包在Ubuntu 14.04 LTS,直到它正式投入使用,因为它绝对需要的可用版本libmount,打破你的启动。(如果您这样做,请mount在重新启动机器之前重新安装软件包,如果可以的话。)

致谢:Trevor Alexander评论


最后你会得到:

sylvain@sylvain-ThinkPad-T430s:~/Downloads/util-linux-2.24.1$ ./nsenter -V
nsenter from util-linux 2.24.1
Run Code Online (Sandbox Code Playgroud)

注意:由于 nsenter 在 ubuntu util-linux 版本中不可用,您可以只在 /usr/bin(或 sbin)中安装此文件:

sudo cp ./nsenter /usr/bin
Run Code Online (Sandbox Code Playgroud)

  • 重要提示:在 Ubuntu 14.04 LTS 正式准备使用之前,不要在 Ubuntu 14.04 LTS 上“sudo make install”,因为它肯定需要一个不可用的“libmount”版本,这会破坏你的启动。(如果你这样做了,如果可以的话,在重启你的机器之前重新安装 `mount` 包。) (2认同)

mic*_*lbn 11

如果您使用 docker,您可以在容器中安装 nsenter,然后将 nsenter 命令复制到主机。

从我的要点:https : //gist.github.com/mbn18/0d6ff5cb217c36419661

# Ubuntu 14.04 don't have nsenter - the straight forward way required me to install build tools and etc.
# I preferred to keep the system clean and install nsenter in a container and then copy the command to the host
# Note - its also possible to run nsenter from a container (didn't tried) https://github.com/jpetazzo/nsenter

# start a container
docker run --name nsenter -it ubuntu:14.04 bash

## in the docker
apt-get update
apt-get install git build-essential libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool

git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git util-linux
cd util-linux/

./autogen.sh
./configure --without-python --disable-all-programs --enable-nsenter
make

## from different shell - on the host
docker cp nsenter:/util-linux/nsenter /usr/local/bin/
docker cp nsenter:/util-linux/bash-completion/nsenter /etc/bash_completion.d/nsenter
Run Code Online (Sandbox Code Playgroud)