[PATCH] inspect: check also /etc/hosts for detecting Linux root (RHBZ#1203898)
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)) { fs->is_root = 1; fs->format = OS_FORMAT_INSTALLED; if (guestfs_int_check_linux_root (g, fs) == -1) -- 2.5.0
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). If you want Linux then how about /lib/ld-linux.so.2 which exists on any Linux with ELF library support.
fs->is_root = 1; fs->format = OS_FORMAT_INSTALLED; if (guestfs_int_check_linux_root (g, fs) == -1)
Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
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
participants (2)
-
Daniel P. Berrange -
Pino Toscano