{"id":47,"date":"2011-01-26T20:43:58","date_gmt":"2011-01-26T19:43:58","guid":{"rendered":"http:\/\/www.netquote.it\/nqmain\/?p=47"},"modified":"2011-12-17T04:12:22","modified_gmt":"2011-12-17T03:12:22","slug":"fonera-2-0n-usb-boot-script","status":"publish","type":"post","link":"https:\/\/www.netquote.it\/nqmain\/2011\/01\/fonera-2-0n-usb-boot-script\/","title":{"rendered":"Fonera 2.0n USB boot script"},"content":{"rendered":"<p>Some time ago I wrote script for Hacking Fonera Access Point. This script move root file system to USB device and permit any kind of installation and easily revert any changes to original state without stress for internal flash drive. In fact it&#8217;s stress USB device but it&#8217;s better than damage the internal flash!<\/p>\n<p>How it works:<br \/>\nFirst time the script copy entire Fonera root file system to USB device, next time everything except kernel is loaded from external USB. If no valid USB drive\/partition is detected it&#8217;s automatically load internal root file system after about 20s.<\/p>\n<p>Preparing USB drive:<br \/>\nCreate on USB device one or more partition with ext2 or ext3 file system. Finally add an empty file named &#8220;usbrootfsready&#8221; on the root of partition. <\/p>\n<p>Preparing Fonera:<br \/>\nWe need to gain access to Fonera shell and create file named &#8220;\/sbin\/usbrootfs&#8221; with this contents.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n# Fonera2.0n usbrootfs\r\n# Copyright (C) 2009 iwi \\at\\ hotmail \\it\\\r\n# exec &gt; \/home\/usbroot.log 2&gt;&amp;1\r\n\r\nUSBROOT=&quot;\/dev\/sda1&quot;\r\nUSBMNTP=&quot;\/mnt&quot;\r\nUSBFLAG=&quot;\/usbrootfsready&quot;\r\n\r\n\/sbin\/insmod ext2\r\n\/sbin\/insmod jbd\r\n\/sbin\/insmod ext3\r\n\/sbin\/insmod dwc_otg\r\n\r\nfor CNTR in $(seq 1 1 10)\r\ndo\r\n    sleep 2s\r\n    if &#x5B; -b &quot;$USBROOT&quot; ]; then \r\n        mount -o rw &quot;$USBROOT&quot; &quot;$USBMNTP&quot; &amp;&amp; {\r\n            if &#x5B; -f &quot;$USBMNTP$USBFLAG&quot; ]; then\r\n                # Copy to new root\r\n                rm &quot;$USBMNTP$USBFLAG&quot;\r\n                cd \/rom\r\n                tar -c * | tar -x -C $USBMNTP\r\n                cd \/jffs\r\n                tar -c * | tar -x -C $USBMNTP\r\n                cd $USBMNTP\r\n                rm `find | grep META_`\r\n                rmdir jffs\r\n                #rm var\r\n                #mkdir var\r\n                mkdir \/usr\/lib\/opkg\r\n                cd \/\r\n            fi\r\n            if &#x5B; -f &quot;$USBMNTP\/sbin\/init&quot; ]; then\r\n                # remount usb as rootfs\r\n                mount -o move \/proc $USBMNTP\/proc &amp;&amp; {\r\n                    pivot_root $USBMNTP $USBMNTP\/rom &amp;&amp; {\r\n                        mount -o move \/rom\/dev \/dev\r\n                        mount -o move \/rom\/sys \/sys\r\n                        mount -o move \/rom\/tmp \/tmp\r\n                        break\r\n                    }\r\n                    mount -o move $USBMNTP\/proc \/proc\r\n                }\r\n            fi\r\n            umount &quot;$USBROOT&quot;\r\n        }\r\n        break\r\n    fi\r\ndone\r\n<\/pre>\n<p>Now delete or rename &#8220;sbin\/init&#8221; and create new init file.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n# Fonera2.0n init override\r\n# Copyright (C) 2009 Toropov Ivan\r\n\r\n\/sbin\/usbrootfs\r\n\r\nexec \/bin\/busybox init\r\n<\/pre>\n<p>Don&#8217;t forget to mark this files as executables.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nchmod +x \/sbin\/init\r\nchmod +x \/sbin\/usbrootfs\r\n<\/pre>\n<p>It&#8217;s all. Reboot and enjoy hacking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago I wrote script for Hacking Fonera Access Point. This script move root file system to USB device<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-fonera","category-linux"],"_links":{"self":[{"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":9,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/posts\/47\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netquote.it\/nqmain\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}