To partition a TF card in Linux, use
fdisk or
parted to create partitions and then format them with filesystems like
vfat for compatibility or
ext4 for performance. Always identify the correct device node using
lsblk before writing any changes to ensure you do not overwrite your primary storage drives.
Identifying the Device Node
Before making any changes to your TF card, it is critical to identify the correct device identifier. Linux assigns dynamic names to block devices such as
/dev/sdb,
/dev/mmcblk0, or
/dev/nvme0n1. Using the wrong identifier can result in catastrophic data loss on your system drive. The safest way to locate your TF card is by observing the output of the
lsblk command while the card is inserted and again after it is removed. This allows you to see which device appears and disappears from the list.
You can also use the
dmesg | tail command immediately after inserting the card to see kernel messages indicating the new device. Look for lines mentioning
mmc or
sdb depending on your hardware interface. Once identified, note the name without any partition numbers; for example, use
/dev/mmcblk0 instead of
/dev/mmcblk0p1. If you are unsure about the device, consult our guide on
Troubleshooting TF Card Partitions: Third Partition Not Detected for deeper diagnostic steps regarding detection issues.
Choosing the Right Filesystem
The choice of filesystem depends heavily on how you intend to use the TF card. For maximum compatibility across Windows, macOS, and Linux systems, the
vfat (also known as FAT32) filesystem is the standard choice. It supports files up to 4GB in size and works out-of-the-box on almost all embedded devices and cameras. However, if you plan to store large files exceeding 4GB or need better performance and journaling features on Linux-only systems,
ext4 is the superior option.
Another modern alternative is
exFAT, which handles large files like
vfat but removes the 4GB file size limit. While native support for
exFAT varies by Linux distribution, most modern kernels include drivers for it. If you encounter issues with specific partition types, refer to resources on
How to Test for ext4 Partition? Not ext4 Filesystem to verify your filesystem integrity and type correctly. Avoid using NTFS unless necessary, as write performance can be slower due to driver overhead in some Linux environments.
Creating Partitions with Fdisk
The
fdisk utility is a powerful tool for managing disk partitions. Start by running
sudo fdisk /dev/mmcblk0, replacing the path with your identified device. Inside the interactive menu, press
n to create a new partition. You will be prompted to select the partition type, usually defaulting to
primary. Next, accept the default first and last sector values to use the entire available space, or specify custom sizes if you need multiple partitions.
After creating the partition, press
w to write the changes to the disk and exit. The kernel may not immediately recognize the new partition table. To force the system to reload the partition information without rebooting, run
sudo partprobe /dev/mmcblk0 or simply remove and reinsert the card. Verify the new partition exists by running
lsblk again; you should now see a new entry like
/dev/mmcblk0p1.
Formatting the Partition
Once the partition is created, you must format it with a filesystem. For a FAT32 partition, use the
mkfs.vfat command. Execute
sudo mkfs.vfat -F 32 /dev/mmcblk0p1. The
-F 32 flag explicitly creates a FAT32 volume, ensuring compatibility with older devices that might misinterpret other FAT variants. If you prefer
ext4, use
sudo mkfs.ext4 /dev/mmcblk0p1. This command initializes the filesystem metadata and prepares the partition for mounting.
For
exFAT, you may need to install additional packages like
exfatprogs on Debian-based systems. Then run
sudo mkfs.exfat /dev/mmcblk0p1. After formatting, it is good practice to label your partition for easier identification later. Use
sudo dosfslabel /dev/mmcblk0p1 MY_CARD for FAT32 or
sudo e2label /dev/mmcblk0p1 MY_CARD for
ext4. This label will appear in file managers and mount points, making management simpler.
Mounting and Verification
Create a mount point directory where the OS will access the card's contents. Run
sudo mkdir -p /mnt/tfcard. Then, mount the partition using
sudo mount /dev/mmcblk0p1 /mnt/tfcard. To ensure automatic mounting at boot, add an entry to your
/etc/fstab file. You can generate the correct UUID for this entry by running
sudo blkid /dev/mmcblk0p1 and copying the UUID string. If you experience issues with updated partition UUIDs affecting mounts, check our article on
Failed Mount API: Filesystems with Updated Partition UUIDs in Linux.
Verify the mount by running
df -h /mnt/tfcard. This command displays disk usage and confirms that the filesystem is accessible. You can now copy files to the card using standard commands like
cp or
rsync. Remember to unmount the card safely before removal using
sudo umount /mnt/tfcard to prevent data corruption.
Frequently Asked Questions
Why is my TF card showing as read-only?
This often happens if the filesystem is corrupted or if the write-protect switch on the adapter is engaged. Check the physical switch on the SD adapter first. If it is off, try remounting the filesystem with the
rw option or checking for errors using
e2fsck.
Can I resize a partition on a TF card after creation?
Yes, you can use tools like
resize2fs for
ext4 or
gparted for graphical management. However, resizing requires unmounting the partition first. Always backup your data before resizing, as incorrect operations can lead to data loss.
What causes the "device busy" error when unmounting?
This error occurs if a process is still accessing files on the mounted partition. Use the
fuser -m /mnt/tfcard command to identify processes holding the mount open. Kill those processes or close the terminal windows accessing the directory, then retry the unmount command.
Is it safe to use NTFS on a TF card in Linux?
While supported via the
ntfs-3g driver, NTFS can have higher CPU overhead and slower write speeds compared to
ext4 or
vfat. It is generally recommended to use native Linux filesystems for performance unless you require strict compatibility with Windows-only legacy software.
How do I fix a "superblock bad" error?
This indicates filesystem corruption. You can attempt to repair it using
sudo fsck -y /dev/mmcblk0p1. If the superblock is severely damaged, you may need to restore it from a backup superblock located at different offsets within the partition.