Setting up RAID1 to new HDD on running Linux Web Server

Posted on 2004-08-07
Last Modified: 2013-12-15
I need to set up RAID1 mirror on a currently running web server with 100 domains, 500 mail accounts.  Here is what we have:

Linux 7.3 with standard kernal 2.4
RAIDTOOLS installed
pretty much standard install, few things added from standard, nothing big

1 80Gb IDE HDD (hda) partitioned as follows:

1 Linux  1 6 /boot
2 Linux swap  7 134 swap
3 Extended  135 10011  
  5 Linux  135 389 /  
  6 Linux  390 772 /usr  
  7 Linux  773 1410 /var  
  8 Linux  1411 10011 /home

1 new 80Gb IDE HDD (hdc) identical to hda, not yet partitioned

I am accessing the server (leased, dedicated) remotely with SSH, as root.

No tape backup

cat /proc/mdstat
Personalities : [raid0] [raid1] [raid5]
read_ahead not set
unused devices: <none>


Here is what we want to do:

We need to keep everything mirrored so that if one or the other hard disks fails, we will neither lose data nor have to take more than a short time to recover with a new hard disk.

What I want is a step by step guide for partitioning the new hard disk and setting up the necessary filesystems (ext2, ext 3, LINUX raid????) or devices, then creating the raidtab file and any other files that need to be created or edited or updated (fstab?), then starting the thing and making sure it is running.

I hope this is enough to get us going...  THANKS!

Question by:rbartz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 40

Accepted Solution

jlevie earned 500 total points
ID: 11745294
Below you'll find the procedure that I use to do this:

 1) Get a list of the partitions on the boot drive with 'fdisk -l
    /dev/hda'. Then create partitions with fdisk on the second drive
    of the same size and mark those partitions as being "Linux raid"
    (type fd in fdisk).

 2) Create /etc/raidtab listing entries for both drives and all
    partitions. Mark the current boot drive as failed.

 3) Execute mkraid on each md device you've defined in /etc/raidtab.

 4) Make a file system on each md device except the one used for swap. Specify
    the appropriate label (/, /home) for those file systems. For the swap
    device execute mkswap.

 5) Make an initrd image and make sure that Grub is configured to use it.

 6) For each file system on the boot disk use dump/restore to transfer those
    file systems to the corresponding md device. Note that you'll have to
    specify the device, not the mount point. E.G., use:

    mkdir /mnt/disk
    mount /dev/md0 /mnt/disk
    dump 0f - /dev/hda1 | (cd /mnt/disk; restore rf -)

    mount /dev/md0 /mnt/disk
    dump 0f - /boot | (cd /mnt/disk; restore rf -)
    It is safest to do the dump/restore in single user mode.

 7) Make a boot floppy (mkbootdisk)

 8) Mount the md device that contains /boot and edit grub.conf to set "root="
    to point to the correct md device. Also edit the fstab file on the md
    device to point swap to the correct md device.

 9) Reboot and you should be running off of the md devices. If something goes
    wrong you have the boot floppy.

10) Use fdisk to change the partition types on hda to be "Linux raid".

11) For each md device, execute 'raidhotadd /dev/md? /dev/hda?'.

12) Edit /etc/raidtab and remove the 'failed flag' for hda.


grub-install seems to get confused by md devices. So to install grub in the
MBR you can use the grub shell. Execute grub and then use:

grub> root (hd0,0)
grub> setup --stage2=/boot/grub/stage2 --prefix=/grub (hd0)

Example raidtab:

# /boot
raiddev                /dev/md0
raid-level                1
nr-raid-disks                2
chunk-size                64k
persistent-superblock          1
nr-spare-disks                0
    device          /dev/hda1
    raid-disk     0
    device          /dev/hdb1
    raid-disk     1
# /
raiddev                /dev/md1
raid-level                1
nr-raid-disks                2
chunk-size                64k
persistent-superblock          1
nr-spare-disks                0
    device          /dev/hda2
    raid-disk     0
    device          /dev/hdb2
    raid-disk     1
# swap
raiddev                /dev/md2
raid-level                1
nr-raid-disks                2
chunk-size                64k
persistent-superblock          1
nr-spare-disks                0
    device          /dev/hda3
    raid-disk     0
    device          /dev/hdb3
    raid-disk     1
# /var
raiddev                /dev/md3
raid-level                1
nr-raid-disks                2
chunk-size                64k
persistent-superblock          1
nr-spare-disks                0
    device          /dev/hda5
    raid-disk     0
    device          /dev/hdb5
    raid-disk     1
# /home
raiddev                /dev/md4
raid-level                1
nr-raid-disks                2
chunk-size                64k
persistent-superblock          1
nr-spare-disks                0
    device          /dev/hda6
    raid-disk     0
    device          /dev/hdb6
    raid-disk     1

Expert Comment

ID: 11750170
I was doing the exactly same thing some time ago. I didn't have the courage to do this on the production machine so I tested the whole procedure on a test computer before. I had many problems when making RAID but I finally succeded. It was a while ago and I don't remember all the problems.

The biggest problem I think was that partitions on the original disk needed to be shortened because RAID needed to write some additional information at the end of partitions. I used software RAID and I have found instructions on the internet. I think it was one of HOWTOs for Linux.

I am not giving you a solution because I see jlevie has done that. I just want to warn you that you may get in trouble. And the last advice. Don't do it remotely.
LVL 40

Expert Comment

ID: 11750216
I've not had the problems that marko has experienced. And those instructions were essentially notes I made while doing a conversion to RAID 1 very, very, remotely. I did have someone on-site that could reboot the system via the boot floppy, and I made sure that would work before starting the conversion. Since then I've done this  a number of times without anything odd occuring.
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.


Author Comment

ID: 11758343
Thank you jlevie, and you too marko, I am warned...  :-)

Our server is leased, and I cannot get physical access to it.  Remote is my only choice.  I will need to arrange a time to do this so that a support tech can help with creating the floppy and rebooting (there may already be a bootable floppy on the machine).

I think RAID1 will be much better than using the second drive to do full and incremental backups.  That is easy enough to do, but will not help us get back on line quickly if a hard drive fails.  We need the best way that we can afford, and RAID1 is it for now.  The risk is worth the difference.

jlevie, I have questions about the following steps!  Appreciate your help.

Additional info:  our original hard disk is hda.  The new one is hdc.  They are identical drives in every way.  Also, I have Webmin installed, updated, and all the modules are working for creating partitions and so on, including the RAID module.

2...  how do I mark the current boot drive as failed when I create the /etc/raidtab?

4... how do I create the filesystem and labels on the new partitions?

5... How do I make an initrd image, and how do I know if my GRUB (vers. 0.90) is configured to use it?  I do not have a grub.conf file....!  Will we need to install GRUB?  I suppose we are using lilo, the lilo.conf file is:









8... the current root=/dev/hda5, so I assume that the new line would be something like root=/dev/md3...?

9.  Reboot should work without the floppy if I am reading between the lines here correctly.  Is there anything I should be aware of if it doesn't and we have to reboot from the floppy?  If the reboot failed from the hard drives, what would be the most likely reasons?

10... the correct command for fdisk to change the partition type?

I think I understand the rest,  I am travelling again tomorrow so will see about doing all this Wednesday night after making and downloadfing backups.  Thanks for your help.

LVL 40

Expert Comment

ID: 11758782
For this task it would be best to forget that you ever had webmin installed. All of it will beed to be done from the command line using the utilities I mention in the notes. And you'd be well advised to not use webmin for maintenance of this server. I've made an obscene amount of money as a consultant in fixing systems that were mucked up beyond comprehension by webmin. Hmm, on second thought continue to use webmin and keep in mind that I do consulting, fo a fee...

Seriously, learning the in's and out's of managing a server via command line tools and direct editing of files is a skill worth having. It really isn't that hard to do, there's never any doubt as to what changes have been made, and it doesn't require that one have a functioning web server.

2... Using /boot as an example the initial raidtab entry would look like:

# /boot
raiddev              /dev/md0
raid-level              1
nr-raid-disks              2
chunk-size              64k
persistent-superblock         1
nr-spare-disks              0
    device         /dev/hda1
    raid-disk     0
    failed-disk  0
    device         /dev/hdc1
    raid-disk     1

4... You execute 'fdisk /dev/hdc' and create the partition (see 'man fdisk'). It's not as difficult as it might seem. The fdisk program is menu driven. In step 4 above you'd use 'mke2fs -j -L /boot /dev/md0', for example

5... You really should switch to Grub. Depending on what version of Lilo you have it may not be capable of booting from a RAID 1 system.

8... That all depends on how you define the RAID devices in the raidtab. The root (/) could be md0, md1 or anything else. All that matters is that the grub.conf and fstab point to the correct RAID device.

9... Yes, it should boot from the RAID device, but just in case you want to be sure that you have a bootable floppy and that it will work.

10... Within fdisk the 't' menu item is used to set the partition type.

Author Comment

ID: 12531348
I apologize for the delay in accepting your answer, jlevie, I was travelling for last 5 months!

Works perfectly.


Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question