Avatar of bmsjeff
bmsjeff
Flag for Afghanistan asked on

Ubuntu - create raid from existing install and adding a new drive.

I know nothing of Linux, but do know windows.
I have an exising Ubuntu installation on a desktop and want to test creating RAID1.
I install a second HDD in the box.  How do I go about installing RAID from scratch?

I would like to Format drive 2, Create a RAID1 partition, and Mirror the data from drive1.
Details please.
Linux

Avatar of undefined
Last Comment
bmsjeff

8/22/2022 - Mon
bmsjeff

ASKER
I have looked at:
http://ascend4.org/Installing_Raid_1_on_Existing_Ubuntu_Server
but don't want to format the first drive.  Is that possible?
farzanj

No formatting.

First step is planning.  What kind of Raid do you want?  What do you really want?  Redundancy (mirroring) or Huge volumes (Stripping) or a mixture of both.

Here is something for you to read on
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch26_:_Linux_Software_RAID

You will make RAID volumes.  Based on that you will be making partitions, and on those partitions you would do the formatting (put appropriate file systems).

https://help.ubuntu.com/community/Installation/SoftwareRAID
farzanj

When you would start building raid, the data will be erased.  So if you have an existing data, please make sure to back it up.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
bmsjeff

ASKER
I put RAID1.
So the drives have to be created before data is placed on them.

What should I do to backup the existing drive so that I can place it back on the newly created RAID1 partition.
wesly_chen

For safety, you might want to buy another hrad disk do disk clone with your original drive first.
The boot up from the clone drive to verify cloning ok.
Then add another disk to do the software raid.
If everything run smoothly, then you can re-use the original drive.
You don't need to worry about if something went wrong and you still can put back the original disk.

For disk clone, you can use Ghost or clonezilla
http://clonezilla.org/
farzanj

You have to make sure that the permissions and ownerships of all files and folders stay intact.  You can either create tar archives or you may simply do rsync.

Where would you store?  Do you have any storage device like NAS or any thing that would carry your data?

With tar you could use options like

tar Ppcvfz archive.tgz /path
You can create tar in some attached storage.

If you can transfer files by rsync, you need simply

rsync -avuz /path dest
Destination may be mounted or remote over ssh.

Other option could be to simply use a new drive, create the RAID on it and then transfer image from old to new.

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bmsjeff

ASKER
so can I place raid on an existing disk or must I start with a formatted disk?
farzanj

You can but it would wipe off everything currently on it.  You have to transfer data somewhere before proceeding.
bmsjeff

ASKER
ok, trying to wrap my head around this:

$ grep /dev/md /etc/fstab
# /dev/md0

$ df -h / /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              19G  2.7G   15G  16% /
/dev/md0              128G   43G   79G  36% /home

$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sda3[0]
      134801344 blocks [2/1] [U_]
     
unused devices: <none>

$ sudo mdadm --query --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Tue Jul  8 19:18:47 2008
     Raid Level : raid1
     Array Size : 134801344 (128.56 GiB 138.04 GB)
  Used Dev Size : 134801344 (128.56 GiB 138.04 GB)
   Raid Devices : 2
  Total Devices : 1
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Wed May 18 21:34:32 2011
          State : active, degraded
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           UUID : 0553725a:cf84abcf:68ceeaf4:7264baec
         Events : 0.48058

    Number   Major   Minor   RaidDevice State
       0       8        3        0      active sync   /dev/sda3
       1       0        0        1      removed


So, I think, I have a single drive with one RAID1 partition (md0)  
The second drive is obviously missing.
I am going to install a new, unformatted drive into the box.

This should give me something like:
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sda3[0]
      134801344 blocks [2/2] [U_]

I would then run
sudo mdadm --add /dev/md0 /dev/sdb3

or would I use this command?
sudo mdadm --manage --add /dev/md0 /dev/sdb3

What is the difference?
Let me know if I am missing anything.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bmsjeff

ASKER
I place a new drive into the box and run:
sudo mdadm --add /dev/md0 /dev/sdb3

and I get:
mdadm: cannot find /dev/sdb3: No such file or directory

do I need to format/partition before doing this?  What is the process?
wesly_chen

> do I need to format/partition before doing this?
You need to use fdisk to partition /dev/sdb to be the same as /dev/sda first.

Please post the output of
sudo fdisk -l
bmsjeff

ASKER
$ sudo fdisk -l
[sudo] password for khudson:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0004a40a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2432    19535008+  83  Linux
/dev/sda2            2433        2675     1951897+  82  Linux swap / Solaris
/dev/sda3            2676       19457   134801415   fd  Linux raid autodetect

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/md0: 138.0 GB, 138036576256 bytes
2 heads, 4 sectors/track, 33700336 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table


⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
wesly_chen

sudo fdisk /dev/sdb
n
p
1
<Enter>         # for start sector
2432 <Enter> # for end sector
n
p
2
<Enter>
2675 <Enter>
n
p
3
<Enter>
19457 <Enter>
t
3
fd
w
bmsjeff

ASKER
Just so I can conceptualize before I perform
sudo fdisk /dev/sdb
n = ???
p = primary
1 = first partition
<Enter>         # for start sector
2432 <Enter> # for end sector
n = ???
p = primary
2 = second partition
<Enter> # for start sector (implies next available sector)
2675 <Enter> # for end sector
n = ???
p = primary
3 = third partition
<Enter> # for start sector (implies next available sector)
19457 <Enter> # for end sector
t = ???
3 = ???
fd = ???
w = write command

wesly_chen

in fdisk , press m for menu
n : add new partition
t: toggle the partition type
fd: is the type show on /dev/sda3 (md)
  You might want to change /dev/sdb2 to type 82 (swap)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
bmsjeff

ASKER
So it would be:???

sudo fdisk /dev/sdb
n
p
1
<Enter>         # for start sector
2432 <Enter> # for end sector
n
82
2
<Enter>
2675 <Enter>
n
p
3
<Enter>
19457 <Enter>
t
3
fd
w
ASKER CERTIFIED SOLUTION
wesly_chen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bmsjeff

ASKER
Thanks Wesly.  Your help is very much appreciated.