How To Check Sd Card In Linux : Linux SD Card Mount And Verify

Mounting an SD card in Linux requires first identifying its device name using `lsblk`. If you’re wondering how to check sd card in linux, the process is straightforward once you know the right commands. This guide will walk you through every step, from listing devices to verifying the card’s health.

Whether you’re using a Raspberry Pi, a laptop, or a desktop, checking an SD card in Linux is a common task. You might need to see if it’s detected, check its partitions, or test for errors. We’ll cover all that and more.

How To Check Sd Card In Linux

To start, you need to understand that Linux treats hardware devices as files. An SD card will appear as a block device, usually named something like `/dev/sdb` or `/dev/mmcblk0`. The exact name depends on your system and other connected drives.

The most reliable way to find your SD card is using the `lsblk` command. It lists all block devices in a tree-like format, showing their sizes and mount points. This is your first and most important tool.

Using Lsblk To Identify The Sd Card

Open a terminal and type:

lsblk

You’ll see output similar to this:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 237.1G  0 part /
sdb      8:16   1  29.7G  0 disk 
└─sdb1   8:17   1  29.7G  0 part /media/user/SD_CARD

Look for a device with a size that matches your SD card. In this example, `sdb` is 29.7G, which is likely a 32GB card. The `RM` column shows 1, meaning it’s removable. That’s a good indicator.

If you have multiple drives, you can unplug the SD card, run `lsblk`, then plug it back in and run it again. The new device that appears is your SD card. This is a simple but effective method.

Using Dmesg To Confirm Detection

Another way to check is with `dmesg`. This command shows kernel messages, including when a new device is attached. After inserting the SD card, run:

dmesg | tail -20

You should see lines like:

[ 1234.567890] mmc0: new high speed SD card at address 1234
[ 1234.567901] mmcblk0: mmc0:1234 ABCD 29.7 GiB 
[ 1234.567912]  mmcblk0: p1

This tells you the kernel detected the card and assigned it the device name `mmcblk0`. The `p1` indicates the first partition. This method is especially useful if `lsblk` doesn’t show the card immediately.

Checking Partitions With Fdisk

Once you know the device name, you can examine its partitions. Use `fdisk` for a detailed view:

sudo fdisk -l /dev/sdb

Replace `/dev/sdb` with your actual device. This will show the partition table, sizes, and file system types. For example:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        8192 62521343 62513152 29.8G  c W95 FAT32 (LBA)

This confirms the card has one FAT32 partition. If you see multiple partitions, you can work with each one separately.

Checking File System With Blkid

To see the file system type and UUID, use `blkid`:

sudo blkid /dev/sdb1

Output example:

/dev/sdb1: UUID="1234-5678" TYPE="vfat" PARTUUID="abcd1234"

This tells you it’s a vfat (FAT32) file system. Knowing the UUID is useful for mounting or editing `/etc/fstab`.

Mounting And Accessing The Sd Card

After identifying the SD card, you might want to access its files. Modern desktop environments often auto-mount removable drives. If not, you can mount it manually.

Creating A Mount Point

First, create a directory where the card will be mounted:

sudo mkdir /mnt/sdcard

You can use any path you like. `/mnt` is a common choice for temporary mounts.

Mounting The Partition

Mount the partition with:

sudo mount /dev/sdb1 /mnt/sdcard

If the file system is not vfat, you might need to specify the type. For example, for ext4:

sudo mount -t ext4 /dev/sdb1 /mnt/sdcard

Now you can access the files at `/mnt/sdcard`. Use `ls` to list them:

ls /mnt/sdcard

Unmounting Safely

Always unmount before removing the card to prevent data corruption:

sudo umount /mnt/sdcard

You can also use the device path:

sudo umount /dev/sdb1

Checking Sd Card Health And Errors

Sometimes you need to check if the SD card is failing or has bad sectors. Linux provides tools for this.

Using Badblocks For Surface Scan

The `badblocks` command scans for bad sectors. Run it on the device (not a partition):

sudo badblocks -sv /dev/sdb

The `-s` shows progress, and `-v` gives verbose output. This can take a long time on large cards. It will list any bad blocks found.

For a destructive write test, use `-w`. This will erase all data, so back up first.

Checking File System Integrity With Fsck

To check and repair the file system, use `fsck`. Unmount the partition first, then run:

sudo fsck /dev/sdb1

For vfat file systems, you can specify:

sudo fsck.vfat /dev/sdb1

It will report errors and offer to fix them. This is good for logical corruption, not physical damage.

Using Smartctl For Sd Cards

While `smartctl` is mainly for hard drives, some SD card readers support it. Try:

sudo smartctl -a /dev/sdb

If it works, you’ll see health metrics. Most SD cards don’t support SMART, so this might fail.

Checking Sd Card Speed And Performance

You might want to test read/write speeds to ensure the card meets specifications.

Using Dd For Simple Speed Test

The `dd` command can measure raw performance. To test write speed:

sudo dd if=/dev/zero of=/mnt/sdcard/test bs=1M count=100 conv=fdatasync

This writes 100MB of zeros. The output shows the speed. For read speed:

sudo dd if=/mnt/sdcard/test of=/dev/null bs=1M count=100

Remove the test file after:

sudo rm /mnt/sdcard/test

Using Hdparm For Read Speed

`hdparm` can test read speed without writing:

sudo hdparm -t /dev/sdb

This gives a buffered read speed. For cached reads, use `-T`. Note that this tests the device, not a file system.

Using Gnome Disks For Gui Speed Test

If you prefer a graphical tool, install `gnome-disk-utility`. Open “Disks”, select the SD card, click the menu button, and choose “Benchmark Disk”. This provides read/write speeds and access time.

Troubleshooting Common Issues

Sometimes the SD card isn’t detected or gives errors. Here are common fixes.

Sd Card Not Showing Up

If `lsblk` doesn’t show the card, try these steps:

  • Check the card reader. Try a different USB port or adapter.
  • Run `sudo dmesg | grep -i sd` to see kernel messages.
  • Check if the card is locked. Some cards have a physical write-protect switch.
  • Try another SD card to rule out a faulty reader.

Mount Error: Unknown Filesystem

If you get “unknown filesystem type”, the card might be unformatted or have a corrupted partition table. Use `sudo fdisk -l` to check. If it shows no partitions, you may need to create one with `fdisk` or `gparted`.

Permission Denied When Accessing

If you can’t access the mounted card, check permissions. The mount point might be owned by root. Use `sudo chmod 755 /mnt/sdcard` or mount with user options:

sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/sdcard

Replace 1000 with your user ID. You can find it with `id -u`.

Read-Only File System

If the card mounts as read-only, it might be damaged or the file system has errors. Run `fsck` to repair. If that fails, the card might be failing. Try formatting it, but back up data first.

Advanced Checks: Sd Card Info And Capabilities

For detailed information about the SD card’s specifications, you can use specialized tools.

Using Sd Card Info From Sysfs

Linux exposes SD card details in `/sys`. For example:

cat /sys/block/mmcblk0/device/cid

This shows the Card Identification Register. Other files include `csd` (Card Specific Data) and `scr` (SD Configuration Register). These contain manufacturer info, serial number, and speed class.

Using MMC Utils For Extended Info

Install `mmc-utils` on Debian/Ubuntu:

sudo apt install mmc-utils

Then run:

sudo mmc extcsd read /dev/mmcblk0

This shows extended card data, including erase size, speed modes, and health indicators. Not all cards support all commands.

Checking Sd Card Speed Class

The speed class is often printed on the card, but you can verify it from the `csd` register:

cat /sys/block/mmcblk0/device/csd | grep -i speed

Or use `mmc-utils` to decode it. This tells you if the card is Class 2, 4, 6, or 10.

Automating Sd Card Checks With Scripts

If you frequently check SD cards, you can write a simple script.

Basic Detection Script

Create a file `check_sd.sh`:

#!/bin/bash
echo "Checking for SD cards..."
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep -E "disk|part"
echo ""
echo "Detailed info:"
sudo blkid | grep -E "sd|mmc"

Make it executable:

chmod +x check_sd.sh

Run it with `./check_sd.sh`. This gives a quick overview.

Health Check Script

For a more thorough check:

#!/bin/bash
DEVICE="/dev/sdb"
echo "Running badblocks on $DEVICE..."
sudo badblocks -sv $DEVICE
echo ""
echo "Checking file system..."
sudo fsck -y ${DEVICE}1
echo ""
echo "Done."

Adjust the device name as needed. This script runs a surface scan and file system check.

Frequently Asked Questions

How do I check if my SD card is detected in Linux?

Use the `lsblk` command. It lists all block devices. Look for a device with the size of your SD card and a removable flag (RM=1). You can also use `dmesg | tail` after inserting the card.

What command shows SD card partitions in Linux?

Use `sudo fdisk -l /dev/sdb` (replace sdb with your device). This shows the partition table, sizes, and file system types. Alternatively, `sudo blkid` shows UUIDs and file system types for all partitions.

How can I test an SD card for errors in Linux?

Use `badblocks` for a surface scan: `sudo badblocks -sv /dev/sdb`. For file system errors, use `fsck`: `sudo fsck /dev/sdb1`. Always unmount the partition before running `fsck`.

Why is my SD card not mounting automatically in Linux?

Auto-mounting depends on your desktop environment. If it doesn’t work, mount manually: create a mount point with `sudo mkdir /mnt/sdcard`, then `sudo mount /dev/sdb1 /mnt/sdcard`. Check if the card has a file system using `blkid`.

Can I check SD card speed in Linux terminal?

Yes, use `dd` for read/write tests: `sudo dd if=/dev/zero of=/mnt/sdcard/test bs=1M count=100 conv=fdatasync` for write, and `sudo dd if=/mnt/sdcard/test of=/dev/null bs=1M count=100` for read. Remove the test file after.

Now you have a complete understanding of how to check sd card in linux. From basic detection to advanced health checks, these commands and tools will help you manage your SD cards effectively. Remember to always unmount before removing the card to avoid data loss. Practice these steps, and you’ll become proficient in no time.

If you encounter any issues, refer back to the troubleshooting section. The Linux community is also a great resource for specific problems. Happy computing!