Topic: How to modify the root filesystem

I was having a bit of trouble with an application I was trying to run which required specific directories (so I could at least make mountpoints) off of the root filesystem.  This is impossible traditionally as the chumby's / partition is a cramfs (read only) filesystem.  Here is how to work around this limitation.  Please bear in mind that there is a limited amount of space on the chumby, so don't add anything too large.  I do not personally know what kind of error correction or size checking is done before it writes the new cramfs out, so I wouldn't suggest chancing it.  I'd also highly suggest creating the directories needed to mount another cramfs or nfs mount with the real data.

First thing, you must enable ssh on the chumby and connect to it

SSH to the chumby, and determine which "disk" is mounted as your / partition

    chumby:~# df -h 
    Filesystem                Size      Used Available Use% Mounted on
    /dev/mtdblock5           34.1M     34.1M         0 100% /

Plug in a usb disk and mount it to /mnt/usb, or connect to an nfs directory with r/w access so that we can create the chumby.cramfs file.  In the following example I am creating it on a usb disk.

chumby:/# dd if=/dev/mtdblock5 of=/mnt/usb/chumby.cramfs
45056+0 records in
45056+0 records out

Now that you have the cramfs image, take it back over to your linux workstation.  To do this you will need to have a kernel that supports cramfs, and you will need the appropriate cramfs tools installed.  It's going to vary by distribution, but google gave me an answer within about a minute for mine.

linuxbox:/root# mount -o loop -t cramfs /media/usb/chumby.cramfs /mnt/tmp

Again you are left with a read only environment, so I copied it to a new (writable) structure as such:

linuxbox:/root# mkdir /root/chumby
linuxbox:/root# (cd /mnt/tmp ; tar cvfp - .)|(cd /root/chumby ; tar xvfp -)

Now you have an exact copy, so you can umount /mnt/tmp as you no longer need it.  Make the changes that you want to make to this new filesystem, keeping in mind that small size is key!  Again, I just created directories, I didn't add any actual files.  Once you are finished, we need to recreate the cramfs filesystem

linuxbox:/root# mkfs.cramfs chumby/ rfs1.bin
linuxbox:/root# zip rfs1.bin.zip rfs1.bin

Copy this back to your vfat formatted usb drive, placing it into a directory called update2/.  It is very finnicky about this, so make sure you set the structure up right!  Turn off your chumby and plug the usb drive in.  Then, power on the chumby while pressing the touchscreen, and continue pressing it until you get into special options. Select the menu option to update the chumby, and then select update via USB.

After it finishes flashing, connect via ssh again and verify that your new directories or files are in place.  Congratulations, you are done!

Re: How to modify the root filesystem

Thanks for the guide!  This makes it a lot easier.

I have a couple of applications that I don't have the source to but are arm compiled as well, this may make it easier to get those running, due to the same reasons you mentioned in your other thread (inability to places files in place).

That's cool, now I can create a few extra mount points that can link to the USB disk.

Great work,  and another reason why Chumby's model is so great. smile

Re: How to modify the root filesystem

What happens if the structure isn't right? Is the chumby dead then, or can I still use the update-mechanism to redeploy the original software?

Re: How to modify the root filesystem

Assuming you don't overwrite the safe mode partition as well, you should be able to restore the primary partition using a standard USB firmware update.

You are free to distribute modified versions of the primary partition as long as you do *not* include the Flash Player executable (chumbyflashplayer.x)  - that binary is not licensed for redistribution, either by us or Adobe.  You will also be responsible for complying with the terms of the licenses of any software included in the distribution, including availability of source code, etc. Under the GPL, for instance, you must pass on the "written offer" (included in our manual), and any commercial distribution requires you to provide source directly, not simply pointing at our upstream repository.

Obviously, Chumby Industries will not provide any support for devices running modified firmware.

Re: How to modify the root filesystem

Thanks deadbydawn, that helped me out a lot.  I was trying to do some of the operations as a regular user, but it wasn't working out.  I was afraid that I had bricked the thing but I finally restarted your instructions (at the chumby.cramfs step), did everything as root, and then it worked.

FYI, I'm using Ubuntu Gutsy and the cramfs stuff just seemed to be there.  Not sure if I did anything in the past to add it, but it all just seemed to work.  Also, I added over 1M of files to the Chumby file system and everything still seems to work fine.

I'm pretty psyched about this - I thought that I was going to have to ship my project with a USB drive sticking out the back, but this is much cleaner.  Thanks again for the timely post.

Re: How to modify the root filesystem

Can somebody from Chumby make it easy on us lazy people and tell us how big the cramfs filesystem can be?  Also, this information should be put on the wiki.  If I get some more information (and time), I will post it (including Duane's disclaimer on licensing).

Linux Guy - Occasional Chumby Hacker

7 (edited by Materdaddy 2008-06-02 20:37:04)

Re: How to modify the root filesystem

Can somebody give me an md5sum of their mtdblock5?  I'm not able to mount it loopback.  Here's my md5sum:
55f22c1de9aa7c502c9696a2d6f2161e  mtdblock5-root-disk-1

After playing around with hexdump on the image, I'm wondering if I need a skip offset or something, as the first 0x4000 is all 0xFs, and the next 0x200 is 0x0's before I see anything that looks useful.

I swear I've done this before...  I can get mtdblock3's data and mount that file system, but not the data from mtdblock5!

Linux Guy - Occasional Chumby Hacker

Re: How to modify the root filesystem

UPDATE: (I hate threads where I talk to myself)

It appears I needed to offset the first 0x4000 of my dump in dd.  I'm not sure why.  It appears that there is approximately 6 Mb of space NOT used by Chumby that is still available in this area of flash.  I'm sure they'll be using it up over time, but for now that's about how much room we can play with.

My operations:

chumby:~# dd if=/dev/mtdblock5 of=/mnt/usb/mtdblock5-data skip=32 bs=512 count=31344
31344+0 records in
31344+0 records out
chumby:~# md5sum /mnt/usb/mtdblock5-data
71b9597f7c43957ab9d9ff9cb183eaa0  /mnt/usb/mtdblock5-data

This is the md5sum of the shipped image from the 1.5 firmware.  I can successfully mount that on my host system.  Now I'm wondering if I dd a new filesystem over the existing one, do I need to add "seek=32" to a dd command for that to work?  Is it safe to dd while the system is running, and reboot to my new rootfs?

Linux Guy - Occasional Chumby Hacker

Re: How to modify the root filesystem

Materdaddy wrote:

Can somebody from Chumby make it easy on us lazy people and tell us how big the cramfs filesystem can be?  Also, this information should be put on the wiki.  If I get some more information (and time), I will post it (including Duane's disclaimer on licensing).

The max partition sizes are as follows:

partition  name            bytes

mtd0       Boot Loader    884736
mtd1       PSP           1769472
mtd2       Kernel2       2129920
mtd3       Root Disk2    7569408
mtd4       Kernel1       2654208
mtd5       Root Disk1   21757952

10

Re: How to modify the root filesystem

If you don't want to deal with a read-only cramfs partition, you can use mkfs.jffs2 to create a writable root file system.  Just replace the 'mkfs.cramfs' step in deadbydawn's instructions with:

mkfs.jffs2 -l --pagesize=0x200 --eraseblock=0x4000 -d chumby/ rfs1.bin

You may also need to align the partition before zipping by doing:

wget http://files.chumby.com/source/ironforge/build396/align.pl
perl align.pl rfs1.bin
zip rfs1.bin.zip rfs1.bin

Note: I haven't tested this, so be careful wink

Re: How to modify the root filesystem

Please forgive me if this is too tangential, but would there be a lot of work to implement an approach using something nlike UnionFS, where the root file system is untouched, but the modifications and additions are kept on the usb drive?  This would potentially avoid bricking the beast.

wayn3w

Re: How to modify the root filesystem

Ken wrote:

If you don't want to deal with a read-only cramfs partition, you can use mkfs.jffs2 to create a writable root file system.  Just replace the 'mkfs.cramfs' step in deadbydawn's instructions with:

mkfs.jffs2 -l --pagesize=0x200 --eraseblock=0x4000 -d chumby/ rfs1.bin

You may also need to align the partition before zipping by doing:

wget http://files.chumby.com/source/ironforge/build396/align.pl
perl align.pl rfs1.bin
zip rfs1.bin.zip rfs1.bin

Note: I haven't tested this, so be careful wink

Will that work since the kernel command line includes rootfstype set to cramfs?

chumby:~# cat /proc/cmdline
console=ttyS0,38400 root=/dev/mtdblock5 rootfstype=cramfs chumby_hwversion=3.7

I've thought about that, but dropped it because of the kernel parameter.  I've also thought about using pivot_root to use a filesystem from a USB stick.

Linux Guy - Occasional Chumby Hacker

13

Re: How to modify the root filesystem

Ah, good catch. smile

The boot loader (2bl.c) would need to be modified in order to change the kernel parameters.  However, I don't recommend reflashing the boot loader, because if you corrupt the bootloader image, you end up bricking the device, leaving yourself no way to reflash/update the firmware.  If you make modifications to the boot loader, proceed at your own risk.

Re: How to modify the root filesystem

Ken wrote:

Ah, good catch. smile

The boot loader (2bl.c) would need to be modified in order to change the kernel parameters.  However, I don't recommend reflashing the boot loader, because if you corrupt the bootloader image, you end up bricking the device, leaving yourself no way to reflash/update the firmware.  If you make modifications to the boot loader, proceed at your own risk.

What about hacking the kernel to ignore bootloader parameters, and use it's own?  I've seen a thread about that, but it was really out of date.  In fact, I think the OE (OpenEmbedded) kernel has a patch already prepared to ignore the bootloader's parameters.

Also, if you corrupt the bootloader, can you get it back using jtag, or i2c?

Linux Guy - Occasional Chumby Hacker

15

Re: How to modify the root filesystem

Materdaddy wrote:

What about hacking the kernel to ignore bootloader parameters, and use it's own?

I'll look into this.

Re: How to modify the root filesystem

FYI, Here's the thread: http://forum.chumby.com/viewtopic.php?id=1469

Looks like "daniel" figured it out and it should work.  I may test this one night this week if I get "chumby time" again.

Linux Guy - Occasional Chumby Hacker

17

Re: How to modify the root filesystem

Yeah, daniel's instructions in that thread should work just fine.

18

Re: How to modify the root filesystem

Materdaddy wrote:

Also, if you corrupt the bootloader, can you get it back using jtag, or i2c?

See this thread for unbricking a chumby (updating the entire firmware, including the bootloader) via serial.

Re: How to modify the root filesystem

Ken wrote:
Materdaddy wrote:

Also, if you corrupt the bootloader, can you get it back using jtag, or i2c?

See this thread for unbricking a chumby (updating the entire firmware, including the bootloader) via serial.

Thanks!  That could be helpful if I REALLY screw something up!

Linux Guy - Occasional Chumby Hacker

20 (edited by hastingsgwen 2010-09-18 00:07:39)

Re: How to modify the root filesystem

smile.. I managed to lunch 1 chumby classic by following the instructions in the first posting. I was trying to disable the getty to ttyUSB0 . I can get to the special ops screen or during normal boot just to all blue circles page just after the initial 2 circles.

I have restoring release 172 from USB and a reboot... no joy..
I reset to factory parameters no joy
I restored my own debian ext2/3 compatible kernel no joy..
I tried dding the cramfs from another chumby classic updated to 1.7.2 and used the procedure here to try and make a clean copy of the cramfs and recreate it no joy..
which MTD is the cramfs  written  and should I just unpack it from 1.7.2  and write just that component during a special ops USB restore.. which directory..?

update1/update2?? something else??


     need someone to hit me with a clue stick I guess smile

      gwen

ps and yes once I get this chumby working again then I will try all the above till I either get it working or find out which step I missed
smile

Re: How to modify the root filesystem

ok pulled the rfs1.bin.zip from update 1.72   put it into update2 and I have my chumby back after the special ops..now I just have to figure out where my preparation of my replacement cramfs is going wrong and I will finally have the thrice damned getty turned off...
and the ttyUSB0 port finally free to use.


      gwen

Re: How to modify the root filesystem

One thing you might try, and this is completely theoretical, is something like this:

cp -a /etc /tmp/etc
mount -obind /tmp/etc /etc
vi /etc/inittab
[edit inittab to remove reference to /dev/ttyUSB0]
kill -HUP 1

That'll temporarily make /etc writable, as it will actually be located in /tmp/etc.

Re: How to modify the root filesystem

Thanx,
that of course will work also... (feeling dumb of course right now)(I KNEW that)... real issue is I DO want to be able to make limited mods to the cramfs but jffs2 and mod of the arguments to the kernel is starting to look real attractive here ,  so to be able to reconstruct cramfs successfully I think I need to run a few more iterations of the above to try and see if I can discover what I am doing incorrectly. Meanwhile the getty sits mute smile


      gwen