Mac mini
The Mac mini is the host of the three VMs and your daily workstation. This chapter takes it from the box to a machine that never sleeps, encrypts its disk, holds no secret outside 1Password, and can start and unlock its VMs with one command. No service is installed on macOS itself: only UTM, 1Password and this repository.
Set the Mac up as a new computer. Do not use Migration Assistant, so nothing from the old machine comes along unseen. The only things carried over are the ~/infra-migration folder from chapter 2 and what 1Password syncs.
Part A. The system
Section titled “Part A. The system”4.1 First start and your account
Section titled “4.1 First start and your account”Why. The account that logs in is the one that runs UTM, so the VMs live inside its session. Its password is the first secret of the new machine.
Mac
- Plug the Mac into the switch port prepared in step 3.5, with Ethernet only. Skip Wi-Fi in the setup assistant.
- Choose Set up as new. Sign in with your Apple Account.
- Create the account with the short name
macadmin. The LaunchAgent in step 4.11 uses that home folder path. - On your phone, in 1Password, create a login item
Mac loginin theInfrastructurevault with a generated password you can type (four or five random words), and use it as the account password. - Turn on Touch ID when offered, if your keyboard has it.
Verify. id -un in Terminal prints macadmin.
Rollback. Erase the Mac from System Settings > General > Transfer or Reset > Erase All Content and Settings and start over.
4.2 FileVault on, no automatic login
Section titled “4.2 FileVault on, no automatic login”Why. R5. The VM disk images sit in your home folder. FileVault is what protects them, and everything else, if the Mac is stolen. Automatic login cannot coexist with FileVault and would defeat it anyway.
Mac
sudo fdesetup statusIf it says FileVault is off: System Settings > Privacy & Security > FileVault > Turn On. Choose Create a recovery key and do not use my iCloud account. Type the key into a new 1Password item FileVault recovery key (vault Infrastructure, category password), then check it character by character.
In System Settings > Users & Groups, confirm Automatically log in as is Off.
Verify. sudo fdesetup status prints FileVault is On. and sudo fdesetup validaterecovery accepts the key copied from 1Password and prints true.
Rollback. sudo fdesetup disable. Not recommended: R5 depends on it.
4.3 A fixed address on the Trusted network
Section titled “4.3 A fixed address on the Trusted network”Why. Firewall policies name the Mac by address (10.0.5.3), and the address is set on the Mac itself so it never waits on the router at boot.
Mac System Settings > Network > Ethernet > Details > TCP/IP: Configure IPv4: Manually, address 10.0.5.3, subnet mask 255.255.255.0, router 10.0.5.1. Under DNS, add 10.0.5.1 for now. Step 6.11 changes it to the new resolver.
Or from Terminal:
networksetup -setmanual Ethernet 10.0.5.3 255.255.255.0 10.0.5.1networksetup -setdnsservers Ethernet 10.0.5.1networksetup -setairportpower Wi-Fi offWi-Fi stays off: a Mac on both Wi-Fi and Ethernet sits on two VLANs at once and confuses discovery.
UniFi Client Devices > the Mac mini > Settings: Fixed IP Address 10.0.5.3, and give it the name mac-mini, so the controller never hands that address to another device.
Verify.
ipconfig getifaddr en0 # 10.0.5.3route -n get default | grep gateway # 10.0.5.1networksetup -getairportpower Wi-Fi # OffIf the Ethernet port is not en0, networksetup -listallhardwareports shows its name. Use that name wherever this guide writes en0, including the UTM bridge in chapter 5.
Rollback. networksetup -setdhcp Ethernet.
4.4 Never sleep, come back after a power cut
Section titled “4.4 Never sleep, come back after a power cut”Why. A sleeping host freezes the VMs, and with them DNS and Home Assistant for the house.
Mac
sudo pmset -a sleep 0 disksleep 0 displaysleep 10 womp 1 autorestart 1 powernap 0Verify. pmset -g | grep -E ' sleep|autorestart|womp' shows sleep 0, autorestart 1 and womp 1.
Rollback. sudo pmset -a restoredefaults.
After a power cut the Mac starts by itself and stops at the FileVault login. Nothing runs until you log in. That is the cost of R5, and the reason for the UPS in chapter 2 and the second DNS server in step 6.11.
4.5 Updates only when you choose
Section titled “4.5 Updates only when you choose”Why. A macOS update restarts the Mac, and a restart stops the VMs until you log in and unlock them. You pick the moment.
Mac System Settings > General > Software Update > Automatic Updates: turn Install macOS updates off. Leave Install Security Responses and system files on, and Download new updates when available on.
Verify. defaults read /Library/Preferences/com.apple.SoftwareUpdate AutomaticallyInstallMacOSUpdates prints 0.
Rollback. Turn the option back on.
4.6 The macOS firewall
Section titled “4.6 The macOS firewall”Why. The Mac runs no service, so it should accept nothing it did not ask for. UTM’s bridge is not affected: the VMs’ traffic does not pass through the macOS firewall.
Mac
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onsudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode onLeave Remote Login and Screen Sharing off in System Settings > General > Sharing unless you administer this Mac from another one. If you turn them on, reach them through the admin VPN of step 10.11 only.
Verify. sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate prints enabled.
Rollback. --setglobalstate off.
Part B. Tools and secrets
Section titled “Part B. Tools and secrets”4.7 Homebrew, 1Password and its command line tool
Section titled “4.7 Homebrew, 1Password and its command line tool”Why. Same as step 2.1, on the new machine. Every later command that needs a secret reads it with op.
Mac
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"eval "$(/opt/homebrew/bin/brew shellenv)" && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofilebrew install --cask 1password 1password-cli utmbrew install git jqOpen 1Password and sign in. Settings > Security: Touch ID on. Settings > Developer: Integrate with 1Password CLI on, Use the SSH agent on. In the SSH agent’s settings, allow the Infrastructure vault: Settings > Developer > SSH Agent > Edit Automatically opens ~/.config/1Password/ssh/agent.toml. Make it read:
[[ssh-keys]]vault = "Infrastructure"Verify. op whoami prints your account after a Touch ID prompt, and op read "op://Infrastructure/LUKS infra/password" | wc -c prints 41.
Rollback. brew uninstall --cask utm 1password-cli 1password.
4.8 SSH through the 1Password agent
Section titled “4.8 SSH through the 1Password agent”Why. The private key made in step 2.4 never leaves 1Password. This file tells SSH to ask the agent, and gives each VM a short name.
Mac
mkdir -p ~/.ssh && chmod 700 ~/.sshcat > ~/.ssh/config <<'EOF'Host * IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
Host home HostName 10.0.5.2 User adminHost infra HostName 10.0.2.5 User adminHost standby HostName 10.0.6.2 User adminEOFchmod 600 ~/.ssh/configop read "op://Infrastructure/SSH mac-admin/public key" > ~/.ssh/mac-admin.pubVerify. SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock ssh-add -l lists one ED25519 key after a Touch ID prompt.
Rollback. Delete ~/.ssh/config.
4.9 The repository and the migration folder
Section titled “4.9 The repository and the migration folder”Why. The repository holds every file this guide installs. It lives on the Mac only: the VMs receive their files by rsync and never hold a GitHub credential.
Mac
- Add the public key to GitHub:
pbcopy < ~/.ssh/mac-admin.pub, then on github.com Settings > SSH and GPG keys > New SSH key, paste. - Clone, and set the two variables every chapter uses:
mkdir -p ~/PycharmProjects && cd ~/PycharmProjectsgit clone git@github.com:OWNER/infrastructure.gitcat >> ~/.zshrc <<'EOF'export INFRA=~/PycharmProjects/infrastructureexport U=/Applications/UTM.app/Contents/MacOS/utmctlexport PATH="$INFRA/mac/bin:$INFRA/scripts:$PATH"EOFsource ~/.zshrc- Copy
infra-migrationfrom the external disk of step 2.14 to~/infra-migration.
Verify. ls $INFRA/vm lists common home infra standby, which vm-up prints a path inside the repository, and ls ~/infra-migration/backups lists the files from chapter 2 (restore path only).
Rollback. Delete the folder and the three lines in ~/.zshrc.
Part C. UTM and the VM routine
Section titled “Part C. UTM and the VM routine”4.10 UTM and its permissions
Section titled “4.10 UTM and its permissions”Why. macOS asks before an application may reach the local network or control another application. Answering the prompts now, with you at the screen, avoids a VM that silently has no network after the first restart.
Mac
- Open UTM once. Accept the prompts.
- System Settings > Privacy & Security > Local Network: UTM must be on. The entry appears after the first VM starts with a bridged network (chapter 5). Come back to check it then.
- Run
$U list. macOS asks whether Terminal may control UTM: Allow.
Verify. $U list prints a header line (and no VM yet) with no error.
Rollback. brew uninstall --cask utm.
4.11 Start the VMs at login
Section titled “4.11 Start the VMs at login”Why. UTM has no start-at-login setting for a VM. A LaunchAgent runs vm-up when you log in. It starts infra first, because the others ask it for DNS, then home, then standby, all without a window.
Mac
cp $INFRA/mac/launchd/com.example.vm-up.plist ~/Library/LaunchAgents/launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.vm-up.plistThe first run asks whether bash may control UTM: Allow. The agent skips any VM that does not exist yet, so it is safe to install now.
Verify. launchctl print gui/$(id -u)/com.example.vm-up | grep -E 'state|last exit' shows last exit code = 0, and cat ~/Library/Logs/vm-up.log exists.
Rollback.
launchctl bootout gui/$(id -u)/com.example.vm-uprm ~/Library/LaunchAgents/com.example.vm-up.plist4.12 The routine: start, unlock, stop
Section titled “4.12 The routine: start, unlock, stop”Why. J14: each VM’s disk is encrypted with a passphrase that only 1Password holds. After every start of a VM somebody types it. vm-unlock does the typing, into the VM’s serial console, after one Touch ID. This step explains the three commands. You run them for real from chapter 5 on.
| Command | What it does | When |
|---|---|---|
vm-up |
Starts infra, home, standby in that order, hidden |
Runs by itself at login |
vm-unlock all |
Reads each passphrase from 1Password and types it at the disk prompt | After every login that follows a restart |
vm-down |
Asks each VM to shut down and waits until all are stopped | Before a restart, a macOS update, or quitting UTM |
A plain utmctl stop, quitting UTM or restarting the Mac cuts a VM’s power in the middle of a write. Always use vm-down first.
Unlocking by hand, if vm-unlock reports no prompt or you want to watch the boot:
vm-tty infra # prints the console device, for example /dev/ttys004screen "$(vm-tty infra)" # press Return: "Please unlock disk vda3_crypt:"In a second Terminal tab, op read "op://Infrastructure/LUKS infra/password" | pbcopy, then paste into screen and press Return. Leave screen with Ctrl-A, K, Y. If vm-tty prints nothing, read the path in UTM: select the VM, and look at Serial (TTY) in its details.
vm-unlock and vm-tty are new and were not run on hardware before this guide was written. The manual way above is proven. Step 5.13 tests the script on the first VM.
Verify. vm-unlock with no argument prints its usage line.
Rollback. None needed.
Result
Section titled “Result”The Mac has an encrypted disk, a fixed address on the Trusted network, no service of its own, and the tools to run VMs: UTM, the repository, 1Password with its SSH agent, and a login agent that will start the VMs. Next comes the base build that every VM shares.