APFS to HFS+ Netbook Script

Piggott
New Contributor

Hi Folks

We are trying to create a script that converts an APFS to HFS+ during a Netboot. The script we are using is below

590a26c3f35b4f0197d9d474931385d3

We can netboot and run the command from terminal however if we try and run the command from a script in JSS it does nothing.

Any help would be great.

5 REPLIES 5

wallis_isaac
New Contributor II

Just adding more info

The following doesn't work either

#!/bin/sh
diskutil apfs deleteContainer /dev/disk1s2 NewNuked

In Casper Imaging logs, all the scripts we have in the configuration have the following message (with the respective script names)

Downloading APFS_Nuke...
Could not download APFS_Nuke to the cache.

The script is set to run Before everything else in the config, and not on reboot

msw
Contributor

Not sure if anyone is still looking for this, but found the following script on the deploystudio forums

#!/bin/bash

convertDisk=$(diskutil list internal | grep -B 2 "APFS Container Scheme" | grep /dev | awk '{print $1}')

diskutil apfs deleteContainer "$convertDisk"

diskutil eraseDisk JHFS+ "Hard Disk" /dev/disk0

exit

I'm investigating in our environment and will post an update on how it goes.

msw
Contributor

Did my own testing. The above script almost works, but fails because following the deleteContainer step, /dev/disk0 ends up with a mounted partition called Untitled, and you can't format a mounted partition, obviously. Added 1 line and comments in case anything happening here isn't clear.

#!/bin/bash

# Script to delete APFS container on any devices delivered with or upgraded to 10.13 with an APFS conversion
# Script adapted from this forum http://www.deploystudio.com/Forums/viewtopic.php?id=8035

# Find and name APFS Container
convertDisk=$(diskutil list internal | grep -B 2 "APFS Container Scheme" | grep /dev | awk '{print $1}')

# Delete APFS Container
diskutil apfs deleteContainer "$convertDisk"

# Unmount disk0 partition
diskutil unmountDisk force /Volumes/Untitled

# Reformat as HFS+ and name
diskutil eraseDisk JHFS+ "Macintosh HD" /dev/disk0

exit

Note this is tested in current gen MacMinis, and I can't vouch for it on any other hardware, though I would expect behavior would be the same.

While the script does 'work' in the generic sense of the world, it didn't solve my problem, which is automating a downgrade of an APFS 10.13 Mac to HFS+ to install a 10.12-based image with Casper Imaging, as the disk you're targeting to image changes once the script runs. You can run the script manually and then follow the normal process, but running the script in casper imaging is a no-go.

dtmille2
Contributor III

@msw-sa and @Piggott did you ever find an automated way of converting a drive from APFS to HFS+ during a NetBoot?

msw
Contributor

@dtmille2 I didn't. Been working on doing device deployment with DEP instead of using Jamf Imaging and imaging over the wire. Since we do still have occasional scenarios where we need to downgrade an APFS 10.13 device to HFS+ for 10.12, I used Platypus to package the script above into a little standalone app, and then added that to the Desktop of my netboot.

Since we often have non-technical staff imaging, they can just double-click to run this, then launch Casper/Jamf Imaging, and proceed as usual. Obviously offered without any guarantees that it won't break your computer, but you're welcome to try it out (or just make the script above into your own app using Platypus).

https://nofile.io/f/kGFrDmZ1SxJ/Reformat+APFS.zip