20

I frequently using nsenter command for my purposes in my main system under Arch Linux. Now I have to work on Ubuntu to test my apps on it, but there isn't nsenter in util-linux. Maybe it's a separate package?

UPD. Ok, I checked that version of util-linux in Ubuntu is still much older than 2.23. How can I install new version of package without any after problems on Ubuntu?

6
  • If you happen to want it for using it with Docker then just follow the guide here github.com/jpetazzo/nsenter
    – Pithikos
    Jul 22, 2014 at 12:19
  • @Sylvain I don't see the point of adding 14.04 as a tag given that 13.xy was removed.
    – muru
    Feb 28, 2015 at 15:54
  • @muru, actually nsenter is available in 14.10 (See the package list for utils-linux). Hence the 14.04 tag to this question. Feb 28, 2015 at 15:59
  • @SylvainPineau maybe, but does it make sense adding tag to a question half a year old? Why not 12.04 then?
    – muru
    Feb 28, 2015 at 16:12
  • @muru I didn't check if compiling 2.24 as suggested in my original answer works on 12.04. So I preferred to restrict the scope of this Q/A to 14.04. The point of keeping it up-to-date is obviously that this solution is not needed as of 14.10 Feb 28, 2015 at 16:21

3 Answers 3

19

Update:

As of 14.10, the util-linux provides the nsenter command. The solution below has been tested with 14.04.


The Debian/Ubuntu version is as you said quite old now, even in Trusty.

There's an opened bug and so far no progress unfortunately.

You could try to build it from source:

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

Make sure to install the following build dependencies:

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

And just run in the source directory (~/Downloads/util-linux-2.24.1):

./autogen.sh

./configure && make

IMPORTANT

Do NOT sudo make install this package on Ubuntu 14.04 LTS until it is officially ready for use, as it definitely demands an unavailable version of libmount, breaking your boot. (If you do this, reinstall the mount package before rebooting your machine, if you can.)

Credits: Trevor Alexander for his comment.


Finally you'll get:

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

Note: as nsenter is not available in the ubuntu util-linux version, you can install just this file in /usr/bin (or sbin):

sudo cp ./nsenter /usr/bin
9
  • I tried your solution, but I get an error while ./configure, because there is no such file. I'm getting Could not locate the pkg-config autoconf macros. if trying to use configure.ac file.
    – zerospiel
    Mar 26, 2014 at 16:51
  • 1
    Try with the tarball instead. Make sure you have both pkg-config and autoconf installed too Mar 26, 2014 at 17:24
  • 2
    IMPORTANT: Do NOT sudo make install this package on Ubuntu 14.04 LTS until it is officially ready for use, as it definitely demands an unavailable version of libmount, breaking your boot. (If you do this, reinstall the mount package before rebooting your machine, if you can.) Oct 5, 2014 at 7:13
  • 1
    It's not going to break anything to put nsenter in /usr/bin, but usual practice is to leave that for stuff installed from apt packages, and install other stuff in /usr/local/bin. It mostly just makes it easier to see what custom stuff you have set up.
    – mc0e
    Feb 6, 2015 at 3:08
  • 1
    Is utils-linux a typo of util-linux? (Not confident enough to edit the answer, but as far as I can tell, it is.) Apr 11, 2016 at 23:02
11

If you use docker you can install nsenter in a container and then copy the nsenter command to the host.

From my gist: 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
1
  • By "keeping host system clean" you mean obviating the need to install build-essential and the other libraries in the apt-get command above, right? That's actually very interesting if yes, didn't know of docker cp. This is great for building all sorts of things as binaries without polluting the host.
    – Aditya M P
    Dec 31, 2015 at 5:55
0

Starting from Docker 1.3 you can use Docker exec to enter a Docker container :

docker exec -it CONTAINER_NAME /bin/bash

as mentioned in the repo for https://github.com/jpetazzo/nsenter

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .