【Linux】嵌入式Linux挂载SD卡

发布于 2021-03-01  21 次阅读


问题描述

之前SD卡主要是用于做内核的烧录,通过修改跳线让芯片从EMMC读取引导程序并进入Uboot。
当进入系统后,想要传输一些文件进去调试而网络不可用时,此时SD卡就又派上用场了

1. 检测SD卡

首先我们需要在系统中检测是否存在SD卡,使用下面的命令输出可用设备

fdisk -l

输出如下

Disk /dev/ram0: 16 MB, 16777216 bytes
255 heads, 63 sectors/track, 2 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/ram0 doesn't contain a valid partition table

Disk /dev/ram10: 16 MB, 16777216 bytes
255 heads, 63 sectors/track, 2 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/ram10 doesn't contain a valid partition table

Disk /dev/mtdblock0: 0 MB, 524288 bytes
255 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/mtdblock0 doesn't contain a valid partition table

Disk /dev/mmcblk0: 7985 MB, 7985954816 bytes
255 heads, 63 sectors/track, 970 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

        Device Boot      Start         End      Blocks  Id System
/dev/mmcblk0p1   *           1         971     7798752+  c Win95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
     phys=(969, 254, 63) logical=(970, 230, 28)

可以看到我们的SD卡设备为 /dev/mmcblk0

之前一直认为SD卡不能热拔插,后面查阅了一些资料,只是在挂载的情况下强行取出容易丢失数据,也就是说取消挂载后是可以直接拔除的。
在内核启动情况下,插入SD卡后调试串口会显示

mmc0: new high speed SDHC card at address 0001
mmcblk0: mmc0:0001 SD 7.44 GiB
mmcblk0: p1

拔掉SD卡也会有提示

mmc0: card 0001 removed

2.挂载SD卡

挂载命令

mount /dev/mmcblk0p1 /mnt/
mount -t vfat  /dev/mmcblk0p1 /mnt/ # 指定文件格式

挂载成功后就可以cd到mnt目录下了

3. 卸载SD卡

使用命令

umount /mnt

注意,当前目录不能是/mnt,否则会出现umount can't umount /mnt device or resource busy的错误提示信息。

总结

只要内核配置没有问题,SD卡能被识别到,那么使用起来还是比较简单的
如果要在上电时自动检测挂载SD卡,可以把挂载命令写到启动脚本中
但是如果开机时没有插入SD卡,后续也还需要手动挂载
因此熟悉SD卡的挂载指令还是有必要的

Comments


来自像素世界的代码家,创造第九艺术!