+ /* Sort by key length, shortest key first, so that we end up
+ * mounting the filesystems in the correct order.
+ */
+ qsort (mps, count_strings (mps) / 2, 2 * sizeof (char *),
+ compare_keys_len);
+
+ for (j = 0; mps[j] != NULL; j += 2) {
+ printf ("mount %s /sysroot%s\n", mps[j+1], mps[j]);
+ free (mps[j]);
+ free (mps[j+1]);
+ }
+
+ /* If it's Linux, print the bind-mounts. */
+ if (type && STREQ (type, "linux")) {
+ printf ("mount --bind /dev /sysroot/dev\n");
+ printf ("mount --bind /dev/pts /sysroot/dev/pts\n");
+ printf ("mount --bind /proc /sysroot/proc\n");
+ printf ("mount --bind /sys /sysroot/sys\n");
+ }
+
+ printf ("\n");
+
+ free (type);
+ free (distro);
+ free (product_name);
+ free (roots[i]);
+ }
+
+ free (roots);
+}
+
+/* Inspection failed, so it doesn't contain any OS that we recognise.
+ * However there might still be filesystems so print some suggestions
+ * for those.
+ */
+static void
+suggest_filesystems (void)
+{
+ char **fses;
+ size_t i;
+
+ fses = guestfs_list_filesystems (g);
+ if (fses == NULL)
+ exit (EXIT_FAILURE);
+
+ if (fses[0] == NULL) {
+ printf (_("This disk contains no filesystems that we recognize.\n\n"
+ "However you can still use virt-rescue on the disk image, to try to mount\n"
+ "filesystems that are not recognized by libguestfs, or to create partitions,\n"
+ "logical volumes and filesystems on a blank disk.\n"));
+ return;
+ }
+
+ printf (_("This disk contains one or more filesystems, but we don't recognize any\n"
+ "operating system. You can use these mount commands in virt-rescue (at the\n"
+ "><rescue> prompt) to mount these filesystems.\n\n"));
+
+ for (i = 0; fses[i] != NULL; i += 2) {
+ printf (_("# %s has type '%s'\n"), fses[i], fses[i+1]);
+
+ if (STRNEQ (fses[i+1], "swap") && STRNEQ (fses[i+1], "unknown"))
+ printf ("mount %s /sysroot\n", fses[i]);
+
+ printf ("\n");
+
+ free (fses[i]);
+ free (fses[i+1]);
+ }
+ free (fses);