+ add_cmdline (g, "-no-reboot"); /* Force exit instead of reboot on panic */
+ add_cmdline (g, "-nographic");
+ add_cmdline (g, "-serial");
+ add_cmdline (g, "stdio");
+
+ /* These options recommended by KVM developers to improve reliability. */
+ if (qemu_supports (g, "-no-hpet"))
+ add_cmdline (g, "-no-hpet");
+
+ if (qemu_supports (g, "-rtc-td-hack"))
+ add_cmdline (g, "-rtc-td-hack");
+
+ /* If qemu has SLIRP (user mode network) enabled then we can get
+ * away with "no vmchannel", where we just connect back to a random
+ * host port.
+ */
+ if (null_vmchannel_sock) {
+ add_cmdline (g, "-net");
+ add_cmdline (g, "user,vlan=0,net=10.0.2.0/8");
+
+ snprintf (buf, sizeof buf,
+ "guestfs_vmchannel=tcp:10.0.2.2:%d", null_vmchannel_sock);
+ vmchannel = strdup (buf);
+ }
+
+ /* New-style -net user,guestfwd=... syntax for guestfwd. See:
+ *
+ * http://git.savannah.gnu.org/cgit/qemu.git/commit/?id=c92ef6a22d3c71538fcc48fb61ad353f7ba03b62
+ *
+ * The original suggested format doesn't work, see:
+ *
+ * http://lists.gnu.org/archive/html/qemu-devel/2009-07/msg01654.html
+ *
+ * However Gerd Hoffman privately suggested to me using -chardev
+ * instead, which does work.
+ */
+ else if (qemu_supports (g, "-chardev") && qemu_supports (g, "guestfwd")) {
+ snprintf (buf, sizeof buf,
+ "socket,id=guestfsvmc,path=%s,server,nowait", unixsock);
+
+ add_cmdline (g, "-chardev");
+ add_cmdline (g, buf);
+
+ snprintf (buf, sizeof buf,
+ "user,vlan=0,net=10.0.2.0/8,"
+ "guestfwd=tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT
+ "-chardev:guestfsvmc");
+
+ add_cmdline (g, "-net");
+ add_cmdline (g, buf);
+
+ vmchannel = "guestfs_vmchannel=tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT;
+ }
+
+ /* Not guestfwd. HOPEFULLY this qemu uses the older -net channel
+ * syntax, or if not then we'll get a quick failure.
+ */
+ else {
+ snprintf (buf, sizeof buf,
+ "channel," GUESTFWD_PORT ":unix:%s,server,nowait", unixsock);
+
+ add_cmdline (g, "-net");
+ add_cmdline (g, buf);
+ add_cmdline (g, "-net");
+ add_cmdline (g, "user,vlan=0,net=10.0.2.0/8");
+
+ vmchannel = "guestfs_vmchannel=tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT;
+ }
+ add_cmdline (g, "-net");
+ add_cmdline (g, "nic,model=" NET_IF ",vlan=0");
+
+#define LINUX_CMDLINE \
+ "panic=1 " /* force kernel to panic if daemon exits */ \
+ "console=ttyS0 " /* serial console */ \
+ "udevtimeout=300 " /* good for very slow systems (RHBZ#480319) */ \
+ "noapic " /* workaround for RHBZ#502058 - ok if not SMP */ \
+ "acpi=off " /* we don't need ACPI, turn it off */ \
+ "printk.time=1 " /* display timestamp before kernel messages */ \
+ "cgroup_disable=memory " /* saves us about 5 MB of RAM */
+
+ /* Linux kernel command line. */
+ snprintf (buf, sizeof buf,
+ LINUX_CMDLINE
+ "%s " /* (selinux) */
+ "%s " /* (vmchannel) */
+ "%s " /* (verbose) */
+ "%s", /* (append) */
+ g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
+ vmchannel ? vmchannel : "",
+ g->verbose ? "guestfs_verbose=1" : "",
+ g->append ? g->append : "");