歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> ARM Linux使用SD卡根文件系統

ARM Linux使用SD卡根文件系統

日期:2017/3/1 10:56:57   编辑:Linux編程
因此指導學員在arm-Linux使用JPT-7模塊來跑GPS應用.Nand Flash 空間太小,而且所用的板經常燒不了根文件系統.所以決定用SD卡來跑根文件系統. 1.PC機上格式化SD卡 在桌面的PC機上用SD讀卡器操作SD卡: 一般情況下PC機上第一個U盤整體設備結點是/dev/sda,第二個是 /dev/sdb,在RHEL5下它會被自動mount到/media/disk和 /media/disk_1 目錄. U盤/dev/sdb上第一個分區是 /dev/sdb1,第二是/dev/sdb2 依此類推. 根文件系統采用符號鏈接等特性,用FAT32是不行的,這裡直接采用標准的ext3的文件系統.在實測時,把U盤整個做一個分區做ext3根文件系統.總是出不少問題(可能步驟也不對),因此按網上推薦的,做二個分區,第一個分區采用vfat格式,第二個分區才采用ext3的格式. 1.1 用fdisk分區 執行fdisk /dev/sdb fdisk有如下常用選項
1. 輸入 m 顯示所有命令列示。
2. 輸入 p 顯示硬盤分割情形。
3. 輸入 a 設定硬盤啟動區。
4. 輸入 n 設定新的硬盤分割區。
4.1. 輸入 e 硬盤為[擴展]分割區(extend)。
4.2. 輸入 p 硬盤為[首要]分割區(primary)。
5. 輸入 t 改變硬盤分割區屬性。
6. 輸入 d 刪除硬盤分割區屬性。
7. 輸入 q 結束不存入硬盤分割區屬性。
8. 輸入 w 結束並寫入硬盤分割區屬性 如果以前U盤有分區,需要輸入d命令來依次刪除分區,以下執行兩次n命令創建一個 400M的FAT分區,以及把剩下的分區設為ext3,最後用w命令把結果保存下來.

Command (m for help): n

Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1020, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1020, default 1020): +400M

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (202-1020, default 202):
Using default value 202
Last cylinder or +size or +sizeM or +sizeK (202-1020, default 1020):
Using default value 1020

Command (m for help): p

Disk /dev/sdb: 2041 MB, 2041577472 bytes
63 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 201 392522 b W95 FAT32
/dev/sdb2 202 1020 1599507 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

1.2 格式化分區 mkfs.vfat /dev/sda1 #第一個分區格式化成fat32 mkfs.ext3 /dev/sda2 #第二個分區格式化成fat32 可以用 tune2fs -l /dev/sda2 來檢驗分區類型  1.3 拷貝根文件系統 mount /dev/sda2 /mnt/sdcard #掛載SD卡 cp -ra /home/hxy/rootfs/* /mnt/sdcard #把根文件系統拷到SD卡 2.編譯ARM Linux內核 2.1 修改內核配置 確保ext3的文件系統支持,和SD卡驅動都被靜態編譯到內核,我使用的是Linux 2.6.29. 在內核源碼目錄執行 make menuconfig 其中ext3在File system下.成功的配置如下.
<*> Ext3 journalling file system support
[*] Ext3 extended attributes
[*] Ext3 POSIX Access Control Lists
[*] Ext3 Security Labels SD卡驅動支持在Device Drivers ->MMC/SD/SDIO card support 下,成功的配置如下 --- MMC/SD/SDIO card support
[*] MMC debugging
[ ] Allow unsafe resume (DANGEROUS)
*** MMC/SD/SDIO Card Drivers ***
<*> MMC block device driver
[*] Use bounce buffer for simple hosts
<*> SDIO UART/GPS class support
<*> MMC host test driver
*** MMC/SD/SDIO Host Controller Drivers ***
<*> Secure Digital Host Controller Interface support
<*> Samsung S3C SD/MMC Card Interface support
編譯內核 make zImage 2.2 在ARM-linux下的測試. 在一個已經正常啟動的ARM-LINUX下,插入SD卡.出現如下提示,表示SD卡已經安裝上 [root: /]# s3c2440-sdi s3c2440-sdi: running at 0kHz (requested: 0kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
mmc0: new SD card at address 0002
mmcblk0: mmc0:0002 00000 1.90 GiB
mmcblk0: p1 p2
FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
但是最後一句在提示FAT有不識別的IO字符集,導致第一個VFAT分區沒有自動創建設備結點.用如下命令只看到mmcblk0p2的結點.(以下操作均是在開發板上進行) [root: /]# ls -l /dev/mmc*
brw-rw---- 1 root root 179, 0 Sep 22 10:48 /dev/mmcblk0
brw-rw---- 1 root root 179, 2 Sep 22 10:48 /dev/mmcblk0p2 測試ext3分區 mount -t ext3 /dev/mmcblk0p2 /mnt 在/mnt上可以讀寫文件.表示ext3分區正常. 手動建立第一個分區的結點. mknod /dev/mmcblk0p1 b 179 1 測試vfat 分區 mount -t vfat /dev/mmcblk0p1 /mnt 在/mnt上可以讀寫文件.表示vfat分區正常.如果想自動創建個設備結點,可以修改/etc/fstat來使用這個分區 3.使用SD卡分區作為根文件 修改LINUX啟動參數.我用的是u-boot .因此在u-boot shell用set bootargs命令來設置Linux啟動參數. 成功的啟動參數是 noinitrd root=179:2 rw console=ttySAC0 其中179和2是sd卡上ext3分區的主設備和從設備號. 用set bootargs "noinitrd root=179:2 rw console=ttySAC0 "設置後.重啟內核,即可用ext3分區作為根文件系統
Copyright © Linux教程網 All Rights Reserved