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.
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.
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. 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.
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. 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.
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. 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