Mounting a raw disk image
[ Twentynineth in a series recreating the lost posts -- This was originally posted 09/08/10]
I have recently started moving my ZipitZ2 development from a combination of aboriginal linux, buildroot and scratchbox1 to a combination of aboriginal linux, buildroot and scratchbox2 which means I need a way to seed the development rootfs with a working rootfs. Now I could manually move files from a ZipitZ2 to the scratchbox2 rootfs but that is error prone as I might miss a file or two or I might mess up permissions and setting up device nodes etc. is a right PITA. The easiest thing to do is to use someone else's rootfs however they are normally distributed as a disk image with one or more partitions in the image which makes mounting them normally almost impossible a bit problematic especially with large disk images (this is not completely true any more if you are using a modern distro with the latest versions things like util-linux). However there is a nice linux program available (available in every linux distribution there is as it's an important command) called losetup that will let us use a disk image as if it is a disk.
We'll use mozzwald's ubuntu rootfs image as an example of how to mount a partition within a disk image. After downloading and untar'ing his rootfs image you need to mount the image as a disk using losetup
sudo losetup /dev/loop0 zubuntu-jaunty-basic-rc1_05172010.img
Once you have done that you can then treat the device /dev/loop0 as if it was a real disk, all the utilities and programs that manipulate disks in linux will work as expected. So what we now need to do is workout where the first partition (or any other partition we are insterested in) is located within the disk image. To do that we use fdisk.
sudo fdisk -lu /dev/loop0
we use the u option as we want to get the fdisk to talk in sectors and not cylinders.
To calculate the offset multiply the units (512) by the partition's start (243), which in this case gives us 124416. Detach the disk image from the loop device.
sudo losetup -d /dev/loop0
and then reattach the disk image to the loop device using the calculated offset.
sudo losetup -o 124416 /dev/loop0 zubuntu-jaunty-basic-rc1_05172010.img
and then mount the loop device as normal.
sudo mount /dev/loop0 /media/rootfs
and you are done and can copy the files from the disk image to wherever you want.
[update: there are other less convoluted ways to mount raw disk images if you have a recent version of util-linux on your system. after finding out the offset just use the offset option in mount. Geordy also let me know that volume 27:2 (Summer 2010) of 2600 magazine (towards the back of the issue) there is more clever usage of the loop back file system with regard to mounting an ISO as writable and tweaking some settings with it. ]
ZipitZ2 JTAG
[ Twentyeighth in a series recreating the lost posts -- This was originally posted 21/08/10]
Sweetlilmre has posted a nice writeup on how to perform the JTAG mod on a ZipitZ2. There is also an old writeup about the JTAG mod available here
