Re: creating raid with existing data?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday February 19, micah@riseup.net wrote:
> I've got /dev/sda with data on it, I want to add /dev/sdb on as a
> mirror (raid-1), can I do this without destroying data on /dev/sda
> when creating the raid? I've setup /dev/sdb to have all the same
> partitions and sizes as /dev/sda has, and I've setup a raidtab file so
> that all the devices match up, but I am a little paranoid about
> creating the raid because I dont want to destroy data on /dev/sda.

No and yes.

If you have data in /dev/sda1, and you create /dev/md0 as a RAID-1
array of /dev/sda1 and /dev/sda2, then /dev/md0 with by 64K smaller
than /dev/sda1 (due to the RAID superblock) and you will loose any
data that it there.

What you could do is create degraded raid arrays on /dev/sdb:
 e.g.
    mdctl --create /dev/md0 --level=1 -n 2 /dev/sdb1 missing

and then copy the data access at the filesystem level

    mkfs /dev/md0
    mount /dev/md0 /somewhere
    cp -a /whereever /somewhere

and the unmount /dev/sda1 and add it to the array

    umount /dev/sda1
    mdctl --add /dev/md0 /dev/sda1

This will work, but requires copying the data.

An alternative is to use my md partitioning patch, from
   http://www.cse.unsw.edu.au/~neilb/patches/linux-stable/2.4.17/

The patches you will need are RaidSplit, MdPart and possible MdpMajor.

Depending on what partitioning tool you used, it is quite possible
that the last few hundred K of sda is not part of any partition.
You can check this by using "fdisk /dev/sda", and giving commands "x"
and "p".
Then look at the start and size of the last partition, add them
together and divide by 2 (to convert sectors to K).
Then compare this with the size of /dev/sda as reported by
/proc/partitions.
If the different is more than 64, then you have room for a RAID
superblock that wont overwrite any data.
So:
   mdctl -C /dev/md0 -l 1 -n 2 /dev/sda missing

Then stop using the sd partitions and start using the md partitions.
/proc/partitions will tell you the major and minor numbers of
the md partitions.

You can then hot-add /dev/sdb with
   mdctl -a /dev/md0 /dev/sdb

and you will have all your data on all your partitions on a raid-1
array.

NOTE: The actual calculation to see if there is enough space for a
raid superblock is:
   E <=    ((S-1) % 64) - 64

when E is the end of the last partition, and S is the size of the
drive.
i.e. reduce to a multiple of 64 and subtract 64.

NeilBrown
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux