public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Tom <alanceil@gmx.net>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user]  Re: "loopback mount" hard-drive image created with   dd?
Date: Thu, 24 Jan 2008 04:45:58 +0100	[thread overview]
Message-ID: <479809F6.8010105@gmx.net> (raw)
In-Reply-To: <fn1mk7$b82$1@ger.gmane.org>

Remy Blank wrote:
> Yahya Mohammad wrote:
>> # losetup /dev/loop0 /path/to/diskimage
>> # fdisk -l /dev/loop0
>> (example)
>> Disk /dev/sdb: 160.0 GB, 160041885696 bytes
>> 255 heads, 63 sectors/track, 19457 cylinders
>> Units = cylinders of 16065 * 512 = 8225280 bytes
>>
>>    Device Boot      Start         End      Blocks   Id  System
>> /dev/sdb1   *           1        1044     8385898+   c  W95 FAT32 (LBA)
>> /dev/sdb2            1045       19457   147902422+  83  Linux
> 
> Thanks for the tip! I didn't know you could mount a whole disk image as 
> loopback, and see the partition table with fdisk. I always printed the 
> partition table before making the disk image.
> 
>> I second that, I'm curious to know if it works
> 
> It does, I have done it before, but there's a special case for the first 
> partition of the disk. According to your output of fdisk, it is supposed 
> to start at cylinder 1. However, if you run fdisk with the -u option 
> (giving the positions and sizes in sectors), you get the following:
> 
> (example)
> # fdisk -lu /dev/loop0
> 
> Disk /dev/loop0: 10.0 GB, 10056130560 bytes
> 240 heads, 63 sectors/track, 1299 cylinders, total 19640880 sectors
> Units = sectors of 1 * 512 = 512 bytes
> Disk identifier: 0xc1afc1af
> 
>       Device Boot      Start         End      Blocks   Id  System
> /dev/loop0p1   *          63     4097519     2048728+   b  W95 FAT32
> /dev/loop0p2         4097520     8195039     2048760    5  Extended
> /dev/loop0p5         4097583     8195039     2048728+   b  W95 FAT32
> 
> That is, the first partition starts at sector 63, i.e. at an offset 
> value of 63 * 512 = 32256.
> 
>> oh, and make a backup just in case :)
> 
> And mount the filesystem read-only with the "ro" mount option.
> 
> -- Remy
> 

Some time ago, I wrote a little script to automate that process, maybe 
it will help you also. (And yes, I know that the code isn't that pretty)

Direct copy & paste:

#!/bin/bash
INFILE="$1"
PARTITION="$2"
MOUNTPOINT="$3"
OPT="$4"

if [ "$INFILE" = "" ] ; then echo "Usage: $0 infile partition mountpoint 
<options>" ; exit ; fi
if [ "$PARTITION" = "" ] ; then echo "Usage: $0 infile partition 
mountpoint <options>" ; exit ; fi
if [ "$MOUNTPOINT" = "" ] ; then echo "Usage: $0 infile partition 
mountpoint <options>" ; exit ; fi

if [ "$OPT" != "" ] ; then OPT2=",${OPT}" ; fi

PSTARTB=`sfdisk -d "$INFILE" | grep "start=" | head -n"$PARTITION" | 
tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'`
PSTART=$[ $PSTARTB * 512 ]
#PSIZEB=`sfdisk -d "$INFILE" | grep "size=" | head -n4 | tail -n1 | sed 
's/.*size=[ ]*//' | sed 's/,.*//'`
#PSIZE=`echo "$PSIZEB * 512" | bc`
mount "$INFILE" "$MOUNTPOINT" -o loop,offset="$PSTART""$OPT2"
#,sizelimit="$PSIZE""$OPT2"

- Tom
-- 
gentoo-user@lists.gentoo.org mailing list



      reply	other threads:[~2008-01-24  3:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-18  3:19 [gentoo-user] "loopback mount" hard-drive image created with dd? Stroller
2008-01-18  9:04 ` आशीष शुक्ल Ashish Shukla
2008-01-18 13:02   ` Stroller
2008-01-18 14:40     ` Ashish Shukla आशीष शुक्ल
2008-01-18 18:47       ` Yahya Mohammad
2008-01-21  8:54         ` [gentoo-user] " Remy Blank
2008-01-24  3:45           ` Tom [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=479809F6.8010105@gmx.net \
    --to=alanceil@gmx.net \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox