[Libguestfs] [PATCH] inspect: check also /etc/hosts for detecting Linux root (RHBZ#1203898)

Pino Toscano ptoscano at redhat.com
Wed Feb 24 17:05:51 UTC 2016


On Wednesday 24 February 2016 16:38:59 Daniel P. Berrange wrote:
> On Wed, Feb 24, 2016 at 05:31:32PM +0100, Pino Toscano wrote:
> > Use /etc/hosts as alternative of /etc/fstab to detect whether a partition
> > represents the root of a Linux installation; the latter might not exist
> > in smaller/special installations like Docker images.
> > ---
> >  src/inspect-fs.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/inspect-fs.c b/src/inspect-fs.c
> > index 02fdb2a..ad175f8 100644
> > --- a/src/inspect-fs.c
> > +++ b/src/inspect-fs.c
> > @@ -217,7 +217,8 @@ check_filesystem (guestfs_h *g, const char *mountable,
> >             (is_dir_bin ||
> >              (guestfs_is_symlink (g, "/bin") > 0 &&
> >               guestfs_is_dir (g, "/usr/bin") > 0)) &&
> > -           guestfs_is_file (g, "/etc/fstab") > 0) {
> > +           (guestfs_is_file (g, "/etc/fstab") > 0 ||
> > +            guestfs_is_file (g, "/etc/hosts") > 0)) {
> 
> /etc/hosts could be present on any UNIX pretty much  (so could /etc/fstab
> for that matter).

I know -- the case here was about Docker images without /etc/fstab.

> If you want Linux then how about /lib/ld-linux.so.2  which exists
> on any Linux with ELF library support.

Well, that is not universally available: on my Fedora 23 it doesn't
exist, and indeed:

  $ env LC_ALL=C readelf -l /bin/ls \
    | perl -n -e 'if (/program interpreter: (.*)]/) { print $1 . "\n"; }'
  /lib64/ld-linux-x86-64.so.2

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20160224/a260cc2f/attachment.sig>


More information about the Libguestfs mailing list