9

I own a Mac Mini 2014 running Big Sur. I've developed a program and I would like to test it in a "clean" environment, like the first day I've purchased the Mac. In particular, the frameworks that I've installed for development must not be present, or they must be "hidden" to the program. These frameworks are XCode and .NET for MacOS.

Is there a way to achieve this on my own machine, without uninstalling all the things? Does creating a new user is a solution (consider that .NET should have been installed at system -not user- level)? Or is there like a "sandbox" mode for this purpose?

1
  • 10
    Install a fresh version of macOS on an external drive and boot from it. Or use a VM.
    – nohillside
    Commented Nov 15, 2021 at 22:20

3 Answers 3

13

If you're okay with rebooting, you can do this easily without using virtual machines:

  1. Open Disk Utility and select your Macintosh HD on the sidebar.
  2. Click the [+] Volume button in the toolbar and enter a disk name of your choosing
  3. Download the macOS Monterey / Big Sur installer and run it, selecting your new volume
  4. When rebooting, hold option (Intel) or keep pressing the power button (Apple Silicon) to choose which volume to run.
3
  • 4
    This approach is straightforward, and APFS logical volume management is excellent. That being said, if you truly need a deterministic, clean install for every test run, the abstractions provided by a VM will save you a lot of time and work.
    – jsejcksn
    Commented Nov 17, 2021 at 0:32
  • @jsejcksn: Is is possible to create a snapshot and then if necessary revert back to the snapshot? Or, would this require a separate APFS container as suggested by Harper - Reinstate Monica's answer. Commented Nov 17, 2021 at 13:00
  • @DavidAnderson If by "revert back to the snapshot" you mean booting into Recovery Mode and using the Restore from Time Machine Backup option, then I don't think a separate APFS container is necessary: in addition to choosing the specific snapshot, one of the options in the restore dialog involves choosing a volume.
    – jsejcksn
    Commented Nov 17, 2021 at 13:35
10

The easiest method is probably to install a virtual machine with a clean macOS install and test your software from there. You'll need virtualization software such as VMware Fusion or Parallels Desktop (both requires a paid license) or VirtualBox (free alternative).

2
  • 1
    Technically, all three have licenses. Parallels requires a purchase after 14 days. VMware Fusion Player does offer a free for Personal Use license as well as versions requiring a purchase. VirtualBox does not require a purchase. Also, VirtualBox does not officially support Big Sur, while VMware Fusion Player does. Commented Nov 17, 2021 at 12:52
  • 1
    Sure, if you want to be pedantic then yes - all software have licenses. However, I specifically wrote that it is a "free alternative", so that @TheUnexpected could see that the others are a non-free alternative. They have included various optimizations for Big Sur in later releases, but YMMV. The commercial options generally work better.
    – jksoegaard
    Commented Nov 17, 2021 at 13:28
1

Macs can boot an external USB fob.

Super easy. Get any respectable USB "fob" and format it in Disk Utility. Then run the OS installer and tell it to install on the USB fob.

When it comes time in the installation to reboot the Mac, hold down "option" to tell it. you want to pick the boot volume. Pick the external USB fob that you just installed the OS on. Now you will boot off that.

Now run Software Update and patch to the latest patch level for that version of the OS. (you can even upgrade to more modern OS if your hardware supports it).

Dismount your other boot volumes so they aren't corrupted

There is one wrinkle: your internal/main hard drive or SSD will now be visible as an auxiliary drive. That can sometimes cause complications with applications; for instance iTunes and Photos will go on a grand "fishing expedition" looking for iTunes libraries and Photos/iPhoto libraries on non-boot drives, will find your main drive's libraries, and corrupt them.

You can make sure that never happens by following the steps given in the next section to establish an fstab to automatically dismount every boot volume but this one. Now when you boot your external fob, your internal hard drive will NOT be mounted and will not be visible. You can "bring it back" manually by launching Disk Utility and mounting it.

All my boot volumes have the same exact fstab, which dismounts all my boot volumes. (the active volume fails to dismount itself).

Prevent a volume from mounting at startup

The text below was authored by by user etresoft at Apple Community. The suggestion offered by user hyphen was incorporated into the text.

Sometimes, it can be useful to prevent a given volume from mounting at boot. You might want to hide an old OS version from Spotlight corruption. You just might not want to clutter your desktop.

Note: Encrypted disks are unlocked before the fstab file is read. In order for this procedure to work with an encrypted disk, you must first mount the disk, unlock it, and save the password in your keychain.

To do this, you will need basic understand of how to enter Terminal commands and use vi.

  1. Make sure the disk you want to prevent mounting at boot is mounted.

  2. Launch Terminal.

  3. Run the following command to print out information about the disk:

    diskutil info /Volumes/<volume that shouldn't be mounted>
    
  4. Locate the line that starts with: Volume UUID:. Select the UUID (Universal Unique Identifier) that follows on the rest of the line. It will be something that looks like FF9DBDC4-F77F-3F72-A6C2-26676F39B7CE. Your value will be different

  5. Copy the UUID to the clipboard.

  6. Navigate to /etc by typing the following and pressing enter:

    cd /etc
    
  7. Edit (or create) an fstab file by typing the following and pressing enter:

    sudo vifs
    
  8. Enter the following line, substituting the UUID you copied in step 5. (Note: vifs uses the value of the EDITOR environment variable to pick the text editor to use. This article assumes you are using the default value of vim.) In vim, the editor starts in command mode. To add a new line, use the arrow keys to move to the end of the document and press the o key to append a new line and enter edit mode. Then type the following:

    UUID=FF9DBDC4-F77F-3F72-A6C2-26676F39B7CE none apfs rw,noauto
    

    and press the return key.

  9. Type escape to return to command mode and then type ZZ (shift key down) to save and exit vifs (or some other method to save and exit if you are using something other than vim).

  10. Type the following and press enter to reset the auto mounter:

    sudo automount -vc
    
  11. Quit Terminal

Now, the next time you restart, or unplug the drive in the case of an external drive, that volume will not be mounted. All you have to do is launch Disk Utility, select the grey, disabled volume, and click the Mount button.

You should be able to use a different text editor than vifs if you want. It needs to be able to edit and save files owned by root.

Note: If all of your disks are encrypted, there is an easier method. For any disk that you don't want to automatically mount, simply don't save the password to the keychain.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .