APFS -> HFS+ During Imaging

wallis_isaac
New Contributor II

Hi all, we're looking at the possibility of having a script to convert an APFS drive to HFS+ before the block copy begins

We're having no luck with DEP, and the issues around account creation/authenticating, so I'm trying to figure this out.

I've got the following

#!/bin/sh
diskutil apfs deleteContainer /dev/disk0s2
diskutil eraseDisk JHFS+ "Nuked" /dev/disk0
echo | diskutil info disk0s2

When we type it by hand (in the 10.13 netboot environment) it works, but having it run as the first step in the configuration doesn't reformat it

Any ideas?

Running JSS 9.101
Target machine on 10.13, APFS

7 REPLIES 7

John_Wetter
Release Candidate Programs Tester

I guess my first question is 'why?' Is there a specific issue you're running in to with APFS? I'd be hard pressed to spend time going backwards at this point without a big win.

dakh7
New Contributor

instead of eraseDisk how about using partitionDisk? e.g.

diskutil partitiondisk disk0 1 GPTFormat JHFS+ "Macintosh HD" 100%

mconners
Valued Contributor

Hello @wallis.isaac have you considered installing high Sierra using where there is no APFS conversion? We use a command that essentially removes the APFS conversion.

/Applications/Install macOS High Sierra.app/Contents/Resources/startosinstall --applicationpath /Applications/Install macOS High Sierra.app --agreetolicense --converttoapfs NO --nointeraction

This will install High Sierra using a command where there is no interaction for the user, no APFS conversion and the license agreement is agreed to. As long as the path to the installer is the correct path, this should work well and of course, the installer is copied to the Mac in the first place.. In our limited testing, we have found this to work well.

Like many things with JAMF and Apple, there are a gazillion ways to do different things. Maybe this command will assist. I learned this from https://derflounder.wordpress.com/2017/09/26/using-the-macos-high-sierra-os-installers-startosinstall-tool-to-avoid-apfs-conversion/

Best of luck...

bvrooman
Valued Contributor

I would assume that this is in effort to image a Mac with a version of macOS prior to 10.13, but your NetBoot set is made with 10.13?

You mentioned typing the command by hand works; if you convert a partition to JHFS+ and then let Imaging do the block copy, does that result in an imaged disk which is formatted the way you want?

rhooper
Contributor III

Hello all,
I was wondering a question on this same line of thinking... I think.
We need to reimage all of our 1300+ devices this summer, installing the new 13.4 OS and wipe the drive with APFS.
We have a script that will install the "Install macOS High Sierra" app in the Applications folder, so that is no biggie. Just a Push out the install app and then a script to run the install script... but to wipe the drive then install the new OS has proven a hurdle I cannot seem to rectify. Any help with it would be greatly appreciated. We are using the script made by someone @ Jamf, but doctored a little to meet our needs, See below for the script. Thanks All,

~Hoop

!/bin/bash

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Copyright (c) 2017 Jamf. All rights reserved.

Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright

notice, this list of conditions and the following disclaimer in the

documentation and/or other materials provided with the distribution.

* Neither the name of the Jamf nor the names of its contributors may be

used to endorse or promote products derived from this software without

specific prior written permission.

THIS SOFTWARE IS PROVIDED BY JAMF SOFTWARE, LLC "AS IS" AND ANY

EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

DISCLAIMED. IN NO EVENT SHALL JAMF SOFTWARE, LLC BE LIABLE FOR ANY

DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND

ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# This script was designed to be used in a Self Service policy to ensure specific

requirements have been met before proceeding with an inplace upgrade of the macOS,

as well as to address changes Apple has made to the ability to complete macOS upgrades

silently.

REQUIREMENTS:

- Jamf Pro

- Latest Version of the macOS Installer (must be 10.12.4 or later)

- Look over the USER VARIABLES and configure as needed.

# For more information, visit https://github.com/kc9wwh/macOSUpgrade

# Written by: Joshua Roskos | Professional Services Engineer | Jamf

Created On: January 5th, 2017

Updated On: October 17th, 2017

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

USER VARIABLES

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Enter 0 for Full Screen, 1 for Utility window (screenshots available on GitHub)

userDialog=1

Specify path to OS installer. Use Parameter 4 in the JSS, or specify here

Example: /Applications/Install macOS High Sierra.app

OSInstaller="$4"

Version of OS. Use Parameter 5 in the JSS, or specify here.

Example: 10.12.5

version="$5"

Trigger used for download. Use Parameter 6 in the JSS, or specify here.

This should match a custom trigger for a policy that contains an installer

Example: download-sierra-install

download_trigger="$6"

Title of OS

Example: macOS High Sierra

macOSname=echo "$OSInstaller" |sed 's/^/Applications/Install (.*).app$/1/'

Title to be used for userDialog (only applies to Utility Window)

title="$macOSname Upgrade"

Heading to be used for userDialog

heading="Please wait as we prepare your computer for $macOSname..."

Title to be used for userDialog

description="
This process will take approximately 40-60 minutes.
Once completed your computer will reboot and begin the upgrade."

Description to be used prior to downloading the OS installer

dldescription="We need to download $macOSname to your computer, this will
take several minutes."

Icon to be used for userDialog

Default is macOS Installer logo which is included in the staged installer package

icon="$OSInstaller/Contents/Resources/InstallAssistant.icns"

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

SYSTEM CHECKS

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Check if device is on battery or ac power

pwrAdapter=$( /usr/bin/pmset -g ps )
if [[ ${pwrAdapter} == "AC Power" ]]; then pwrStatus="OK" /bin/echo "Power Check: OK - AC Power Detected"
else pwrStatus="ERROR" /bin/echo "Power Check: ERROR - No AC Power Detected"
fi

Check if free space > 15GB

osMinor=$( /usr/bin/sw_vers -productVersion | awk -F. {'print $2'} )
if [[ $osMinor -ge 12 ]]; then freeSpace=$( /usr/sbin/diskutil info / | grep "Available Space" | awk '{print $6}' | cut -c 2- )
else freeSpace=$( /usr/sbin/diskutil info / | grep "Free Space" | awk '{print $6}' | cut -c 2- )
fi

if [[ ${freeSpace%.} -ge 15000000000 ]]; then spaceStatus="OK" /bin/echo "Disk Check: OK - ${freeSpace%.} Bytes Free Space Detected"
else spaceStatus="ERROR" /bin/echo "Disk Check: ERROR - ${freeSpace%.*} Bytes Free Space Detected"
fi

Check for existing OS installer

if [ -e "$OSInstaller" ]; then /bin/echo "$OSInstaller found, checking version." OSVersion=/usr/libexec/PlistBuddy -c 'Print :"System Image Info":version' "$OSInstaller/Contents/SharedSupport/InstallInfo.plist" /bin/echo "OSVersion is $OSVersion" if [ $OSVersion = $version ]; then downloadOS="No" else downloadOS="Yes" ##Delete old version. /bin/echo "Installer found, but old. Deleting..." /bin/rm -rf "$OSInstaller" fi
else downloadOS="Yes"
fi

Download OS installer if needed

if [ $downloadOS = "Yes" ]; then /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$title" -alignHeading center -alignDescription left -description "$dldescription" -button1 Ok -defaultButton 1 -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/SidebarDownloadsFolder.icns" -iconSize 100 ##Run policy to cache installer /usr/local/jamf/bin/jamf policy -event $download_trigger
else /bin/echo "$macOSname installer with $version was already present, continuing..."
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

CREATE FIRST BOOT SCRIPT

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

/bin/mkdir /usr/local/jamfps

/bin/echo "#!/bin/bash

First Run Script to remove the installer.

Clean up files

/bin/rm -fdr "$OSInstaller"
/bin/sleep 2

Update Device Inventory

/usr/local/jamf/bin/jamf recon

Remove LaunchDaemon

/bin/rm -f /Library/LaunchDaemons/com.jamfps.cleanupOSInstall.plist

Remove Script

/bin/rm -fdr /usr/local/jamfps
exit 0" > /usr/local/jamfps/finishOSInstall.sh

/usr/sbin/chown root:admin /usr/local/jamfps/finishOSInstall.sh
/bin/chmod 755 /usr/local/jamfps/finishOSInstall.sh

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

LAUNCH DAEMON

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

cat << EOF > /Library/LaunchDaemons/com.jamfps.cleanupOSInstall.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict> <key>Label</key> <string>com.jamfps.cleanupOSInstall</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>-c</string> <string>/usr/local/jamfps/finishOSInstall.sh</string> </array> <key>RunAtLoad</key> <true/>
</dict>
</plist>
EOF

Set the permission on the file just made.

/usr/sbin/chown root:wheel /Library/LaunchDaemons/com.jamfps.cleanupOSInstall.plist
/bin/chmod 644 /Library/LaunchDaemons/com.jamfps.cleanupOSInstall.plist

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

APPLICATION

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Caffeinate

/usr/bin/caffeinate -dis &
caffeinatePID=$(echo $!)

if [[ ${pwrStatus} == "OK" ]] && [[ ${spaceStatus} == "OK" ]]; then ##Launch jamfHelper if [[ ${userDialog} == 0 ]]; then /bin/echo "Launching jamfHelper as FullScreen..." /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -title "" -icon "$icon" -heading "$heading" -description "$description" & jamfHelperPID=$(echo $!) fi if [[ ${userDialog} == 1 ]]; then /bin/echo "Launching jamfHelper as Utility Window..." /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$title" -icon "$icon" -heading "$heading" -description "$description" -iconSize 100 & jamfHelperPID=$(echo $!) fi

##Begin Upgrade /bin/echo "Launching startosinstall..." "$OSInstaller/Contents/Resources/startosinstall" --applicationpath "$OSInstaller" --nointeraction --pidtosignal $jamfHelperPID & /bin/sleep 3
else ## Remove Script /bin/rm -f /usr/local/jamfps/finishOSInstall.sh /bin/rm -f /Library/LaunchDaemons/com.jamfps.cleanupOSInstall.plist

/bin/echo "Launching jamfHelper Dialog (Requirements Not Met)..." /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$title" -icon "$icon" -heading "Requirements Not Met" -description "We were unable to prepare your computer for $macOSname. Please ensure you are connected to power and that you have at least 15GB of Free Space.

If you continue to experience this issue, please contact the IT Support Center." -iconSize 100 -button1 "OK" -defaultButton 1

fi

Kill Caffeinate

kill ${caffeinatePID}

exit 0

Yogini90
New Contributor

Hi All

I am trying to run below command to skip APFS in terminal during High Sierra installation but get error "No such file or directory". Could anyone advise what needs to be done ?

/Applications/Install macOS High Sierra.app/Contents/Resources/startosinstall --converttoapfs NO

cizdziem
New Contributor III

@Yogini90 , try the below...I'm thinking you may need to set the path to the installer via the --applicationpath flag:

/Applications/Install macOS High Sierra.app/Contents/Resources/startosinstall --applicationpath /Applications/Install macOS High Sierra.app --converttoapfs NO