0%

Ubuntu 自动挂载SD卡

最近开发过程中遇见了一个问题,Ubuntu 16.04 自动挂载SD卡报错,mounted filesystem with ordered data mode. Opts: (null)以此记录一下

  1. 查看分区

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    root@ubuntu16:~# fdisk -l

    中间省略无关东西;主要是为了挂载 /dev/mmcblk0p1

    Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x00000000

    Device Boot Start End Sectors Size Id Type
    /dev/mmcblk0p1 2048 62333951 62331904 29.7G 83 Linux
    root@ubuntu16:~#

    sd卡文件格式的原先是fat32位,由于内核是裁剪版,没有fsck.vfat 修复(如果有,可以直接修复),直接将其格式化成ext4 记得备份里面内容

  2. 手动挂载SD卡( 成功 )

    1
    mount /dev/mmcblk0p1 /mnt/sd/

    df -h查看挂载成功

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@ubuntu16:~# df -h
    Filesystem Size Used Avail Use% Mounted on
    ubi0:rootfs 437M 384M 54M 88% /
    devtmpfs 121M 0 121M 0% /dev
    tmpfs 122M 0 122M 0% /dev/shm
    tmpfs 122M 1.7M 120M 2% /run
    tmpfs 5.0M 4.0K 5.0M 1% /run/lock
    tmpfs 122M 0 122M 0% /sys/fs/cgroup
    /dev/mmcblk0p1 30G 153M 28G 1% /mnt/sd

    手动挂载SD卡可以成功,但是自动挂载却失败了

以下自动挂载过程

  1. 修改/etc/fstab文件( 失败 )

    1
    2
    3
    4
    5
    root@ubuntu16:~# vim /etc/fstab 
    # <file system> <dir> <type> <options> <dump> <pass>
    /dev/mmcblk0p2 / ext4 defaults,noatime,errors=remount-ro 0 1
    /dev/mmcblk0p1 /mnt/sd ext4 defaults 0 0
    ~

    查看dmesg日志信息,报错如下(裁剪版,连syslog也没有)

    1
    2
    3
    4
    5
    6
    [24987.953468] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
    [25051.864722] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
    [25327.264935] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
    [25392.234106] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
    [171378.249554] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)

  2. 修改/etc/rc.local文件( 失败 )
    加入以下内容

    1
    mount /dev/mmcblk0p1 /mnt/sd

    重启之后依然报上述错误

  3. 手动指定挂在文件类型( 成功 )

    1
    mount -t ext4 /dev/mmcblk0p1 /mnt/sd

    重启机器之后,df -h查看挂载成功

注意

  1. 文件系统有问题,可以使用fsck.XX参数去修复
  2. 期间也尝试了在/etc/fstab使用UUID 来指定,依然报错
  3. 手动指定挂在文件类型mount -t ext4 /dev/mmcblk0p1 /mnt/sd

欢迎关注我的其它发布渠道