Move OS to USB storage PDF Print E-mail
Written by Jim Kinter, K5KTF   


One of the big issues with a Mesh node as it comes from the factory is the amount of available storage onboard and memory.


Now that you have the USB mod done ( http://www.broadband-hamnet.org/applications-for-the-mesh/114-usb-mesh-node.html ), you can plug in USB storage and use it for storage. This can be a USB thumbdrive, or even an external drive like you have in your computer/laptop.


One problem is, if you load packages, they will still load to the onboard flash and the system, unless you move the OS over to the USB storage.


I bought a 4GB USB thumbdrive specifically for this project, for about $14.00. I partitioned it with 1GB swap partition and a 3GB EXT2 partition for file storage. That in essences gives me a gig of ram !


And here is how we do it, step-by-step, with kudos and credit to http://www.rooot.net/en/geek-stuff/openwrt/36-mount-external-usb-root-partition-openwrt.html :

  • Plug your USB storage (from now on I will refer to it as the 'stick', be it a thumbdrive or IDE/SATA hardrive) into an existing Linux computer, and using the computer, create at least 2 partitions on the stick: one as Linux Swap, and the second (or more) as EXT2.
  • You can format both partitions, using mkswap on the 1st, and mke2fs on the second (if you need help with these commands, ask our friend, Mr. Google).
  • Once they are formatted, remove the stick from the computer and plug it into the mesh node.
  • Once its plugged into the node, SSH in to the node and run dmesg. It should show that the node has recognized the stick and show details about the hardware. For mine, it maps it to /dev/scsi/host0/bus0/target0/lun0/part1 (the swap partition) and /dev/scsi/host0/bus0/target0/lun0/part2 (the EXT2partition). If it does not see the stick, or it gives errors, make sure you have the proper packages loaded (USB-storage, EXT2, etc). Reboot with the stick plugged in, re-SSH, and dmesg again.
  •  Lets go ahead and give us some headroom by turning swap on, using the stick with 'swapon /dev/scsi/host0/bus0/target0/lun0/part1' . 
  • So now, lets mount the storage portion of the stick:
    • mkdir -p /mnt/root
    • mount /dev/scsi/host0/bus0/target0/lun0/part2 /mnt/root
  • And now we copy the OS onto the new mount point for the stick:
    • tar cvO -C / bin/ etc/ root/ lib/ sbin/ usr/ www/ var/ | tar x -C /mnt/root
    • mkdir -p /mnt/root/tmp && mkdir -p /mnt/root/dev && mkdir -p /mnt/root/proc && mkdir -p /mnt/root/jffs && mkdir -p /mnt/root/mnt/openwrt && mkdir -p /mnt/root/sys  (this should be all one line)
  • Here is some code you can copy into a new file you create,  /etc/init.d/mountusb  :


      #!/bin/sh /etc/rc.common
      EXTERNAL_PARTITION=/dev/scsi/host0/bus0/target0/lun0/part2

      START=41

      start () {
      echo "loading USB and ext2 modules"

      for module in usbcore usb-ohci uhci ehci-hcd scsi_mod sd_mod usb-storage jbd ext2; do
      insmod $module
      done
      sleep 2s

      [ "$FAILSAFE" != "true" ] && [ -b $EXTERNAL_PARTITION ] && {
      mount $EXTERNAL_PARTITION /mnt/root
      [ -x /mnt/root/sbin/init ] && {
      mount -o move /proc /mnt/root/proc && \
      pivot_root /mnt/root /mnt/root/mnt/openwrt && {
      mount -o move /mnt/openwrt/dev /dev
      mount -o move /mnt/openwrt/tmp /tmp
      swapon /dev/scsi/host0/bus0/target0/lun0/part1
      }
      }
      }
      }


  • After you save mountusb, you need to make it executable ' chmod +x /etc/init.d/mountusb ' and then if you want it to start automatically everytime you boot, run this: ' cd /etc/rc.d/ && ln -s ../init.d/mountusb S41mountusb '. That will start it after the USB modules and stuff loads.
  • Here is the extremely hard part..... type  ' reboot '  and then WAIT that excrutiating 1 minute to see if it worked.


Once it reboots, a quick ' mount ' will tell you if it worked, as you should see something like ' /dev/scsi/host0/bus0/target0/lun0/part2 on / type ext2 (rw) ' as the last line. If you dont see that root ( / ) is mounted to the /dev/scsi/blah/part2, then it didnt start properly for some reason. Go back and check each step, or run ' /etc/init.d/mountusb start ' and see if there are any errors.

If after running it manually and typing ' mount' again, you DO now see it, then check why the rc.d isnt functioning properly (maybe its still loading before USB or something).


If you do see that root has been mounted to the USB stick, you are now free to load all the packages you want (depending on the size of the USB storage of course) and do many many things almost impossible with an HSMM-MESH node before.

  

If you come up with a novel use with the USB and extra storage, email me, This e-mail address is being protected from spambots. You need JavaScript enabled to view it , and I will be glad to post your story and give you full credit.


Thanks and 73

Jim

K5KTF





    Last Updated on Wednesday, 24 June 2015 07:09
     
    SPONSORED AD: