> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/stratosphere-ve/ozone/llms.txt
> Use this file to discover all available pages before exploring further.

# qemu Package — QEMU Lifecycle API Reference

> API reference for the qemu package: Start() and Stop() functions for managing QEMU virtual machine lifecycle in Ozone.

The `qemu` package provides the runtime lifecycle interface for Ozone-managed virtual machines. It wraps `qemu-system-x86_64` invocations and process control behind two simple Go functions — `Start` and `Stop` — so that callers never need to construct raw command strings or manage process handles directly.

```go theme={null}
import "github.com/stratosphere-ve/ozone/qemu"
```

***

## qemu.Start()

```go theme={null}
func Start()
```

`Start` launches an interactive prompt asking for the name of the VM to start, then reads the corresponding configuration from `vms/<vmname>.json` via `vmparser.VMParser`. If the config file cannot be read, the function prints an error message and returns early.

On success, it prints the loaded VM info struct to stdout and spawns a `qemu-system-x86_64` subprocess with the following fixed command-line flags:

| Flag       | Value                              | Purpose                                                                                                 |
| ---------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `-machine` | `q35`                              | Selects the Q35 chipset (PCIe, IOMMU-capable)                                                           |
| `-m`       | *(empty string)*                   | Guest memory argument — sourced from the package-level `memsize` variable, which is initialized to `""` |
| `-smp`     | `4`                                | Configures 4 symmetric multi-processing vCPUs                                                           |
| `-drive`   | `file=myvm.qcow2,format=qcow2`     | Attaches the primary qcow2 disk image                                                                   |
| `-cdrom`   | `debian.iso`                       | Attaches a Debian installer ISO as a virtual CD-ROM                                                     |
| `-boot`    | `d`                                | Sets boot order to CD-ROM first                                                                         |
| `-qmp`     | `tcp:127.0.0.1:4444,server,nowait` | Opens a QMP control socket on localhost port 4444                                                       |

The full assembled command is:

```bash theme={null}
qemu-system-x86_64 \
  -machine q35 \
  -m "" \
  -smp 4 \
  -drive file=myvm.qcow2,format=qcow2 \
  -cdrom debian.iso \
  -boot d \
  -qmp tcp:127.0.0.1:4444,server,nowait
```

Any output from the QEMU process is captured and printed to stdout. If the subprocess exits with a non-zero status, the error is printed but execution continues. `Start` has no return value.

<Note>
  The package-level variable `memsize` is declared as `var memsize string = ""` and is not read from any configuration file. As a result, the `-m` flag is passed with an empty string value in the current implementation.
</Note>

<Tip>
  For a comprehensive reference on all `qemu-system-x86_64` command-line options — including alternative machine types, CPU models, network backends, and display drivers — see the [QEMU Options page on the Gentoo Wiki](https://wiki.gentoo.org/wiki/QEMU/Options).
</Tip>

***

## qemu.Stop()

```go theme={null}
func Stop()
```

`Stop` prints `"stopping qemu"` to stdout and then runs `system_powerdown` as a local subprocess via `exec.Command`. Any output from the process is captured and printed to stdout. If the command exits with a non-zero status, the error is printed to stdout. `Stop` has no return value.

<Warning>
  `Stop` does **not** send a QMP command to the running VM. It calls `exec.Command("system_powerdown")` as a standalone local process. Ensure that `system_powerdown` is present and executable in your `PATH` for this function to work as intended.
</Warning>
