How to Write an SD Card Image (Linux, Windows, Mac OSX)

sd-card

The question “How do I write a TS Image to an SD card under Linux / Mac OSX / Windows?” comes up quite a bit when dealing with embedded systems or any situation where you want to make an exact, bit-by-bit copy of a removable storage card or disk. While the following guide talks about our products, it can be applied generically. Read through it first to make sure you have a basic, core understanding of the instructions given, and then apply them to your situation. We’ll be looking at how to write to an entire disk and/or a specific partition on that disk using the dd command, a common utility found in most unix systems for low-level operations on hard disks. Jokingly, ‘dd’ stands for “disk destroyer” or “delete data”, so take care!      Home

If you are working with a Technologic Systems‘ product, please be sure to also see the product manual for specific instructions for that device.

Table of Contents

Linux

1.) The following commands will need to be executed as root. It’s popular to prefix the commands with ‘sudo’, but you can also become root by using the command (may vary depending on distribution) for Super User which will look for a [set] password entry:

su

2.) Plug in your SD card and then use the following command to see which /dev/ node it’s located on (be sure of this!):

fdisk -l

3.) Unmount the disk (using /dev/sda as example, verify with step 2):

umount /dev/sda*

4.) Use the dd command to copy the image file (ts-image.dd) to the entire disk:

dd if=ts-image.dd of=/dev/sda bs=1M conv=fsync

Note, bs=1M is telling dd to write 1 Mb block sizes at a time (faster write speeds this way) and conv=fsync is telling dd to flush data to the disk after every write.

As an example, say you have a separate kernel partition, you can write the image to the specific partition number:    Home

dd if=ts-kernel.dd of=/dev/sda1 bs=1M conv=fsync

Mac OSX

1.) Become root(Super User):

su

2.) Plug in your SD card and then use the following command to see which /dev/diskN node it’s located on:

diskutil list

3.) Unmount the disk where “N” is the number of the disk taken from the above command:

diskutil unmountDisk /dev/diskN

If the above command was successful, you will see:

Unmount of all volumes on diskN was successful

4.) Use the ddcommand to copy the image file (ts-image.dd) to the entire disk:

dd if=ts-image.dd of=/dev/diskN

Also, you can write the image to particular partitions of the disk with (N is the disk number and P is the partition number):

dd if=ts-kernel.dd of=/dev/diskNsP

The process to do this under Linux is very similar except that it’s not required to un-mount the drive before using the ddcommand and the commands are a little different. For example, you would use fdisk -linstead of diskutil list, your device node would be located at /dev/sda instead of /dev/disk and the un-mount command is umountinstead of diskutil unmountDisk.    Home

Windows

With Windows, you’ll need to search out some third party utilities to help. For example, here are some we’ve seen which work well:

  • https://sourceforge.net/projects/win32diskimager/
  • http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/
  • http://unetbootin.github.io/

You could also use a Linux virtual machine. VirtualBox is a nice, user friendly virtualization program and you can find ready-to-run Linux distributions easily online, such as Ubuntu on VirtualBoxes.org.     Home

3 thoughts on “How to Write an SD Card Image (Linux, Windows, Mac OSX)”

  1. Thanks for this quick guide, I always need a reminder, and I appreciate the explanation of the flags to dd!

    Another way to determine which device is the SD card on Linux is to run `lsblk`, which lists the devices, whether mounted or not (and is runnable by not-root). It should be easy to recognize the card by the size, and they usually start with “MMC”.

    I would recommend changing the example from “/dev/sda” to “/dev/mmcblk0”, since that’s more likely to be the device node, whereas sda is more likely to be the hard drive that the root partition is on – a less safe example!

Leave a Reply

Your email address will not be published. Required fields are marked *