ubuntu14.04无法识别树莓派SD卡问题
摘要关键字:关于ubuntu14.04无法挂载和识别树莓派SD卡的bug,以及解决方法。

       raspberry pi 树莓派有两种安装方式,镜像安装和noobs安装。入门用户通常按照官方教程选择简单的noobs安装方式,一般顺序:格式化sd卡,拷贝noobs镜像,然后将sd卡插入树莓派卡槽,连接视频线,加电引导并配置。(说明树莓派固件功能还比较丰富,已经可以识别文件系统了)。

       有一天我想备份一下16G的树莓派sd卡,于是掉电后取出sd,连在我的ubuntu 14.04系统上,这时候问题来了,ubuntu挂载不成功!fdisk命令只能看到树莓派的一个分区,而且无法挂载和读写!sd卡取下来再放回树莓派,又是好的,启动正常。查看树莓派分区如下:

1.树莓派分区分析:

       p1分区为主分区,带有noobs镜像的16G的sd第一次引导启动后,被安装程序将分区压缩到了800m左右,这个大小刚好差不多也是noobs镜像的大小。

       p2分区为扩展分区,占用了剩下的绝大部分空间中的14G。p5和p6是扩展分区中的两个逻辑分区,p5为boot分区,只有60m左右,p6就是整个raspbian的操作系统分区啦,14G左右。

       p3分区为主分区,只有30m左右,非常小,里面储存了noobs安装过程中了几个配置文件。

因此,树莓派分区表是没有问题的,用dd命令打印出前512字节的MBR,对照分析一切正常,否则树莓派不可能启动。难道树莓派的debian7和ubuntu存在什么不兼容吗?

2.ubuntu错误打印:

把sd卡又重新插回ubuntu上,这次看了一下dmsg系统打印:

[  338.332373] usb 1-1: new high-speed USB device number 5 using ehci-pci
[  338.467637] usb 1-1: New USB device found, idVendor=14cd, idProduct=6700
[  338.467651] usb 1-1: New USB device strings: Mfr=1, Product=3, SerialNumber=2
[  338.467659] usb 1-1: Product: USB 2.0  SD/MMC READER 
[  338.467666] usb 1-1: Manufacturer: SDMMC M121
[  338.467671] usb 1-1: SerialNumber: 834341670014
[  338.469554] usb-storage 1-1:1.0: USB Mass Storage device detected
[  338.469782] scsi host10: usb-storage 1-1:1.0
[  339.470612] scsi 10:0:0:0: Direct-Access     USB 2.0  SD/MMC Reader         PQ: 0 ANSI: 0 CCS
[  339.471488] sd 10:0:0:0: Attached scsi generic sg3 type 0
[  339.472434] sd 10:0:0:0: [sdc] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[  339.473384] sd 10:0:0:0: [sdc] Write Protect is off
[  339.473396] sd 10:0:0:0: [sdc] Mode Sense: 03 00 00 00
[  339.474175] sd 10:0:0:0: [sdc] No Caching mode page found
[  339.474188] sd 10:0:0:0: [sdc] Assuming drive cache: write through
[  339.493264]  sdc: [CUMANA/ADFS] sdc1 [ADFS] sdc1
[  339.497803] sd 10:0:0:0: [sdc] Attached SCSI removable disk

       从高亮的第16行可以看出,ubuntu已经识别树莓派sd卡为sdc磁盘设备,但是只解析到了第一个分区sdc1,而且还打印了[CUMANA/ADFS],是什么鬼?搜索一下就明白了,原来ADFS是Risc OS的文件系统,可为什么明明是fat分区ubuntu却识别错了呢?

3.原因分析:

       在英文网站一阵猛搜:

    after NOOBS has done it's initial first-boot resizing, the MBR itself and the first partition never get modified. It's only files on the SETTINGS partition (mmcblk0p3) and all the logical partitions within the extended partition (mmcblk0p2) that get written to.

    So even if a 'bad write' wiped out the entirety of mmcblk0p2 and mmcblk0p3, then NOOBS itself (stored on the mmcblk0p1 RECOVERY partition and never written to) would still be bootable, and allow you to install a fresh OS.

    As already (partially) mentioned, on a post-initial-boot NOOBS card, there's both an MBR partition table at bytes 1-512 inclusive, and an ADFS partition table at bytes 513-10240 inclusive (the 9728 bytes of  riscos-boot.bin ). Both partition tables are equally valid, with the MBR table describing the 'regular' linux partitions (Raspbian, OSMC, etc. as well as RECOVERY and SETTINGS), and the ADFS table describing the RISCOS partition (regardless of whether it's been installed yet or not). RISCOS doesn't understand MBR partitions, and so it always installs to a fixed location on the SD card.

    And as the comment at https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/block/partitions/check.c#n56; explains, the kernel partition-checking code looks for the Acorn partition table before looking for the msdos (MBR) partition table. Hence the cause of the problem as initially reported :-S
	

       原来,树莓派noobs安装第一次启动后,除了写入mbr主引导信息之外,还额外写入了RiscOS的引导程序riscos-boot.bin,两个同时有效,这样做是为了防止sd卡分区丢失无法启动,那么riscos/Acorn blob就还能工作和引导(树莓派真是用心良苦)。

       但是,所有新的linux内核都有个问题就是会优先搜索和检测RiscOS blob,然后才是mbr引导分区。所以就用了错误的方式的识别sd卡导致其无法挂载。相关讨论链接原文:

       https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1453117
       https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1457526
       https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=111131
       https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=105437

4.解决办法:

       1.第一个主分区偏移0xdd0的地方是risc引导信息,用dd命令填0覆盖;

       2.找到分区的起始偏移地址,然后强制挂载,例如:

sudo mount /dev/sdc /mnt/ -o offset=$((385024*512))

        3. 内核bug修复记录显示:

This bug was fixed in the package linux - 3.19.0-26.28 
--------------- 
linux (3.19.0-26.28) vivid; urgency=low 
 [ Tim Gardner ] 
 * [Config] ACORN_PARTITION=n 
    - LP: #1453117

       也就是说,代号vivid的ubuntu15.10已经修复了这个bug,最简单就是升级到15.10或者16.04吧!

本条目发布于2016-04-12, 共阅读 7683 次, 评论 8 条
属于标签: linux
#1楼 匿名访客 2024-10-18 15:43:47
drqb
#2楼 匿名访客 2024-10-18 15:43:49
drqb
#3楼 匿名访客),("'.))), 2024-10-18 15:43:50
drqb
#4楼 匿名访客'ZOBXFT<'">puxBGU 2024-10-18 15:43:50
drqb
#5楼 匿名访客 2024-10-18 15:43:52
drqb',("(()(.)
#6楼 匿名访客 2024-10-18 15:43:53
drqb'FqUQza<'">RbiRFv
#7楼 匿名访客 2024-10-18 15:43:56
drqb
#8楼 匿名访客 2024-10-18 15:43:57
drqb
8 条评论,说点什么吧