1. Introduction

There are different portable storage mediums, but few are as small and widespread as memory cards. Although they often require additional specific hardware, non-volatile flash memory cards can now hold a vast amount of data and reach relatively good transfer speeds. However, to use them, we first need to know how to prepare and attach such mediums to the operating system (OS).

In this tutorial, we explore memory cards and ways to work with them on a Linux system. First, we perform a general overview of memory cards. After that, we focus on perhaps the most widely used type of memory card. Finally, we go over the practical steps to find, format, and mount with a memory card reader.

We tested the code on Debian 12 (Bookworm) with GNU Bash 5.2.15. It should work in most POSIX-compliant environments unless otherwise specified.

2. Memory Cards

There are many non-volatile flash memory card standards:

  • Memory Stick (MS, MSD, MSPD): MagicGate proprietary
  • MultiMediaCard (MMC): open format developed by JEDEC
  • xD-Picture Card (xD): open format developed by Olympus and Fujifilm
  • Universal Flash Storage (UFS): initially opened by UFSA, now proprietary by JEDEC
  • Secure Digital (SD, SDHC, SDXC): officially proprietary by SD Association, now open-source

Some were mainly used with specific devices, such as the Sony Memory Stick (MS, MSD, MSPD) standard and their devices, such as the PlayStation and PlayStation Portable. Others had brief fame in terms of portable storage and then got embedded into devices, such as the Universal Flash Storage (UFS) standard. Still others remained with niche use cases.

In general, memory cards have multiple applications:

  • mobile phone storage
  • camera storage
  • mobile gaming console storage
  • laptop storage
  • mini computing systems storage (RaspberryPI, Arduino, and similar)

Although not the fastest, by far, the most used and available type of memory card adheres to the Secure Digital standard.

3. Secure Digital (SD, SDHC, SDXC, SDUC) Cards

Developed by the SD Association, the SD standard was born from the MultiMediaCard. Initially, SD was a closed proprietary specification, with open-source driver development even being banned. However, wide adoption led to reverse engineering and many free drivers.

3.1. Physical Size

There are several formats for the SD card form factor:

  • standard (original): 32.0 x 24.0 x 2.1 mm
  • miniSD: 21.5 x 20.0 x 1.4 mm
  • microSD: 15.0 x 11.0 x 1.0 mm

Another name for the microSD physical format is T-Flash (TransFlash, TF).

Importantly, standard SD cards are more rugged and have a physical write protection switch.

3.2. Capacity and Classes

Currently, there are at least four classes of SD cards:

+------+---------------------+-------------+
|      | Name                | Capacity    |
+------+---------------------+-------------+
| SD   | standard            | <= 2GB      |
| SDHC | [H]igh capacity     | 2GB - 32GB  |
| SDXC | e[X]tended capacity | 32GB - 2TB  |
| SDUC | [U]ltra capacity    | 2TB - 128TB |
+------+---------------------+-------------+

Notably, these aren’t strict requirements but general guidelines.

3.3. Speed

Many speed class scales exist for SD cards. As speeds grow, scales haven’t gotten extended, but instead, new classes get created, some overlapping with older ones:

+---------+-----------------------------------------------+
|         |                     Speed                     |
|         |                     Scale                     |
+---------+-------+-----------+-------------+-------------+
|  Speed  | Speed | UHS Speed | Video Speed | SD Express  |
|         | Class |   Class   |    Class    | Speed Class |
+---------+-------+-----------+-------------+-------------+
| 600MB/s |       |           |             | E600        |
| 450MB/s |       |           |             | E450        |
| 300MB/s |       |           |             | E300        |
| 150MB/s |       |           |             | E150        |
| 90MB/s  |       |           | V90         |             |
| 60MB/s  |       |           | V60         |             |
| 30MB/s  |       | 3         | V30         |             |
| 10MB/s  | 10    | 1         | V10         |             |
| 6MB/s   | 6     |           | V6          |             |
| 4MB/s   | 4     |           |             |             |
| 2MB/s   | 2     |           |             |             |
+---------+-------+-----------+-------------+-------------+

While card classes don’t define speeds, bigger-capacity cards usually support higher speeds at the very least due to the total transfer time of the entire card contents.

3.4. Filesystems

While any storage card can be formatted with any filesystem, FAT32 was the default for SD and SDHC cards until the introduction of SDXC, when exFAT became the new default:

  • SD: FAT16/FAT32
  • SDHC: FAT32
  • SDXC: exFAT
  • SDUC: exFAT

Considering the filesystem expectation, let’s understand how to format and mount SD and memory cards in general.

4. Formatting and Mounting Memory Cards

Regardless of the memory card type, we first need to have the relevant hardware and drivers. This way, our device can physically connect with, read, and write the card.

Usually, card readers are plug-and-play, but some systems could require a specific setup outside the scope of this article.

4.1. List Cards

Since memory cards and their readers are block devices, we can use the lsblk command to list them:

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda               8:0    0  666G  0 disk
├─sda1            8:1    0  600G  0 part /
├─sda2            8:2    0   10G  0 part /var
├─sda3            8:3    0  666M  0 part [SWAP]
├─sda4            8:4    0  799M  0 part /tmp
└─sda5            8:5    0   54G  0 part /home
mmcblk0         179:0    0 66.6G  0 disk
├─mmcblk0p1     179:1    0  666M  0 part
└─mmcblk0p2     179:2    0   66G  0 part

Here, we see a standard disk at sda along with a memory card disk at mmcblk0. Due to the number suffix of the card, partition numbers have the p prefix.

As with other devices, memory cards show up under the /dev block devices path, usually as mmcblk*. Despite the mmc prefix, this can be any card (reader) type.

4.2. Format Card

Critically, formatting devices and partitions wipe out their contents.

As mentioned, due to its flexibility, exFAT is now usually preferred over FAT32 for all but the oldest devices. So, let’s format a memory card as exFAT:

$ mkfs.exfat /dev/mmcblk0p1

Here, we assume the mmcblk0p1 partition was already in place. If that’s not the case, we can repartition as necessary.

Either way, at this point, we should have a new empty exFAT partition on /dev/mmcblk0p1.

4.3. Mount Card and Card Partition

Mounting cards and their partitions doesn’t differ much from the usual way to mount as long as we have the main components prepared:

For example, let’s mount the partition we formatted earlier:

$ mkdir /mnt/sd1
$ mount --types exfat --source /dev/mmcblk0p1 --target /mnt/sd1

In this case, we mount the first memory card partition at /mnt/sd1, a directory we created via mkdir.

Although the filesystem might be deduced by the mount command, it’s usually a good idea to specify it explicitly.

Now, let’s see the same with FAT32:

$ mkdir /mnt/sd2
$ mount --types msdos --source /dev/mmcblk0p2 --target /mnt/sd2

Here, we assume /dev/mmcblk0p2 holds a FAT32 partition, so we can mount it at /mnt/sd2.

5. Summary

In this article, we talked about memory cards and ways to manipulate them.

In conclusion, regardless of the memory card type, most Linux systems are equipped to handle basic actions with such storage mediums as long as there’s a card reader present and properly configured.