linux内核不识别分区,ubuntu14.04无法识别树莓派SD卡问题
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卡導致其無法掛載。相關討論鏈接原文:
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吧!
總結
以上是生活随笔為你收集整理的linux内核不识别分区,ubuntu14.04无法识别树莓派SD卡问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(3068):vue+eleme
- 下一篇: MySQL——安装