Why there is no nsenter in util-linux?

11,269

Solution 1

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

Solution 2

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
Share:
11,269

Related videos on Youtube

zerospiel
Author by

zerospiel

Freelancer as a Golang developer

Updated on September 18, 2022

Comments

  • zerospiel
    zerospiel over 1 year

    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?

  • zerospiel
    zerospiel about 10 years
    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.
  • Sylvain Pineau
    Sylvain Pineau about 10 years
    Try with the tarball instead. Make sure you have both pkg-config and autoconf installed too
  • CamelBlues
    CamelBlues almost 10 years
    Also, if you get an error about missing python when you actually do have python, make sure to install python2.7-dev package
  • Thomas Ward
    Thomas Ward over 9 years
    Keep in mind the 2.24.x and newer versions are all in "experimental" for good reason, they probably haven't been uploaded to Unstable in Debian due to bugs and issues and aren't ready. As a result of that, and or because it's just too new, it's not in Ubuntu. (NOTE: Utopic looks like it'll have a newer version of this package)
  • bright-star
    bright-star over 9 years
    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.)
  • Sylvain Pineau
    Sylvain Pineau over 9 years
    @TrevorAlexander Thank you, I've added your comment to my answer
  • Aditya M P
    Aditya M P over 8 years
    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.
  • DreadPirateShawn
    DreadPirateShawn about 8 years
    Is utils-linux a typo of util-linux? (Not confident enough to edit the answer, but as far as I can tell, it is.)
  • Sylvain Pineau
    Sylvain Pineau about 8 years
    @DreadPirateShawn It's a typo, good catch. Thanks