over the mount’n

Okay, that was a terrible pun. I thought I’d share something today which is pretty cool although it gets a little technical at the end. You can actually edit the files on a tiny microSD card like you might have in some device like a 3D printer or similar. And you don’t have to have it running (like in your product/device) in order to do so.

Smart Things (IoT)

We live in a world of ever-smarter things. There’s a new term, the Internet of Things (IoT) which basically means that lots of the products we’re using now not only have little computers inside, but they also use the Internet in some way.

Tiny Hard Drives

Given the diminutive size of some of these new products, they often use the microSD card as an actual hard drive. These days, they include an entire operating system which boots up the product’s computer and provides a variety of functionality.

microsd

The Bleeding Edge

For some of us, we like to install the very latest version of software for something like this. Those updates sometimes come in the form of an entire image file for the microSD card in this case.

Instructions for editing files on an image file itself

Okay, so I have downloaded an image for a Raspberry Pi computer and the version name is Jessie. The name of the operating system itself which runs on this computer is called Raspbian, btw. The image’s filename is then raspbian-jessie.img, easy enough.

I’m running these commands on a Linux-compatible computer:


$ file raspbian-jessie.img

raspbian-jessie.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x8,138,2), startsector 8192, 129024 sectors; partition 2 : ID=0x3, start-CHS (0x8,138,3), end-CHS (0x213,120,37), startsector 137216, 8400896 sectors

So we’re interested in only one number here, that value after startsector for partition 2, namely 137216. Multiply that by 512 to get 70254592 which we use in the next command:

$ sudo mount raspbian-jessie.img -o offset=70254592 /mnt

This means, essentially, “open up the file indicated (at an offset of 7 million or so characters into that file) and show me everything that’s in it and put that in the /mnt folder area”.

So now, you can actually edit the image’s computer name in the /mnt/etc/hostname file, for example. Assuming we have done so, we now unmount the file:

$ sudo umount /mnt

And you’ve managed to edit its internal files in place! The typical activity next is to burn that image to another microSD, put it into your smart refrigerator’s computer or whatever and boot it up.

Conclusion

Okay, so you’re not as excited as I am but this is a giant leap forward in workflow for me. Since I maintain several of these image files, this is pretty cool stuff.

Imagine if you were trying to build a supercomputer with a hundred individual (small) computers and it were necessary to then build 100 different image files each with their own setup. This would be so not fun if you had to do this manually. Using this new method, you could script all this and then run it.  By the end of some lengthy process, you would have all hundred different image files as produced by this method. Huzzah…, right?

Advertisements

1 thought on “over the mount’n”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s