{"id":690,"date":"2012-11-23T23:59:46","date_gmt":"2012-11-23T23:59:46","guid":{"rendered":"https:\/\/trouble.org\/?p=690"},"modified":"2013-08-15T19:20:06","modified_gmt":"2013-08-15T19:20:06","slug":"mounting-jffs2","status":"publish","type":"post","link":"https:\/\/trouble.org\/?p=690","title":{"rendered":"mounting jffs2"},"content":{"rendered":"<p>After mounting a bunch of filesystems I thought I&#8217;d just whip up a little shell script to help me out when working with jffs2 images, mtd, and linux (only tested on centos 6.) I won&#8217;t go over how to get kernel support and all that crap &#8211; there are many guides, and while many won&#8217;t work eventually something will for you too ;(<\/p>\n<p>This one is fairly simple to use; assuming you have mounting jffs2 at all, it assumes the directory in \/mnt exists (I just named mine &#8220;\/mnt\/jffs2&#8221;) and that the device in question to be mounted will be &#8220;\/dev\/mtdblock0&#8221; (both are vars at the top of the script.) It uses flash-erase to prep the \/dev file (currently clears out 4megs there; as long as the image to be mounted is smaller, no problemo.) Not much error checking, but it works for me&#8230; in case someone else might have to deal with this stuff&#8230; should be modestly easy to change.<\/p>\n<p>On Ubuntu you might do the following prior to running this script (the initial &#8220;#&#8221; is the root prompt):<\/p>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\"># modprobe mtd<\/div><\/div>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\"># modprobe jffs2<\/div><\/div>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\"># modprobe mtdram<\/div><\/div>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\"># modprobe mtdchar<\/div><\/div>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\"># modprobe mtdblock<\/div><\/div>\n<div><\/div>\n<div><\/div>\n<p>Usage of below script simply &#8220;j-mount.sh jffs2-image&#8221;; it&#8217;ll complain if it can&#8217;t do it.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;height:800px;\"><div class=\"bash codecolorer\">:<br \/>\n<br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"co0\"># try to mount a jffs2 fs from a file image... assumes<\/span><br \/>\n<span class=\"co0\"># kernel is ready to rumble<\/span><br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"co0\"># Use: $0 jffs2-image-file<\/span><br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"co0\">#<\/span><br \/>\n<br \/>\n<span class=\"re2\">usage<\/span>=<span class=\"st0\">&quot;Usage: $0 jffs2-image-file&quot;<\/span><br \/>\n<br \/>\n<span class=\"re2\">mtd<\/span>=<span class=\"st0\">&quot;\/dev\/mtdblock0&quot;<\/span><br \/>\n<span class=\"re2\">mnt<\/span>=<span class=\"st0\">&quot;\/mnt\/jffs2&quot;<\/span><br \/>\n<br \/>\n<span class=\"re2\">image<\/span>=<span class=\"st0\">&quot;$1&quot;<\/span><br \/>\n<br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"co0\"># 1024*1024*4 = four megs<\/span><br \/>\n<span class=\"co0\">#<\/span><br \/>\n<span class=\"re2\">four<\/span>=<span class=\"nu0\">4194304<\/span><br \/>\n<br \/>\n<span class=\"kw1\">if<\/span> <span class=\"br0\">&#91;<\/span> <span class=\"st0\">&quot;x<span class=\"es2\">$image<\/span>&quot;<\/span> == <span class=\"st0\">&quot;x&quot;<\/span> <span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"re1\">$usage<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">1<\/span><br \/>\n<span class=\"kw1\">fi<\/span><br \/>\n<br \/>\n<span class=\"kw1\">if<\/span> <span class=\"br0\">&#91;<\/span> <span class=\"sy0\">!<\/span> <span class=\"re5\">-b<\/span> <span class=\"re1\">$mtd<\/span> <span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;<span class=\"es2\">$mtd<\/span> file doesn't exist or isn't a block device: <span class=\"es2\">$usage<\/span>&quot;<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">2<\/span><br \/>\n<span class=\"kw1\">fi<\/span><br \/>\n<br \/>\n<span class=\"kw1\">if<\/span> <span class=\"br0\">&#91;<\/span> <span class=\"sy0\">!<\/span> <span class=\"re5\">-d<\/span> <span class=\"re1\">$mnt<\/span> <span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;<span class=\"es2\">$mnt<\/span> directory doesn't exist: <span class=\"es2\">$usage<\/span>&quot;<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">2<\/span><br \/>\n<span class=\"kw1\">fi<\/span><br \/>\n<br \/>\n<span class=\"re2\">jmnt<\/span>=$<span class=\"br0\">&#40;<\/span><span class=\"kw2\">df<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">grep<\/span> <span class=\"re1\">$mnt<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<br \/>\n<span class=\"kw1\">if<\/span> <span class=\"kw3\">test<\/span> <span class=\"re4\">$?<\/span> == <span class=\"nu0\">0<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n<span class=\"kw3\">echo<\/span> Won<span class=\"co3\">\\'<\/span>t <span class=\"kw2\">mount<\/span> over another <span class=\"kw2\">file<\/span> system at <span class=\"re1\">$mnt<\/span>:<br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot; <span class=\"es2\">$jmnt<\/span>&quot;<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">3<\/span><br \/>\n<span class=\"kw1\">fi<\/span><br \/>\n<br \/>\n<span class=\"co0\"># \/dev\/mtdblock0 4096 544 3552 14% \/mnt\/jffs2<\/span><br \/>\n<br \/>\n<span class=\"co0\"># erase the past occupants....<\/span><br \/>\n<br \/>\n<span class=\"kw3\">echo<\/span> erasing <span class=\"re1\">$mtd<\/span><br \/>\nflash_erase <span class=\"re1\">$mtd<\/span> <span class=\"nu0\">0<\/span> <span class=\"nu0\">0<\/span><br \/>\n<br \/>\n<span class=\"kw3\">echo<\/span> copying <span class=\"re1\">$image<\/span> to <span class=\"re1\">$mtd<\/span><br \/>\n<span class=\"kw2\">dd<\/span> <span class=\"re2\">if<\/span>=<span class=\"re1\">$image<\/span> <span class=\"re2\">of<\/span>=<span class=\"re1\">$mtd<\/span> <span class=\"re2\">bs<\/span>=<span class=\"re1\">$four<\/span> <span class=\"re2\">count<\/span>=<span class=\"nu0\">1<\/span><br \/>\n<br \/>\n<span class=\"kw3\">echo<\/span> mounting <span class=\"re1\">$image<\/span> on <span class=\"re1\">$mnt<\/span><br \/>\n<span class=\"kw2\">mount<\/span> <span class=\"re5\">-t<\/span> jffs2 <span class=\"re1\">$mtd<\/span> <span class=\"re1\">$mnt<\/span><br \/>\n<br \/>\n<span class=\"kw1\">if<\/span> <span class=\"br0\">&#91;<\/span> <span class=\"re4\">$?<\/span> <span class=\"re5\">-eq<\/span> <span class=\"nu0\">0<\/span> <span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">echo<\/span> win, it worked - <span class=\"re1\">$image<\/span> has been mounted on <span class=\"re1\">$mnt<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"kw2\">df<\/span> of newly mounted filesystem:<br \/>\n<span class=\"kw2\">df<\/span> <span class=\"re1\">$mnt<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"kw2\">ls<\/span> <span class=\"re5\">-lasg<\/span> of newly mounted filesystem:<br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-lasg<\/span> <span class=\"re1\">$mnt<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw1\">else<\/span><br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw3\">echo<\/span> no luck this time....<br \/>\n<span class=\"kw3\">echo<\/span><br \/>\n<span class=\"kw1\">fi<\/span><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>After mounting a bunch of filesystems I thought I&#8217;d just whip up a little shell script to help me out when working with jffs2 images, mtd, and linux (only tested on centos 6.) I won&#8217;t go over how to get kernel support and all that crap &#8211; there are many guides, and while many won&#8217;t [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,176,146,6],"tags":[175,178,177],"class_list":["post-690","post","type-post","status-publish","format-standard","hentry","category-code","category-embedded","category-hack","category-tech","tag-all-that-jazz","tag-flash","tag-mtd"],"_links":{"self":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=690"}],"version-history":[{"count":8,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":886,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/690\/revisions\/886"}],"wp:attachment":[{"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}