当前位置: 首页>>技术教程>>正文


为什么util-linux中没有nsenter?

, ,

问题描述

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

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

最佳答案

更新:

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


正如您所说,Debian/Ubuntu 版本现在已经很老了,即使在 Trusty 中也是如此。

有一个打开的 bug,不幸的是到目前为止没有进展。

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

wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -qO - | tar -xz -C ~/Downloads

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

sudo apt-get install libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool

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

./autogen.sh

./configure && make

IMPORTANT

在正式准备好使用之前,不要在 Ubuntu 14.04 LTS 上 sudo make install 这个包,因为它肯定需要一个不可用的 libmount 版本,这会破坏你的启动。 (如果您这样做,请在重新启动计算机之前重新安装 mount 软件包,如果可以的话。)

学分: Trevor Alexander 为他的 comment


最后你会得到:

sylvain@sylvain-ThinkPad-T430s:~/Downloads/util-linux-2.24.1$ ./nsenter -V
nsenter from util-linux 2.24.1

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

sudo cp ./nsenter /usr/bin

次佳答案

如果您使用 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

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13005.html,未经允许,请勿转载。