:: Re: [DNG] Help needed:[Fwd: eudev: …
Top Page
Delete this message
Reply to this message
Author: aitor_czr
Date:  
To: dng
New-Topics: [DNG] What to do with an inode?
Subject: Re: [DNG] Help needed:[Fwd: eudev: Methods to detect if running in a container.]
Hi Svante,

On 19/2/20 15:17, Svante Signell via Dng wrote:
> Hello,
>
> No replies so far from the devuan-dev list. Maybe with a larger audience I can
> get some help!
>
> Thanks!

Checking  whether the *inode* number of the primary directory in the
standard filesystem hierarchy
used in the most unix-like sytems(that is, the root "/" directory) is
*equal* to 2 will help to differentiate
if you are within a container or not. eg you can do:

$ ls --inode --directory "/"

2 /

While in a container the output of this command will return a high inode
number. I tested it in three
different scenarios:

a) Using docker bash shell of ubuntu:

# docker run -it ubuntu bash

root@b87da5b70a84:/# ls --inode --directory "/"

2492863 /

b) Using a qemu qcow2 image of devuan:

$ ls --inode --directory "/"

9531 /

c) Inside the chroot jail of the live-sdk:

root@devuan:/# ls --inode --directory "/"

22839335 /

I reckon this approach won't work neither in the case of operating
systems using random inode numbers
(but this is not our case),nor in the case of chroot jails rooted on a
mount point, in which case we have
the following workaround(at least in debian-based systems):

https://manpages.debian.org/jessie/debianutils/ischroot.1.en.html

Hope this helps,

Aitor.