Mailinglist Archive: opensuse (2430 mails)

< Previous Next >
Re: [opensuse] dmraid and files

----- Original Message -----
From: "Dave Howorth" <dhoworth@xxxxxxxxxxxxxxxxx>
To: <opensuse@xxxxxxxxxxxx>
Sent: Friday, April 18, 2008 5:27 AM
Subject: Re: [opensuse] dmraid and files


Matthias Bach wrote:
Hi!

Am Donnerstag, 17. April 2008 16:06 schrieb Dave Howorth:
Is it possible to use dmraid with files rather than physical devices?
I've made copies with dd of two RAID0 disks as files. Is there any way
to access the contents of the RAID or do I need to copy them onto other
physical disks first?

You could try "mdadm --assemble /dev/md/0 file1 file2 ...". Don't know
whether
it works so. Afterwards you should be able to mount /dev/md0 as usual.

I tried

mdadm --assemble /dev/md0 /tmp/mnt/sda /tmp/mnt/sdb

but it says:

mdadm: /tmp/mnt/sda is not a block device
mdadm: /tmp/mnt/sda has no superblock - assembly aborted

Oh well. Thanks for the idea, though.

What you want is called a loop device in linux. (other os's call it a
file-backed ram disk)
losetup is your friend here.

Assume your disk images are stored in file0, file1, file2
I'm working with three blank 512 meg files for the sake of the examples here.

Assign loop devices to your 3 files:
mybox:~ # losetup /dev/loop0 file0
mybox:~ # losetup /dev/loop1 file1
mybox:~ # losetup /dev/loop2 file2

Assemble the array:
mybox:~ # mdadm -A /dev/md3 /dev/loop[0-2]
mdadm: /dev/md3 has been started with 3 drives.

View the array status:
mybox:~ # cat /proc/mdstat
Personalities : [raid5] [raid4]
md3 : active raid5 loop0[0] loop2[2] loop1[1]
1048448 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>


Mount the filesystem:
mybox:~ # mkdir /md3
mybox:~ # mount /dev/md3 /md3

View the filesystem:
mybox:~ # mount
[...]
/dev/md3 on /md3 type ext2 (rw)
mybox:~ # df -h
Filesystem Size Used Avail Use% Mounted on
[...]
/dev/md3 1008M 20K 957M 1% /md3
mybox:~ #

3 x 512 megs in raid5 = 1gig

Now, that assumed the disk images were actually partition images, which I'm
guessing you didn't think to collect but instead collected images of the full
raw disks, such that each file contains the boot block, partition table and
multiple partitions all in one file.
In that case it's a bit trickier.Then you have to collect the offsets of the
different partitions and use them with the -o offset option to losetup, or
extract the partitions into new fils with dd and the same offset numbers.
Assuming all three disk images are exactly the same sizes and have exactly the
same size partitions, collect the numbers from any one disk, if the disks
and/or partitions are different from each other, then do the following for each
& every disk :

mybox:~ # fdisk -ul /dev/loop0

Disk /dev/loop0: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/loop0p1 63 112454 56196 83 Linux
/dev/loop0p2 112455 1044224 465885 83 Linux


Assuming the 2nd partition is the important one:
p2 starts at 512 bytes (per block) x 112455 (blocks) = byte numbr 57576960

There is actually no such file for the partitions like "/dev/loop0p2". We do
need to use offsets into the full file with losetup -o offset or dd
seek/skip=offset
At this point we could either create more loop devices 3,4,5 mapped to chunks
of loop0,1,2, such that /dev/loop0 is the full disk and /dev/loop3 would be
partition 2 within loop0
but we don't actually need the full disk image loop devices any more, lets
un-map them and map them to the partitions we want instead so that loop0
becomes partition 2 of file0, loop1 becomes partition 2 of file1, etc... To me
this is less confusing, but do whatever is less confusing for you.
Assuming my way, deconstruct the existing loopbacks:
mybox:~ # losetup -d /dev/loop0
mybox:~ # losetup -d /dev/loop1
mybox:~ # losetup -d /dev/loop2

And reconnect to the partitions within the same files using -o offset:
mybox:~ # losetup -o 57576960 /dev/loop0 file0
mybox:~ # losetup -o 57576960 /dev/loop1 file1
mybox:~ # losetup -o 57576960 /dev/loop2 file2


From here on it's exactly the same as the first example:

Assemble the array:
mybox:~ # mdadm -A /dev/md3 /dev/loop[0-2]
mdadm: /dev/md3 has been started with 3 drives.

Check it out:
mybox:~ # cat /proc/mdstat
Personalities : [raid5] [raid4]
md3 : active raid5 loop0[0] loop2[2] loop1[1]
935936 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>

Mount the filesystem:
mybox:~ # mount /dev/md3 /md3

Check it out:
mybox:~ # mount
[...]
/dev/md3 on /md3 type ext2 (rw)
mybox:~ # df -h
Filesystem Size Used Avail Use% Mounted on
[...]
/dev/md3 900M 20K 854M 1% /md3

Notice the size of the array is smaller than my first example now that I'm
using a 50 meg offset into each file instead of the full file.

Now just pull out your data at will:

mkdir /restore
rsync -av --sparse /md3/* /restore
or
star -copy -v -C /md3 . /restore

Don't use tar for a full filesystem like that, use cpio or afio or star or
rsync.

Just in case it's confusing how a given set of files could make a valid array
and a valid filesystem both from the full file and from a 50 meg offset within
it, It can't,
I did new fdisk, mdadm -C, and mkfs commands on the files between the first &
second examples to simulate the 2 different scenarios.

--
Brian K. White brian@xxxxxxxxx http://www.myspace.com/KEYofR
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!

--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups