>>>>> "Howard" == Howard Lowndes <[EMAIL PROTECTED]> writes:
Howard> I have a disk image of a CompactFlash disk as a file on a PC.
Howard> The image was created by using dd.
Howard> I know that the image has a partition table, a Linux (83)
Howard> partition and a Linux Swap (82) partition. The Linux
Howard> partition is formatted ext2.
Howard> I want to be able to mount the Linux partition rw somewhere
Howard> onto the PC's file system so that I can work on it using an
Howard> editor.
Here's a script I use for loopback mounting a partitioned disk image.
It's not particularly efficient.
----
#!/bin/sh
# Warning: this code isn't particularly safe.
#
if [ $# -ne 2 ]
then
echo >&2 "Usage: $0 file partitionnumber"
exit 1
fi
#
# Get start of partition n
# Usage:
# get_offset partitionNumber filename
#
function get_offset()
{
parted $2 unit b print | sed -n 's/^'$1'[ ][
]*\([0-9]*\)B.*/\1/p'`
}
#
# fsck a filesystem starting at offset on a file.
# Usage: run_fsck offset file | sudo -s
function run_fsck()
{
OFFSET="$1"
FILE="$2"
cat <<XXX
dev=\`losetup -f\`
losetup -o$OFFSET \$dev "$FILE"
fsck -f -y \$dev
losetup -d \$dev
XXX
}
function do_mount()
{
OFFSET="$1"
FILE="$2"
MNT="$3"
cat <XXX
mount -oloop,offset=$"OFFSET",rw "$FILE" "$MNT"
XXX
}
offset=`get_offset "$1" $2`
run_fsck $offset "$1" | sudo -s
do_mount $offset "$1" /mnt | sudo -s
--
Dr Peter Chubb http://www.gelato.unsw.edu.au peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au ERTOS within National ICT Australia
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html