How to Write, Format and Manage an SD Card in Linux

Bertel King 15-03-2016

SD cards play a special role for Linux desktop users. Yes, they serve as a way to store photos or video and get both onto your hard drive. They also provide a simple way to expand how many files you can carry about on a laptop. But in many cases, these little squares of portable storage are what you need to turn your Windows or Mac OS X machine into a Linux box in the first place 3 Ways to Install Linux on Windows or Mac Read More .


With SD cards solving so many problems, it’s important that you know how to manage them. Mistakes can happen, and they tend to result in losing data. No one wants that.

There are multiple ways to configure your SD cards, either from the command line or using a handful of graphical applications. Here’s how you do it.

What Is a Partition Manager?

A partition is a region of digital storage space. This can be your entire hard drive, but this isn’t always the case. Dual booters will have a portion dedicated to whichever Linux distribution is installed, and another allocated to Windows. Some use partitions to keep their operating system separate from their personal files. Usually there’s also a separate partition for swap What Is a Linux Swap Partition? Everything You Need to Know Most Linux installations suggest you include a swap partition. What is a swap partition for? Here's what you need to know. Read More .

A partition editor is a tool for managing these partitions. These are what you use to format SD cards, create new partitions, or make duplicates.

SD cards typically come with one partition, but you can break a 32GB card into two 16GB ones if you desire.


Here you can see the 2GB card I’ve inserted into my computer.


Memory cards are commonly assigned a simple device name like /dev/sda, /dev/sdb, or /dev/sdc. That’s not always the case. Above, I’m being shown the significantly longer /dev/mmcblk0p1. If I were to use the command line, as I will explain later, this is the location I would enter.

Another way to find the name is by entering into the terminal:


You will get a long list of results, so this approach is recommended for people who already have some idea of what they’re looking for. Even then, I typically prefer to fire up whichever partition manager comes pre-installed.

Some desktop environments and distributions come with their own partition editors. GNOME Disks (pictured above) integrates with the GNOME 3.x desktop,while KDE users may want the KDE Partition Manager. Many distributions still use GParted GParted - The Ultimate In Partitioning Software Read More . All essentially do the same thing.

If you’re looking for a single piece of software that doesn’t require installing additional software and works across Linux distributions, dd is your best bet. This command line tool makes backing up your SD card and writing an image a straightforward, one-line task. But you need to be careful, because the wrong command can wipe the contents of your entire hard drive 9 Lethal Linux Commands You Should Never Run You should never run a Linux command unless you know exactly what it does. Here are some of the deadliest Linux commands that you'll, for the most part, want to avoid. Read More .

Format an SD Card

Partition editors will generally give you an option to select a partition and format it into a new one. If you want to give away or recycle a card, you can opt to thoroughly erase all of its contents. This process takes a while, so if you’re merely looking to clear the data on a card so that you can put more stuff on it or intend to turn it into a bootable Linux drive, choosing the faster option is fine.


You have to choose a partition type when you do this. The FAT format will work across various desktop operating systems, and this is how most SD cards begin their life. Chances are, that is the option you want.


To wipe a card using the command line, we turn to dd. The command below will wipe all data from your card and replace it with zeroes. It’s not impossible to recover data erased this way, but most people won’t be able to.

dd if=/dev/zero of=/dev/sdc

In dd commands, the if parameter determines the source of the data. The of indicates the destination. Here, we’re copying zeroes onto /dev/sdc. Replace this with whatever location your computer assigns your card, as mentioned above.


After running this command, you may need to create a new partition. Maybe even two.

Create a Separate Partition

Creating a separate partition out of one you’re currently using is a risky way to lose data, though you can try doing so using a GParted Live CD The GParted Live CD: A Quick Way To Edit Your Primary Partitions [Linux] Edit your partitions from outside your operating system. The GParted Live CD is a simple Linux distro you can use to change the size of your partitions – or wipe a drive entirely. Built around... Read More . To play it safe, back up your data and start fresh. Erase your current partition either by tapping the icon or selecting the option from a menu. Then tap the + icon or select the option to create a new one.

Instead of using all of the available space, choose a new amount. Here I’m laying down the foundation for two partitions of the same size.


Repeat this process for as many partitions as you want to create.

If you want to do this from the command line, you can turn to fdisk to make the magic happen Take Control of Linux Disk Partitions with These 10 fdisk Commands While desktop disk management tools are also available for Linux distros (such as the Disk Utility in Ubuntu), using the fdisk command line tool offers more options. Read More .

Back up an SD Card

The most straightforward way to back up your SD card is to open a file manager and copy over the files into a folder on your computer. Personally, that’s all I feel the need to do. But this method admittedly isn’t the best if you’re looking to make identical copies or store numerous backups.

In that case, you want to create a partition image. Changes are, you can find this option in your partition editor.


To do the same thing using dd, you will open a terminal and enter a line that looks like this.

dd if=/dev/sdc of=sdcard.img

The command above backs up the contents of your SD card to an .img file in your home folder, allowing you to restore an identical copy later on. You need to have as much free space on your hard drive as the size of the SD card, meaning a 32GB card will consume 32GB on your computer. Waiting for the task to complete can take a while, and it will look like dd has stopped working. Just be patient.

Restore a Backup Image

When you’re ready to restore your SD card, you will simply flip the two destinations in dd.

dd if=sdcard.img of=/dev/sdc

In a partition editor, you use the option to restore an image. This will prompt you to select an image you’ve previously created to write to your SD card.


Create a Bootable SD Card

To boot Linux from an SD card using dd, first download the image of the Linux distribution you’re looking to test or install. Then insert the path to that file as the if parameter, just as you would when restoring an SD card. For example:

dd if=/home/user/Downloads/parabola-2015.11.11-dual.iso of=/dev/sdc

This is the last of the dd commands I’m covering here. Just know, dd is powerful enough to clone your entire hard drive, even if you’re moving terabytes of data. When you’re ready to tackle more advanced commands, you can find a list over on the dd Wikipedia page. But again, be careful. You do not want to enter these in a hurry.

If you want to avoid the command line, search your distribution’s package manager for a live USB stick creator. Ubuntu has the Startup Disk Creator. Fedora has the Live USB Creator. These and other distributions work with UNetbootin How To Install Linux With Ease Using UNetbootin We've already talked about Linux and why you should try it, but probably the hardest part of getting used to Linux is getting it in the first place. For Windows users, the simplest way is... Read More . Using one of these tools, you select the Linux image you wish to install (or have the application download one on the spot) and designate your SD card as the target device.


SD Cards: Versatile and Compact

SD cards have many advantages over flash drives. They’re thinner, lighter, and easier to carry in bulk. Since they typically sit flush with the side of a computer, it’s possible to plug them in full-time in a way you typically can only do with the tiniest of flash drives, and they still protrude less.

If you prefer flash drives, that’s fine too. The tools for managing one typically work with the other.

What advice would you recommend for people looking to manage their SD cards? Have you ever put multiple partitions on a single card? Do you use one as a live operating system? Share your experience with others in the comments below!

Image Credits:penguin holding by Asfia via Shutterstock

Related topics: File Management, Memory Card.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

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

  1. Anonymous
    March 15, 2016 at 11:28 pm

    Ahh yes, Disks is a wonderful utility, maybe even better than Gparted! The reason I say this is because it looks better, supports SMART functionality (S.M.A.R.T.), and uses GB (x1000), not GiB (x1024), which is so confusing, because some applications use GIB, while others use GB. I personally like GB, it's much simpler, and I hate it when companies (especially corps) hide this and pretend it's the other one with their data.

  2. Andrius
    March 15, 2016 at 9:25 pm

    Disk and Gparted is the best what you can get for managing your usb/sd card/harddrives etc... believe me :)

    • Bertel King
      March 18, 2016 at 10:45 pm

      No disagreement here!