1 |
Remy Blank wrote: |
2 |
> Yahya Mohammad wrote: |
3 |
>> # losetup /dev/loop0 /path/to/diskimage |
4 |
>> # fdisk -l /dev/loop0 |
5 |
>> (example) |
6 |
>> Disk /dev/sdb: 160.0 GB, 160041885696 bytes |
7 |
>> 255 heads, 63 sectors/track, 19457 cylinders |
8 |
>> Units = cylinders of 16065 * 512 = 8225280 bytes |
9 |
>> |
10 |
>> Device Boot Start End Blocks Id System |
11 |
>> /dev/sdb1 * 1 1044 8385898+ c W95 FAT32 (LBA) |
12 |
>> /dev/sdb2 1045 19457 147902422+ 83 Linux |
13 |
> |
14 |
> Thanks for the tip! I didn't know you could mount a whole disk image as |
15 |
> loopback, and see the partition table with fdisk. I always printed the |
16 |
> partition table before making the disk image. |
17 |
> |
18 |
>> I second that, I'm curious to know if it works |
19 |
> |
20 |
> It does, I have done it before, but there's a special case for the first |
21 |
> partition of the disk. According to your output of fdisk, it is supposed |
22 |
> to start at cylinder 1. However, if you run fdisk with the -u option |
23 |
> (giving the positions and sizes in sectors), you get the following: |
24 |
> |
25 |
> (example) |
26 |
> # fdisk -lu /dev/loop0 |
27 |
> |
28 |
> Disk /dev/loop0: 10.0 GB, 10056130560 bytes |
29 |
> 240 heads, 63 sectors/track, 1299 cylinders, total 19640880 sectors |
30 |
> Units = sectors of 1 * 512 = 512 bytes |
31 |
> Disk identifier: 0xc1afc1af |
32 |
> |
33 |
> Device Boot Start End Blocks Id System |
34 |
> /dev/loop0p1 * 63 4097519 2048728+ b W95 FAT32 |
35 |
> /dev/loop0p2 4097520 8195039 2048760 5 Extended |
36 |
> /dev/loop0p5 4097583 8195039 2048728+ b W95 FAT32 |
37 |
> |
38 |
> That is, the first partition starts at sector 63, i.e. at an offset |
39 |
> value of 63 * 512 = 32256. |
40 |
> |
41 |
>> oh, and make a backup just in case :) |
42 |
> |
43 |
> And mount the filesystem read-only with the "ro" mount option. |
44 |
> |
45 |
> -- Remy |
46 |
> |
47 |
|
48 |
Some time ago, I wrote a little script to automate that process, maybe |
49 |
it will help you also. (And yes, I know that the code isn't that pretty) |
50 |
|
51 |
Direct copy & paste: |
52 |
|
53 |
#!/bin/bash |
54 |
INFILE="$1" |
55 |
PARTITION="$2" |
56 |
MOUNTPOINT="$3" |
57 |
OPT="$4" |
58 |
|
59 |
if [ "$INFILE" = "" ] ; then echo "Usage: $0 infile partition mountpoint |
60 |
<options>" ; exit ; fi |
61 |
if [ "$PARTITION" = "" ] ; then echo "Usage: $0 infile partition |
62 |
mountpoint <options>" ; exit ; fi |
63 |
if [ "$MOUNTPOINT" = "" ] ; then echo "Usage: $0 infile partition |
64 |
mountpoint <options>" ; exit ; fi |
65 |
|
66 |
if [ "$OPT" != "" ] ; then OPT2=",${OPT}" ; fi |
67 |
|
68 |
PSTARTB=`sfdisk -d "$INFILE" | grep "start=" | head -n"$PARTITION" | |
69 |
tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` |
70 |
PSTART=$[ $PSTARTB * 512 ] |
71 |
#PSIZEB=`sfdisk -d "$INFILE" | grep "size=" | head -n4 | tail -n1 | sed |
72 |
's/.*size=[ ]*//' | sed 's/,.*//'` |
73 |
#PSIZE=`echo "$PSIZEB * 512" | bc` |
74 |
mount "$INFILE" "$MOUNTPOINT" -o loop,offset="$PSTART""$OPT2" |
75 |
#,sizelimit="$PSIZE""$OPT2" |
76 |
|
77 |
- Tom |
78 |
-- |
79 |
gentoo-user@l.g.o mailing list |