raw Software
RAW Software Administration Linux Provisioning

Flash a Linux Image to an SD Card on macOS

Robert Eisele

A raw Linux disk image can be written to an SD card from the macOS command line with diskutil and dd. This is useful for Raspberry Pi OS and other embedded Linux distributions that publish an .img file.

Warning: dd overwrites the selected device without confirmation. Substituting the wrong disk identifier can destroy the contents of another drive. Verify the device name, capacity, and removable status immediately before writing.

1. Prepare and Verify the Image

Decompress the download when necessary. Keep the original archive until the new card has booted successfully.

xz -dk raspberry-pi-os.img.xz

For a ZIP archive, inspect its contents and extract the image:

unzip raspberry-pi-os.zip

Compare the image checksum with the value published by the distribution:

shasum -a 256 raspberry-pi-os.img

An ISO file is not interchangeable with a board-specific raw image. Renaming or converting an installer ISO does not make it suitable for a Raspberry Pi. Use the image format required by the target hardware; only write an ISO directly when that platform's documentation explicitly identifies it as a bootable hybrid image.

2. Identify the SD Card

Insert the card and list external physical disks:

diskutil list external physical

Replace diskN in the remaining commands with the identifier shown for the complete SD card, such as disk2. Do not select a partition such as disk2s1. Inspect the candidate once more:

diskutil info /dev/diskN

Confirm that its capacity, protocol, device location, and removable status match the inserted card.

3. Unmount and Write the Image

Unmount every mounted volume on the card without ejecting the device:

diskutil unmountDisk /dev/diskN

Write the image to the raw device. The r in rdiskN selects macOS's faster raw character-device interface:

sudo dd if=raspberry-pi-os.img of=/dev/rdiskN bs=4m status=progress

Wait for dd to finish and return to the shell prompt. Do not remove the card while the command is running. On older macOS versions whose dd lacks status=progress, omit that option and press Ctrl+T to request a progress report.

4. Flush and Eject the Card

Flush pending writes, then eject the complete disk:

sync
diskutil eject /dev/diskN

Remove the card only after macOS reports that the disk was ejected. The card can then be inserted into the target device for its first boot.