Categories
armbian Raspberry Pi Software

The fastest way to clone an SD card on macOS

If you have a raspberry pi or other single board computer and would like to make a backup of it, or even clone it to another SD card, then it can take a long time. Your first thought is to probably use the built in “Disk Utility”. Unfortunately this has issues reading linux partitions (well in my experience) and is often slow. This simple command line trick will have you copying or cloning a full disk image of your SD card in record time!

WARNING: Be very careful when running any command with sudo dd in it. If you type any of the parameters incorrectly you may accidently erase or overwrite important data.

Requirements:

  • macOS running a recent version (this guide was tested on macOS Catalina).
  • basic knowledge of command line operations.
  • Make sure you’ve got homebrew installed. You can visit this link to find out how to download and install homebrew if you haven’t already got it.
  • After you’ve installed homebrew, you’ll need to install a package called core-utils. Do so by running brew install coreutils in your terminal. It should take a few minutes to run.

Identify your sd card:

You’ll need to find out which disk your SD card represents. You can run diskutil list and should see an output like below:

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +500.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD — Data     396.0 GB   disk1s1
   2:                APFS Volume Preboot                 81.9 MB    disk1s2
   3:                APFS Volume Recovery                528.5 MB   disk1s3
   4:                APFS Volume VM                      4.3 GB     disk1s4
   5:                APFS Volume Macintosh HD            11.0 GB    disk1s5

/dev/disk4 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.9 GB    disk4
   1:             Windows_FAT_32 boot                    268.4 MB   disk4s1
   2:                      Linux                         31.6 GB    disk4s2

From that output we can see that our SD card must be /dev/disk4 as our card is 32GB in size and has a fat32 and linux partition (standard for most raspberry pi images). You should add an r in front of disk4 so it looks like this /dev/rdisk4. The r means when we’re copying, it will use the “raw” disk. For an operation like this, it is much more efficient.

Copy the SD card as a disk image (dmg)

Now you should run the following command, replacing 4 with whatever number you identified as your sd card:

sudo gdd if=/dev/rdisk4 of=sd_backup.dmg status=progress bs=16M

Tip: you can experiment with different numbers for the block size by replacing bs=16M with larger or smaller numbers to see if it makes a difference to the speed. I’ve found 16M the best for my hardware.

You should see some progress feedback telling you the transfer speed. If you’d like to experiment with different block sizes, just type ctrl + c to cancel the command, then you can run it again.

Once the command has finished running, you’ll end up with a file in your home directory called sd_backup.dmg. If you’d like to backup multiple SD cards (or keep multiple backups!) simply replace sd_backup.dmg with a different file name. This will contain a complete disk image of your SD card. If you’d like to restore it, or clone it to another SD card, read on.

Copy the disk image (dmg) to your SD card

You’ll first need to unmount your SD card. Do not click the eject button in finder, but run this command, replacing 4 with whatever number you identified as your sd card sudo diskutil unmountDisk /dev/disk4.

Then to copy the image, run the following command:

sudo gdd of=/dev/rdisk4 if=sd_backup.dmg status=progress bs=16M

Tip: you can experiment with different numbers for the block size by replacing bs=16M with larger or smaller numbers to see if it makes a difference to the speed. I’ve found 16M the best for my hardware.

You should see some progress feedback telling you the transfer speed. If you’d like to experiment with different block sizes, just type ctrl + c to cancel the command, then you can run it again.

Once the command has finished running, your SD card should be an exact copy of the disk image you specified.

Categories
armbian

Connect to armbian (orange pi) without the IP

There are many reasons why you may not have a static IP configured for your orange pi/armbian installation.  Maybe it needs to be portable to different networks or your network doesn’t allow static IPs.  Whatever the reason it is a pain to find the IP, often you have to use a scanning tool like nmap.

We’re going to install a popular Linux implementation of zerconf.  These steps should work on any flavour of Ubuntu but I specifically used armbian on an orange pi zero.  It’s simple to install, just follow these steps:

Change your hostname from default

While not mandatory, it’s generally a good idea.  If another device running raspbian for example pops onto the network you’ll have two devices with the same hostname!  Edit /etc/hostname using the vim text editor (if you don’t know vim install it then type “vimtutor”):

sudo vim /etc/hostname

In that file you’ll see the current hostname, simply remove it and replace it with the new one.  Now edit the hosts file.  Make sure you replace every instance of the old hostname with the new one to make sure it resolves properly

sudo vim /etc/hosts

Now reboot your system to apply all of the changes.

sudo reboot

Install the Avahi Daemon

Something to note is most full versions of Ubuntu come with avahi-daemon installed out of the box, so give hostname.local a try first.  Simply type the following command and it’ll install avahi-daemon.  You shouldn’t need to restart but if it doesn’t work right away you know what to do.

sudo apt-get install avahi-daemon

In the case of my orange pi, after setting the hostname to “homeassistant” and installing the avahi daemon, it’s now accessible via homeassistant.local – much more convenient than an IP.