Pino Toscano
2016-Feb-24 14:43 UTC
[Libguestfs] [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
Use /etc/hosts instead 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. Put an empty /etc/hosts in all the phony Linux guests to keep them detected as we want. --- src/inspect-fs.c | 2 +- test-data/phony-guests/make-archlinux-img.sh | 1 + test-data/phony-guests/make-coreos-img.sh | 1 + test-data/phony-guests/make-debian-img.sh | 1 + test-data/phony-guests/make-fedora-img.pl | 1 + test-data/phony-guests/make-ubuntu-img.sh | 1 + 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 02fdb2a..82e1254 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -217,7 +217,7 @@ 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/hosts") > 0) { fs->is_root = 1; fs->format = OS_FORMAT_INSTALLED; if (guestfs_int_check_linux_root (g, fs) == -1) diff --git a/test-data/phony-guests/make-archlinux-img.sh b/test-data/phony-guests/make-archlinux-img.sh index 066df09..f748171 100755 --- a/test-data/phony-guests/make-archlinux-img.sh +++ b/test-data/phony-guests/make-archlinux-img.sh @@ -45,6 +45,7 @@ mkdir-p /var/lib/pacman/local/test-package-1:0.1-1 write /etc/fstab "/dev/sda1 / ext4 rw,relatime,data=ordered 0 1" touch /etc/arch-release +touch /etc/hosts write /etc/hostname "archlinux.test" upload $SRCDIR/archlinux-package /var/lib/pacman/local/test-package-1:0.1-1/desc diff --git a/test-data/phony-guests/make-coreos-img.sh b/test-data/phony-guests/make-coreos-img.sh index 1de2f25..e229926 100755 --- a/test-data/phony-guests/make-coreos-img.sh +++ b/test-data/phony-guests/make-coreos-img.sh @@ -76,6 +76,7 @@ write /etc/coreos/update.conf "GROUP=stable" upload archlinux.release /usr/share/coreos/lsb-release ln-s ../usr/share/coreos/lsb-release /etc/lsb-release write /etc/hostname "coreos.invalid" +touch /etc/hosts EOF diff --git a/test-data/phony-guests/make-debian-img.sh b/test-data/phony-guests/make-debian-img.sh index 637bd4b..0b4f75e 100755 --- a/test-data/phony-guests/make-debian-img.sh +++ b/test-data/phony-guests/make-debian-img.sh @@ -81,6 +81,7 @@ mkdir /var/log upload debian.fstab /etc/fstab write /etc/debian_version "5.0.1" write /etc/hostname "debian.invalid" +touch /etc/hosts upload $SRCDIR/debian-packages /var/lib/dpkg/status diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl index 192f48f..b1098ba 100755 --- a/test-data/phony-guests/make-fedora-img.pl +++ b/test-data/phony-guests/make-fedora-img.pl @@ -211,6 +211,7 @@ $g->write ('/etc/motd', "Welcome to Fedora release 14 (Phony)\n"); $g->write ('/etc/redhat-release', 'Fedora release 14 (Phony)'); $g->write ('/etc/fedora-release', 'Fedora release 14 (Phony)'); $g->write ('/etc/sysconfig/network', 'HOSTNAME=fedora.invalid'); +$g->touch ('/etc/hosts'); if (-f "fedora.mdadm") { $g->upload ("fedora.mdadm", '/etc/mdadm.conf'); diff --git a/test-data/phony-guests/make-ubuntu-img.sh b/test-data/phony-guests/make-ubuntu-img.sh index a3aa610..b49e8ff 100755 --- a/test-data/phony-guests/make-ubuntu-img.sh +++ b/test-data/phony-guests/make-ubuntu-img.sh @@ -72,6 +72,7 @@ upload ubuntu.fstab /etc/fstab write /etc/debian_version "5.0.1" upload ubuntu.release /etc/lsb-release write /etc/hostname "ubuntu.invalid" +touch /etc/hosts upload $SRCDIR/debian-packages /var/lib/dpkg/status -- 2.5.0
Pino Toscano
2016-Feb-24 16:31 UTC
Re: [Libguestfs] [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
On Wednesday 24 February 2016 15:43:40 Pino Toscano wrote:> Use /etc/hosts instead 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. > > Put an empty /etc/hosts in all the phony Linux guests to keep them > detected as we want. > ---Discard this version, I'll send a more safe version. -- Pino Toscano
Roman Kagan
2016-Feb-24 17:05 UTC
Re: [Libguestfs] [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
On Wed, Feb 24, 2016 at 03:43:40PM +0100, Pino Toscano wrote:> Use /etc/hosts instead 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.IMHO /etc/hosts is just as unreliable as /etc/fstab. I'd rather test for /bin/sh being present and being an ELF executable or shared object. Roman.
Pino Toscano
2016-Feb-24 17:09 UTC
Re: [Libguestfs] [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
On Wednesday 24 February 2016 20:05:35 Roman Kagan wrote:> On Wed, Feb 24, 2016 at 03:43:40PM +0100, Pino Toscano wrote: > > Use /etc/hosts instead 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. > > IMHO /etc/hosts is just as unreliable as /etc/fstab. > > I'd rather test for /bin/sh being present and being an ELF executable or > shared object.That won't work with recent Fedora/RHEL/CentOS systems due to the UsrMerge: if /usr is in a separate partition, /bin/sh "exists" there too, and thus that partition would be detected as root. -- Pino Toscano
Richard W.M. Jones
2016-Feb-25 09:04 UTC
Re: [Libguestfs] [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
On Wed, Feb 24, 2016 at 05:31:06PM +0100, Pino Toscano wrote:> On Wednesday 24 February 2016 15:43:40 Pino Toscano wrote: > > Use /etc/hosts instead 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. > > > > Put an empty /etc/hosts in all the phony Linux guests to keep them > > detected as we want. > > --- > > Discard this version, I'll send a more safe version.What about /etc/services? That's been available on every Unix since 4.2BSD (released in 1983). On Fedora it's part of the 'setup' package. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Seemingly Similar Threads
- Re: [PATCH] inspect: use os-release for CoreOS
- [PATCH 1/2] test-data: phony-guests: Don't use *.tmp.* temporary files.
- Re: [PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
- [PATCH v4 01/17] tests: Introduce test harness for running tests.
- Re: [PATCH] inspect: check also /etc/hosts for detecting Linux root (RHBZ#1203898)