Skip to content

Conversation

@trinitronx
Copy link

@trinitronx trinitronx commented May 6, 2025

This PR incorporates and supercedes #259

Changes

  • Enable TRIM support for the macOS hard drive image.
  • Prevent qcow2 image ballooning with discard=unmap,detect-zeroes=unmap
  • Document qcow2 + macOS SSD TRIM support further
  • Consolidate rotation_rate=1 into device args

solemnwarning and others added 4 commits April 5, 2025 11:07
We need to tell macOS the emulated drive is an SSD *and* run `trimforce enable`
in the guest because we can't emulate a specific (i.e. Apple-approved) drive.
To prevent the `qcow2` image file from inevitably ballooning or expanding on the
host, we need to tell qcow2 image format block driver to unmap on discard/TRIM.

Due to how `qcow2` sparse images integrate with SSD TRIM (a.k.a. "`discard`"),
we also must set `discard=unmap`, and `detect-zeroes=unmap`.

However, these parameters are usually specified on the block device, so we must
fallback to the more declarative `-blockdev ...` + `-device ...` form of QEMU
CLI args to specify them [^1].  For example:

```console
  # need to specify 'discard=unmap, detect-zeroes=unmap' on blockdev
  -blockdev driver=qcow2,node-name=MacHDD,file.driver=file,file.filename="$REPO_PATH/mac_hdd_ng.img",file.aio=threads,discard=unmap,detect-zeroes=unmap
  -device ide-hd,bus=sata.4,drive=MacHDD,id=macssd,rotation_rate=1
```

[^1]: See: [_QEMU User Documentation: Block device options_][1] or `man qemu` "_Block device options_" section:

> The  most  explicit  way  to describe disks is to use a combination of
> `-device` to specify the hardware device and `-blockdev` to describe the
> backend. The device defines what the guest sees and the backend describes how
> QEMU handles the data. _**It is the only guaranteed stable interface for
> describing block devices and as such is recommended for management tools and
scripting**_.
> The `-drive` option combines the device and backend into a single command line
> option which is a more human friendly. There is however
> _no interface stability guarantee_ although some older board models still need
> updating to work with the modern `blockdev` forms.

Signed-off-by: James Cuzella <[email protected]>
Suggested-by: Daniel Collins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants