Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for detecting a distro from a rootfs even on another OS #161

Closed
pombredanne opened this issue Jan 15, 2017 · 10 comments
Closed

Comments

@pombredanne
Copy link
Contributor

I would be interested to run a distro detection based on some rootfs-like archive for aLinux distro and that on any OS. It could be a a plain pre-imaged rootfs, a container image, a VM image or similar and I would like to detect what it is regardless of which OS distro runs on.

@pombredanne
Copy link
Contributor Author

So essentially I would modify distro to accept an optional path to the root of a distro FS defaulting to / so the behavior would be the same as today by default and would not attempt to run lsb_release unless the path is the default '/' and the current OS is Linux.

@pombredanne
Copy link
Contributor Author

... and make a few paths relative to that provide root path rather than absolute.
Do you have any appetite for including this type of behavior?

@nir0s
Copy link
Collaborator

nir0s commented Jan 17, 2017

Well, you're the first one asking for such behavior, so I can't say that I've had any appetite for it just yet. It went through my mind that it would be nice to support remote distro identification in the sense that you could just provide a machine to identify a distribution on. It would be better if you could provide the exact API you'd expect from a feature like that, and, of course, a PR if you're interested.

@pombredanne
Copy link
Contributor Author

perfect. I will consider a PR .

@hartwork
Copy link
Contributor

lsb_release does not seem to support a custom root directory. So for the callto lsb_release -a (https://github.com/nir0s/distro/blob/1a7d01b095f757754b511591ebe428bd57e19d34/distro.py#L917) it seems to me that root permissions and using chroot would be needed. Unless the call to lsb_release can be avoided. I'm curious what you come up with.

@pombredanne
Copy link
Contributor Author

@hartwork What is lsb_release? it depends!

This is a spec AFAIK. Tool-wise we have many implementations.

At https://sourceforge.net/projects/lsb and now at http://bzr.linuxfoundation.org/loggerhead/lsb/3.1/si/annotate/head:/lsb_release/src/lsb_release this is a shell script.

In Debian and Ubuntu this is a Python script:
https://anonscm.debian.org/cgit/collab-maint/lsb.git/tree/lsb_release.py
http://packages.ubuntu.com/yakkety/lsb-release

In Fedora and Red Hat, the lsb shell script is used as a base:
http://pkgs.fedoraproject.org/repo/extras/redhat-lsb/redhat-lsb-4.1-1.tar.bz2/9c1e474cb81c0ee1941c3129e0e50ea1/

AFAIK, other distros each use their own minor variations or do not have it at all.

So the strategy could be:

  1. skip running lsb_release entirely.
  2. OR vendor the major distros scripts and patch them to accept a root path (or something similar such as https://github.com/likema/lsb_release_ex )
  3. OR implement the strategies of every lsb_release for distros supported here (which is essentially what this module does already so it would just be to further this)

@nir0s
Copy link
Collaborator

nir0s commented Mar 13, 2017

Assuming that we (we being the world) want to standardize retrieving the linux distrubtion information, I guess that not using lsb_release at all but rather implementing the major distribution's implementation of lsb_release (whatever is not already explicitly implemented in distro) would be great. This would not only force standardization but also remove a known yet arbitrarily implemented dependency on lsb_release.

pombredanne added a commit to pombredanne/distro that referenced this issue Nov 12, 2019
This introduce a new optional root_dir argument to contruct a
LinuxDistribution object. When provided, this is used as if it were
the root of the filesystem when looking up for files.

Signed-off-by: Philippe Ombredanne <[email protected]>
@pombredanne
Copy link
Contributor Author

I pushed a PR with a fix for this #247

pombredanne added a commit to pombredanne/distro that referenced this issue Nov 13, 2019
Also fix the root_dir arg of LinuxDistribution() to be an absolute
path to the root of a filesystem and not a path to /etc

Signed-off-by: Philippe Ombredanne <[email protected]>
pombredanne added a commit to pombredanne/distro that referenced this issue Nov 13, 2019
Also fix the root_dir arg of LinuxDistribution() to be an absolute
path to the root of a filesystem and not a path to /etc

Reported-by: Sebastian Pipping <[email protected]> @hartwork
Signed-off-by: Philippe Ombredanne <[email protected]>
nir0s added a commit that referenced this issue May 29, 2020
Detect distro from arbitrary rootfs root_dir #161
@hartwork
Copy link
Contributor

Is this ready to be closed as fixed by #247?

@hartwork hartwork added this to the 1.6.0 milestone Jul 10, 2021
@HorlogeSkynet
Copy link
Member

Indeed, closing here then 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants