1. 程式人生 > >在Linux PC上掛載JFFS2檔案系統

在Linux PC上掛載JFFS2檔案系統

Mounting JFFS2 Images on a Linux PC

It is possible to mount a binary JFFS2 image on a Linux PC without a flash device. This can be useful for examining the contents of the image, making required changes, and creating a new image in any format. When a JFFS2 image is copied directly from a JFFS2 flash partition, the resulting image is the size of the source partition, regardless of how much space is actually used for storage. Mounting the filesystem and using the mkfs.jffs2 utility to create a new image will result in a JFFS2 image without blank nodes. This can also be used to create multiple images for flashes with different characteristics, such as erase block sizes. This page describes two different methods of mounting JFFS2 images on a Linux PC.

Mounting JFFS2 Images using RAM

One method of mounting JFFS2 images uses the mtdram module to emulate an MTD device using system RAM. This works well for JFFS2 images that are less than approximately 32 MB but will not work for larger images since it requires allocating a large amount of system RAM. The basic steps of this process are as follows:

  1. Load mtdram and mtdblock modules.
  2. Use the dd command to copy the JFFS2 image to /dev/mtdblock0.
  3. Mount /dev/mtdblock0 as a JFFS2 filesytem.

In order to simplify this process, EMAC has created a script which takes the JFFS2 image, mount point, and the erase block size of the image as parameters. The default erase block size for this script is 128 KiB, which is the correct value for most NOR flashes used on EMAC products and some NAND flashes. The eraseblock size can be determined from the contents of /proc/mtd from the system that the image was copied from or created for. For example, if the value of the “erasesize” parameter is 00040000, the erase block size for the device is 256 KiB (0x40000 = 262144 bytes, 262144 / 1024 = 256 KiB). The jffs2_mount_mtdram.sh script is shown below.

#!/bin/bash

## Script to mount jffs2 filesystem using mtd kernel modules.
## EMAC, Inc. 2009

if [[ $# -lt 2 ]]
then
    echo "Usage: $0 FSNAME.JFFS2 MOUNTPOINT [ERASEBLOCK_SIZE]"
    exit 1
fi

if [ "$(whoami)" != "root" ]
then
    echo "$0 must be run as root!"
    exit 1
fi

if [[ ! -e $1 ]]
then
    echo "$1 does not exist"
    exit 1
fi

if [[ ! -d $2 ]]
then
    echo "$2 is not a valid mount point"
    exit 1
fi

if [[ "$3" == "" ]]
then
        esize="128"
else
        esize="$3"
fi

# cleanup if necessary
umount /dev/mtdblock0 &>/dev/null
modprobe -r mtdram &>/dev/null
modprobe -r mtdblock &>/dev/null

modprobe mtdram total_size=32768 erase_size=$esize || exit 1
modprobe mtdblock || exit 1
dd if="$1" of=/dev/mtdblock0 || exit 1
mount -t jffs2 /dev/mtdblock0 $2 || exit 1

echo "Successfully mounted $1 on $2"
exit 0

To mount an image with 256 KiB erase block size named rootfs.jffs2 on /mnt/jffs2 using jffs2_mount_mtdram.sh, run the script as shown below:

developer@ldc:~$ sudo ./jffs2_mount_mtdram.sh rootfs.jffs2 /mnt/jffs2 256

Once this has been done, the contents of the image should be accessible at /mnt/jffs2.

Mounting JFFS2 Images using a Loop Device

A second method for mounting JFFS2 images utilizes a loop device. This method is appropriate for larger images that cannot be mounted successfully with the mtdram approach. The process requires the following steps:

  1. Load loop, block2mtd, and jffs2 modules
  2. Create a loop device
  3. Set the block2mtd parameters for the loop device
  4. Mount the JFFS2 image

EMAC has created a script to simplify this process that takes the JFFS2 image, mount point, and image erase block size as parameters. The default erase block size for this script is 128 KiB, which is the correct value for most NOR flashes used on EMAC products and some NAND flashes. See the description of determining the correct erase block size to use in the previous section. The jffs2_mount_loop.sh script is shown below.

#!/bin/bash

## Script to mount jffs2 filesystem using mtd kernel modules.
## EMAC, Inc. 2011

if [[ $# -lt 2 ]]
then
    echo "Usage: $0 FSNAME.JFFS2 MOUNTPOINT [ERASEBLOCK_SIZE]"
    exit 1
fi

if [ "$(whoami)" != "root" ]
then
    echo "$0 must be run as root!"
    exit 1
fi

if [[ ! -e $1 ]]
then
    echo "$1 does not exist"
    exit 1
fi

if [[ ! -d $2 ]]
then
    echo "$2 is not a valid mount point"
    exit 1
fi

if [[ "$3" == "" ]]
then
        esize="128"
else
        esize="$3"
fi

# cleanup if necessary
umount /tmp/mtdblock0 &>/dev/null
umount $2 &>/dev/null
modprobe -r jffs2 &>/dev/null
modprobe -r block2mtd &>/dev/null
modprobe -r mtdblock &>/dev/null
sleep 0.25
losetup -d /dev/loop1 &>/dev/null
sleep 0.25

modprobe loop || exit 1
losetup /dev/loop1 "$1" || exit 1
modprobe block2mtd || exit 1
modprobe jffs2 || exit 1
if [[ ! -e /tmp/mtdblock0 ]]
then
    mknod /tmp/mtdblock0 b 31 0 || exit 1
fi

echo "/dev/loop1,${esize}KiB" > /sys/module/block2mtd/parameters/block2mtd

mount -t jffs2 /tmp/mtdblock0 "$2" || exit 1

echo "Successfully mounted $1 on $2"
exit 0

Usage for this script is identical to the jffs2_mount_mtdram.sh script discussed in the previous section.

相關推薦

Linux PC掛載JFFS2檔案系統

Mounting JFFS2 Images on a Linux PC It is possible to mount a binary JFFS2 image on a Linux PC without a flash device. This ca

linuxPC掛載jffs2檔案系統映像

我們在除錯硬體板時,經常需要做多個jffs2的根檔案系統映像,有時也要對比其他途徑得到的可用的jffs2根檔案系統映像。但jffs2的檔案系統映像不象光碟的映像檔案一樣可以通過loop裝置來掛載,總不可能一個個燒錄到硬體板去看吧。 後來到網上google了一把

linux檢視磁碟掛載檔案系統

命令:$ df -T -h [[email protected]_10_1_x_x ~]# df -T -h Filesystem Type Size Used Avail

一臺Linux伺服器掛載另一臺Linx伺服器檔案系統的方法

目標:在伺服器B上訪問伺服器A上指定的檔案系統 首先要配置伺服器A 編輯/etc/exports,加入: /home     192.168.1.1(rw)    #IP是伺服器B的地址, 目錄是要共享出的目錄 然後啟動nfs服務: /etc/init.d/nfs sta

怎樣在 Ubuntu 使用 ZFS 檔案系統 | Linux 中國

在 Linux 系統上,有大量的檔案系統能夠使用,那麼我們為什麼還要嘗試一個新的檔案系統?它們都工作的很好。不是嗎?可是它們並不全然同樣,當中的一些檔案系統具有很突出的長處。比如 ZFS。-- Nick Congleton 本文導航◈ 為什麼選擇 ZFS

Linux啟動過程分析》核心掛載檔案系統

說明:本文基於Linux2.6.29核心分析;其他核心版本僅供參考。   前邊通過原始碼情景分析,看過了匯流排、裝置、驅動及其發現機制,Linux2.6核心udev裝置節點建立相關;對於檔案系統,一直望而生畏,但核心學習、這部分又不可能繞的過去。目前對VFS中使用的has

linux下使用kpartx掛載虛擬檔案系統

linux下使用kpartx掛載虛擬檔案系統在linux中,如果映像檔案(.img)含有分割槽表的話,那麼用losetup這個程式來載入檔案系統就有點力不從心了。因為losetup只能載入無分割槽的檔案

從NFS啟動Linux掛載檔案系統

要搞嵌入式NFS確實必不可少,否則每次都要重啟煩都煩死。這裡總結在NFS建立過程中遇到的幾個問題。 下面記錄幾個遇到的問題 VFS: Cannot open root device “

linux-2.6.21核心中建立jffs2檔案系統(mtd分割槽的使用)

本文主要介紹如何在AT91SAM9261EK板子上製作和使用jffs2檔案系統,使用的是linux-2.6.21核心。 首先配置MTD $ make menuconfig 進入 Memory Technology Devices (MTD)

linux開發環境搭建(3)-nfs掛載檔案系統

前面講解了網絡卡配置和使用tftp下載核心,這次要講的是使用nfs掛載根檔案系統。 1、什麼是根檔案系統 所謂根檔案系統,也就是系統啟動後第一個掛載的目錄,根檔案系統包括Linux啟動時所必須的目錄和關鍵性的檔案,例如Linux啟動時都需要有init目錄下的

linux磁碟分割槽,建立檔案系統掛載,解除安裝,自動掛載

1 EMMC磁碟分割槽 fdisk -l /dev/mmcblk0, 命令p檢視分割槽情況,n配置分割槽大小,w儲存配置,d刪除分割槽,p退出不儲存配置 2 瀏覽檔案系統情況dumpe2fs /dev/mmcblk0p1檢視是否有檔案系統 3 建立檔案

linux掛載ntfs檔案系統

首先我們注意到ntfs是什麼東西,ntfs是一種檔案系統,現在主流有兩種檔案系統,是FAT與NTFS,他們兩個的區別就是NTFS格式可以解壓4G以上的檔案,(如果想研究透徹,我想應該去深入瞭解硬體儲存

【原創】Linux 系統移植日誌----jffs2檔案系統定製

【原創】Linux 系統移植日誌—-jffs2檔案系統定製 DATE:2011-9-13 目標: 熟練u-boot、linux系統、檔案系統的優化裁剪;精通系統移植;精通linux系統、檔案系統、uboot原理等。 第一天,嘗試在AT91SAM9

[置頂] 《Linux啟動過程分析》核心掛載檔案系統 http://blog.csdn.net/tankai19880619/article/details/12093239

說明:本文基於Linux2.6.29核心分析;其他核心版本僅供參考。   前邊通過原始碼情景分析,看過了匯流排、裝置、驅動及其發現機制,Linux2.6核心udev裝置節點建立相關;對於檔案系統,一直望而生畏,但核心學習、這部分又不可能繞的過去。目前對VFS中使用的hash表還未做研究,它在dent

如何在 Linux 虛擬機器擴充套件根檔案系統

問題描述 通過 Azure 平臺部署的 Linux 虛擬機器預設的根檔案系統容量有限,需要進行擴充套件。 問題分析 由於 Azure 平臺部署的 Linux 虛擬機器預設根檔案系統容量比較小,客戶在使用過程中,經常會出現根檔案系統用滿,導致虛擬機器不可用的情況,需要

Linux系統掛載NTFS檔案系統

  今天嘗試併成功的將一塊500G的行動硬碟掛載到了RHEL5的系統上,甚感欣慰。想到也許以後自己或其他同學們會有類似經歷,於是儘量細緻的記錄於此。     無論是一塊安裝了Windows/Linux雙系統的硬碟,還是通過USB連線的行動硬碟/U盤,都是可以掛載到Linu

linux基礎3-磁碟和檔案系統相關 LINUX支援哪些檔案系統 linux下磁碟分割槽詳解 圖文(fdisk;mkfs)

一 dumpe2fs :    在Linux使用過程中,我們如果要了解檔案系統的配置情況,可以使用dumpe2fs檢視ext2/ext3/ext4格式的檔案系統資訊。 命令格式: dumpe2fs [選項] 裝置 常用選項: -h  僅列出超級塊中的資訊

centos7多伺服器掛載同一檔案系統

1,主要命令 mount 這裡使用的服務端:237 掛載的客戶端有:235和236 2,伺服器端配置: rpm -qa |grep nfs yum install nfs-utils 編輯或新建以下檔案 vi /etc/exports /app/storage 192.168.1.

linux命令--使用fsck修復檔案系統

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

掛載檔案系統的實操

宿主機的NFS配置,不詳細描述; 1. 檔案系統的許可權 ,進入根目錄     #chmod -R 777 *    #chown -R nobody 2. 防火牆關閉 # service iptables stop 3.