OpenWrt Forum Archive

Topic: Mounting a squashfs image

The content of this topic has been archived on 7 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have an image of a squashfs rootfs . ie cut from a flash(rom) image with dd . I would like to mount this , open it up , do a small edit to a script file, resquash it back , then re write it back to the device.

I have an asus wl-600g running openwrt here that i could use . I believe the asus and the nsd100 are both little endian , if that matters?

the device is a emprex nsd100. there is /dev/mtd3 which is all squashfs. I was hoping to use dd to put the flash image back where it came from.

dd if=/mnt/data/public/squashfs.bin of=/dev/mtd3

where squashfs.bin is the modified file.

But I am stuck as to how to mount the file.

Ant help much appreciated.

pale

All done now !

Well, how did you solve your problem?

Not with openwrt .

First off the squashfs image included the kernel. I found the point where the fs started by the gzip header and cut there. then I unzipped it with winrar. saved the resultant file . I then had to create a loop device in the /dev directory then I could mount the saved/unzipped file as a loop device .  I did my edit , unmounted and gzip'ed it up to put it all back together and pasted it back into the image. worked a treat once I had worked it all out.

pale wrote:

Not with openwrt .

First off the squashfs image included the kernel. I found the point where the fs started by the gzip header and cut there. then I unzipped it with winrar. saved the resultant file . I then had to create a loop device in the /dev directory then I could mount the saved/unzipped file as a loop device .  I did my edit , unmounted and gzip'ed it up to put it all back together and pasted it back into the image. worked a treat once I had worked it all out.

This is all great for you, but if you could be more specific, it may be more helpful to others.

(1) How did you find the GZIP header?
(2) What was the gzip header in your case?
(3) What was the content of the unzipping?
(4) How did you create the loop device?
(5) what command(s) did you use to mount it?

Cheers!

from my post at http://emprex.codejs.com ( join to see more stuff and forum topics and down load flash image  for emprex nsd-100)

*****************************



This is how it is done ( from my crib notes ). It looks quite strait forwards , and it is, but it took quite a bit of time and reading of other web sites. thanks to http://tinyhack.com/ for the info on how to find the start of the ramdisc. The guy at tinynack has done far more with a similar device, and this place http://emprex-nas.blogspot.com/2008/08/ ... d-100.html for getting me going with telnet and debian.

***********************************************
On a windows PC

load V03R14_eon.bin into hex editor . I use "hex editor neo" ( demo lasts 14 days )

search for 1f 8b 08 ,this is the header of a gzip archive. ( search in hex not ascii )

found at two places, cut at 2nd 0x0017af34 just before it says ramdisk ,cut right to the end of the file. The ramdisk isn't as big as this but when we open it up the extra bit will be left.

save as file ending in gz ie ramdiskfs.gz

I opened this file with winrar

http://www.rarlab.com/

you get a file called ramdisk ,extract and save it to a file called ramdisk some where on your pc.

with your nsd100 running and your pc looking at the samba share "public" copy to "public"

on the nsd100 this will be in
/mnt/data/public

Now login to the nsd100 via telnet
type

mknod /dev/loop0 b 7 0
mkdir /mnt/ram
mount -o loop /mnt/data/public/ramdisk /mnt/ram

edit /mnt/ram/etc/init.d/rc.sysinit ( I did this across samba as I have a share on the root and use SCiTE http://www.scintilla.org to edit the file as this does not create CR at the end of the line )

add

#start telnet demon
echo "pts/0" >> /etc/securetty
/usr/sbin/telnetd

#wait 15 seconds
sleep 15
#run script boot in public

/mnt/data/public/boot


just before this line at the end

/bin/echo "Sysinit done"

save file


umount /mnt/ram
( need to be out of /ram directory to do this.just type cd /)

cd /mnt/data/public
gzip ramdisk

to recompress. it takes 5 minutes or so just watch the telnet session for your cursor to come back. I did this on the nsd100 as I knew it would be able to decompress it later when it boots . dont do it in winrar the compression is the wrong type and will brick your nsd100.

this makes ramdisk.gz

on the windows pc copy the ramdisk.gz file back to the pc

paste this back into the flash image with hex edit neo

make sure the paste goes in at address 0x0017af34 starting with 1f 8b 08 00

and the end bytes of what you are pasting are 00 00 40 01 ( my image was abit smaller than the original )

save flash image . as V03R14_new.bin


reflash device with new patched image using the update firmware page on the nsd100 web interface.
this takes a few minutes.

it will reboot its self , you config should stay , IP address etc.

on the public share you need to add the script file "boot" . When the nsd100 boots it will look for this and run it.

here is mine

#!/bin/sh
#echo "pts/0" >> /etc/securetty
#/usr/sbin/telnetd
/mnt/data/public/debian/usr/sbin/chroot /mnt/data/public/debian /etc/init.d/ssh start

/mnt/data/public/debian/usr/sbin/chroot /mnt/data/public/debian lighttpd -f /etc/lighttpd/lighttpd.conf

/usr/sbin/setled --buzzer=1 >/dev/null
/usr/sbin/setled --buzzer=1 >/dev/null
/usr/sbin/setled --buzzer=1 >/dev/null

you dont need the telnet bit anymore as this is in the rc.sysinit.

the ssh bit and lighttpd bit are to do with debian ignore them at the moment I will do another post about them later.

the buzzer bit buzzes the buzzer 3 times when all is done to let you know it has run.

this script must have root privileges

once made go to telnet and type

chmod 755 /mnt/data/public/boot

I am not sure if having CR at the end of each line will upset this.

I now have debian running and a multitude of other software including a gui desktop via vncserver ( Xwindows)

Pale

(Last edited by pale on 30 Mar 2011, 20:34)

Awesome, great writeup! I love it when people are being pedagogical!

The discussion might have continued from here.