How does "xcrun simctl runtime add <path>" command work?

After I downloaded Xcode 15, I use the following approach to download and install iOS 17 simulator:

  • Download iOS 17.0 simulator runtime from Apple website

  • Then run xcrun command to install it:

    $ xcrun simctl runtime add iOS_17_Simulator_Runtime.dmg

(BTW, I can't install iOS simulator from within Xcode directly because downloading the image always failed. I have a fast Internet connection. The issue seems to be intermittent connection failure.)

The iOS simulator was installed successfully. However, I find the behavior of xcrun command is very confusing. Below is what I observed.

First this is xcrun command output:

$ xcrun simctl runtime add iOS_17_Simulator_Runtime.dmg
D: EEF873B8-E0E6-4A0E-9A1E-C4C7E6D3BE1A iOS (17.0 - 21A328) (Ready)

I suspect the output means it mounted the img somewhere. However, I can't find that disk in Finder. I checked the manually page and found the following:

add <path> [-ma]
     Add a runtime disk image to the secure storage area. The image will be staged, verified, and mounted.
     When possible the image file will be cloned so no additional disk space will be used.
     If stdout is a terminal and a copy is required then progress will be reported.

I wonder what's that "secure storage area"? Is that the reason why I can't see the disk?

What's more confusing is that, shortly after the xcrun command completed, a GUI message box popped up, displaying a messsage "Verifying iOS 17.0.simruntime". This took a while. Then the message box disappeared and nothing more happended. At this time I opened Xcode and verified iOS similator was installed indeed.

I monitored disk IO during the entire process. I observed a lot of read ops but few write ops, which is odd. I understand why there were many read ops, but I expected the same amount of write ops also. Is it due to COW, plus the fact that the image is mounted rather than uncompressed?

The manual says "The image will be staged, verified, and mounted." I wonder what does "staged" mean in this case? Also, the mannual says the image is mounted. So my first thought was that I shouldn't move or delete the image file I downloaded. Then I noticed the manual also says "When possible the image file will be cloned so no additional disk space will be used." So I think it's OK to delete the image file? I'd like to confirm my understanding first so I haven't tried it yet.

Thanks for any explanation.

If Apple wanted us to know, they would have open-sourced the platform or documented it.

Hmm...I think my question is a basic user question and understanding it helps me (and perhaps other users) better use Apple's technologies. I understand it's Apple's culture to not disclose its product details, but it's bad that the culture is often used as an excuse. Anyway I have deleted the simulator image file I downloaded and Xcode works fine (it would be absurd if it didn't). I compared "df -m" output on my MBP before and after I deleted the file. There is little change (as expected).

So I believe my understanding is correct. The downloaded image was cloned and mounted by "xcrun simctl runtime add" command. That's the reason why I didn't observe many write ops when running xcrun command. BTW, the GUI message box that popped up after xcrun completed is bad UX. It's confusing.

My observation of this simulator installation process suggests:

  • "Staged" means that the file is being copied to a temporary location so that the rest of the installation can proceed using the copy, unaffected by what happens to the downloaded file later.

  • "Mounted" likely refers to an internal step of mounting the disk image file to process its contents. I don't think you should expect anything to be visible in the Finder while it's mounted.

  • "Verification" means that Xcode is verifying the installation after the file has been copied from the staging area to its final location.

  • If you have downloaded the file yourself, I wouldn't expect any significant file writing activity during execution of xcrun simctl runtime add, because any copies it makes use APFS to clone the file. Copying files in disk volumes using APFS is basically instant, because the file system doesn't actually need to copy the file contents. That's the significance of the "cloned" comment in the text of the command's output.

Note that, apparently, there are 2 copy operations on your downloaded file: one from the download location to the staging location, and a second one from the staging location to the final location that Xcode expects. (At least, we can deduce that the second one is a copy, because it's fast. If data was extracted from the file and re-written at that point it'd be much slower.)

Having said all that, I'll point out that I'm basing this on general knowledge about file systems on macOS, not on any specific knowledge of the internals of the installation process.

I have the same question when I tried to airdrop the simulator from one Mac to another (don't want to download it again)

$ xcrun simctl runtime list
== Disk Images ==
-- iOS --
iOS 17.4 (21E213) - 72E27A4C-7B41-448C-B18A-0A1F7EC9590C (Ready)

Total Disk Images: 1 (6.7G)

I found the directory where the simulator runtime stores:

/Library/Developer/CoreSimulator/Volumes

I opened it in Finder but I can't airdrop that folder as it's a mount point

$ mount
/dev/disk3s1s1 on / (apfs, sealed, local, read-only, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
/dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
/dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
/dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
/dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect, root data)
map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
/dev/disk9s1 on /Library/Developer/CoreSimulator/Volumes/iOS_21E213 (apfs, local, nodev, nosuid, read-only, journaled, noowners, noatime, nobrowse)

I guess the block device "/dev/disk9s1" is the result of "cloned, staged, verified" by the command xcrun simctl runtime add and then it was mounted at /Library/Developer/CoreSimulator/Volumes/iOS_21E213

How does "xcrun simctl runtime add &lt;path&gt;" command work?
 
 
Q