Git for embedded devices with limited storage
Recently I have been playing around with OpenWRT, a firmware I unfairly derided in the past in favor of other firmwares like DD-WRT, Tomato, and Asus-wrt, but these days I have been delving into more deeply and am finding the level of customization is greater. I may write a separate article exploring all the different ways I find OpenWRT to be superior, but for now lets get to to it!
So what’s the problem with installing Git? First off it is roughly 4mb in size, when compressed! Once you extract it however it balloons to 7.1mb in size and that is a massive chunk of space for routers and small embeded devices that only have 16mb of storage.
I have never had to contemplate doing an install that did not take up local storage, because in most cases expanding storage, virtually or physically has been an option. Due to the nature of wanting to use this specific hardware, it forced me into looking into the alternatives. Of course I am aware of ramdisks since the 90’s, and ramdisks have all sorts of useful use case scenarios where you might want to the employ them, but typically for faster data retrieval, here we just need the space and the temporary nature of the install is moot as the utility can be installed manually per a reboot or scripted to re-install.
This device has built in memory that is also mounted as a /tmp folder and according to ‘df -h’ I have 64mb of tmp space to play with! You can also use ncdu for a better breakdown of what is taking up your space.
And as you can also see my overlay capacity is only 5.9mb in total, so installing git was never realistic, regardless of the device having 16mb of storage. It has obviously been partitioned up in a way that makes it inaccessible to me. Once option though is to download the imagebuilder for my model router that is available on github. I am however largely satisfied with the firmware as is, and would just like the addition of git, so here’s how to do that.
We’ll first want to cd into the tmp directory and create a downloads folder, we have plenty of space there.
cd /tmpmkdir ./downloads
Next we’ll download the git package we need for our specific router, yours may be a different architecture so you may need to seek yours out.
wget http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/packages/git_2.16.3-1_mipsel_24kc.ipk
opkg git-http ca-bundle# If you are on an official OpenWRT build then try the following
opkg install git git-http ca-bundle
And this is where the magic happens, opkg has the option of installing in ram, so the /tmp folder essentially and it is as simple as the following.
opkg install git_2.16.3-1_mipsel_24kc.ipk -d ramln -s /tmp/usr/bin/git /usr/bin/gitln -s /tmp/usr/share/git-core /usr/share/git-core
And that is it! You should now have a working copy of git on your linux embeded device. If anyone has any questions or a better alternative then please let me know!