How does Apple perform a lossless in-place conversion from HFS+ to APFS

apfshfs+

Since High Sierra, Apple has allowed users to do an in-place conversion of an existing HFS+ file systems to APFS without losing files. This can happen automatically during an OS upgrade or can be done by the user with Disk Utility.

My question is, how, technically, is this accomplished? I'm not asking how a user can do the conversion, I'm asking what actually happens on the disk during the conversion process. I've done some searches but have only found references to the fact that it can be done. This article provides some analogies, and I found some hints on how APFS allows easier resizing of partitions.

Does the software directly convert one file system to another on the fly? If APFS is basically an enhancement to HFS+ I can see this being easy, but my impression is that is not the case.

Does it create two partitions and slowly move content from one to the other, resizing as it goes, or create an image of the old system then restore it to the new system? It seems these would require a fair amount of free space, and could fail if the drive is full.

Something else?

Best Answer

It’s a four step process according to this article from The Ecletic Light Company

  1. Read and convert the existing HFS+ metadata (files, directories, etc) to APFS format; writes it to free space on the drive
  2. Verifies that the APFS data is correct
  3. If no errors, it writes the volume super block in APFS format
  4. It deletes the HFS+ meta data leaving just the APFS volume

It converts it a single piece at a time, updating the volume as it goes. This is why you need sufficient free space prior to the conversion process begins.