Keep a macOS disk between instances
Save the files, apps, and tools a macOS instance changed, and start the next instance from them.
A macOS instance starts from a clean disk, and deleting it discards everything you set up. A disk snapshot keeps every file the virtual machine changed since it started, including the home directory, installed apps, and tools, so the next instance starts where the last one stopped.
A snapshot is an asset of kind MacOSSnapshot. The instance saves it under a key you choose when it terminates, and a later instance restores it once it is ready. Snapshots need lim 0.65.1, @limrun/api 0.79.1, or Go SDK v0.15.0 or later.
Save and restore a disk snapshot
Create the instance with a snapshot key. The instance restores the snapshot saved under that key, if there is one, and saves its disk under the key when it terminates:
lim macos create --snapshot-key my-macconst mac = await lim.macosInstances.create({
wait: true,
spec: {
role: {
permissions: [
'asset:name/my-mac*:read',
'asset:name/my-mac:create',
'asset:name/my-mac:upload',
'asset:name/my-mac:update',
],
},
},
});
const guest = await lim.macosInstances.createClient({ instance: mac });
const result = await guest.restoreSnapshot({
key: 'my-mac',
onProgress: (p) => console.log(p.phase, p.doneBytes, p.totalBytes),
});
console.log(result.phase); // restored, skipped, or failedmac, err := client.MacosInstances.New(ctx, limrun.MacosInstanceNewParams{
Wait: param.NewOpt(true),
Spec: limrun.MacosInstanceNewParamsSpec{
Role: limrun.MacosInstanceNewParamsSpecRole{Permissions: []string{
"asset:name/my-mac*:read",
"asset:name/my-mac:create",
"asset:name/my-mac:upload",
"asset:name/my-mac:update",
}},
},
})
if err != nil {
panic(err)
}
guest, err := client.MacosInstances.CreateClient(*mac)
if err != nil {
panic(err)
}
defer guest.Close()
result, err := guest.RestoreSnapshot(ctx, macos.RestoreSnapshotOptions{
Key: "my-mac",
OnProgress: func(p macos.SnapshotProgress) {
fmt.Println(p.Phase, p.DoneBytes, p.TotalBytes)
},
})The instance’s role needs read on the asset names it restores and create, upload, and update on the name it saves under. The CLI adds these permissions for you; the SDKs take them in spec.role.permissions. The read permission ends in * because a restore also matches names that start with the key.
In the SDKs, call restoreSnapshot once the instance is ready and before you use the virtual machine. It sets the key the instance saves under and restores at most once per instance: a second call joins the restore already running, and a call after it finished returns its outcome without touching the disk. The CLI prints the restore’s progress and its outcome before lim macos create returns.
Restore from another snapshot
To start from a different snapshot than the one you save to, such as a shared base image or the snapshot of another branch, pass restore keys. They are tried in order, each by its exact name first and then by the newest snapshot whose name starts with it:
lim macos create --snapshot-key mac/feature-x --snapshot-restore-keys "mac/feature-x,mac/main,mac/base"await guest.restoreSnapshot({
key: 'mac/feature-x',
restoreKeys: ['mac/feature-x', 'mac/main', 'mac/base'],
});_, err = guest.RestoreSnapshot(ctx, macos.RestoreSnapshotOptions{
Key: "mac/feature-x",
RestoreKeys: []string{"mac/feature-x", "mac/main", "mac/base"},
})In the SDKs, grant read on each restore key’s names as well (asset:name/mac/main*:read, and so on). The CLI grants them from --snapshot-restore-keys.
Understand a skipped or failed restore
A snapshot restores only onto the macOS build it was saved on. A snapshot from another build is skipped and the next restore key is tried. When no restore key matches, or the restore fails, the instance starts with a clean disk, and the CLI prints why:
| Reason | Meaning |
|---|---|
no_match |
No snapshot matches the restore keys. |
compat_mismatch |
The snapshot was saved on another macOS build. |
checksum |
The downloaded snapshot did not match its checksum. |
disk_headroom |
The instance does not have enough free disk space. |
transport |
The transfer failed. |
extract |
Extracting the snapshot failed. |
restore_deadline |
The restore did not finish in time. |
not_eligible |
The instance is being deleted. |
In the SDKs, the final progress event carries the phase (restored, skipped, or failed) and this reason.
Wait for the save
Deleting the instance starts the save, and lim macos delete returns as soon as the deletion is accepted while the save continues in the background. To wait until the snapshot is published, and see each phase, pass --wait-snapshot:
lim macos delete --wait-snapshot
The save goes through requested, archiving, and uploading, and ends as published, skipped, failed, or timed_out. While it runs, status.snapshot.save on the instance holds its phase, and a reason and message when it did not publish.
Inspect and delete saved snapshots
List the snapshots your credential can read, newest first, and show one:
lim macos snapshot list --prefix mac/
lim macos snapshot get mac/main
snapshot get shows the snapshot’s asset ID, the macOS build it restores onto, its compressed and uncompressed size, its SHA-256, when it was saved, and the instance that saved it.
Delete a snapshot you no longer need. Deletion is permanent, and a running instance with that key saves it again when it terminates:
lim macos snapshot delete mac/feature-x