Warning — These pages discuss older technologies. Though the high-level concepts are still valid, some of the low-level specifics (Linux 2.4, LILO, IDE disks, etc.) are obsolete. You probably don't want to go through these steps verbatim on a modern system.

Migrating a Linux boot partition to RAID-1

Alexander Hajnal
7 FAQ
Q1 I had successfully added a device to the array but it shows as failed after a reboot.
A1   There are a number of things that could have caused this:
  • The disk might really have failed. See if you can access the disk using cfdisk.
  • The partition that you added might not be the same as the device listed in /etc/raidtab One common mistake is to omit the partition number when adding the device. For example, if this is your /etc/raidtab:
    raiddev                /dev/md0
    raid-level             1
    nr-raid-disks          2
    nr-spare-disks         0
    persistent-superblock  1
    device                 /dev/hda1
    raid-disk              0
    device                 /dev/hdc1
    raid-disk              1
    you may have run /sbin/raidhotadd /dev/md0 /dev/hdc instead of /sbin/raidhotadd /dev/md0 /dev/hdc1
    See if you can add the correct partition by running the latter command. If it fails then you will need to re-partition the physical disk (/dev/hdc) and then re-run raidhotadd with the correct parameters. The correct partition information can be determined by running cfdisk /dev/hda A reboot may be neccessary before running these commands.
Q2 My exisiting drive has more than one partition. How can I convert it to RAID?
A2   The simplest way to do this is to create an array on the new drive that has the same capacity as the old drive in its entirety. Set up the array and make it bootable, the re-partition then old drive to match new one and add it to the array.

You can determine the correct size for the RAID partition by doing the following:

  • Run cfdisk /dev/hda where /dev/hda is your new disk.
  • Type uEnter to change the unit to sectors.
  • Type pEnter to display the partition table
  • Make a note of the size of a sector in bytes.
  • Type qEnter to exit the program
  • Run cfdisk /dev/hdc where /dev/hdc is your old disk.
  • Type uEnter to change the unit to sectors.
  • Type pEnter to display the partition table
  • Make a note of the total number of sectors on the disk as well as the size of a sector in bytes.
  • Type qEnter to exit the program
  • Determine the size (in sectors) to use for the RAID partitions on the old and new drives.
    • If the sector size is the same on the old and new drives then the partition size on both disks is the same:
      partition_sizenew   =   disk_sizeold - 1
      partition_sizeold   =   disk_sizeold - 1
      For example, if disk_sizeold=10000, sector_sizeold=512 and sector_sizenew=512 then:
      partition_sizenew   =   10000 - 1   =   9999
      partition_sizeold   =   10000 - 1   =   9999
    • If the sector size of the old drive is larger than the the sector size on the new drive then the partition size on the new disk will be larger than the total number of sectors on the old disk:
      partition_sizenew   =   ( disk_sizeold - 1 ) ( sector_sizeold )

      sector_sizenew
      partition_sizeold   =   disk_sizeold - 1
      For example, if disk_sizeold=10000, sector_sizeold=1024 and sector_sizenew=512 then:
      partition_sizenew   =   ( 10000 - 1 ) ( 1024 )   =   ( 9999 ) ( 2 )   =   19998

      512
      partition_sizeold   =   10000 - 1   =   9999
      Please note that since I do not have drives with differing sector sizes, I was unable to test this configuration. Proceed at your own risk (and let me know if it works correctly).
    • If the sector size of the old drive is smaller than the the sector size of the new drive then the partition size on the new drive will be smaller than the partition size of the old disk:
      partition_sizenew   =   floor ( ( disk_sizeold - 1 ) ( sector_sizeold ) ) - 1

      sector_sizenew
      partition_sizeold   =   ( ( partition_sizenew + 1 ) ( sector_sizenew ) ) - 1

      sector_sizeold
      For example, if disk_sizeold=10000, sector_sizeold=512 and sector_sizenew=1024 then:
      partition_sizenew   =   floor ( ( 10000 - 1 ) ( 512 ) ) - 1   =   floor( 9999 × 0.5 ) - 1   =   floor( 4999.5 ) - 1   =   4999 - 1   =   4998

      1024
      partition_sizeold   =   ( ( 4998 + 1 ) ( 1024 ) ) - 1   =   ( 4999 × 2 ) - 1   =   9998 - 1   =   9997

      512
      Please note that since I do not have drives with differing sector sizes, I was unable to test this configuration. Proceed at your own risk (and let me know if it works correctly).
  • Follow the main instructions for setting up the array with the following deviations:
    • When you use fdisk to set up the RAID partition on the new drive, enter 1 for the start sector of the partition and partition_sizenew as the end sector.
    • After you have set up the array and you can boot off it, but before you run raidhotadd to add the old drive to the array, you will need to re-partition the old drive:
      • Clear the partition table on the old drive by running dd if=/dev/zero of=/dev/hdc bs=512 count=1 where /dev/hdc is the old drive.
        You may wish to make a backup of the partition table before deleting it. You can do this by running dd if=/dev/hdc of=/root/hdc_partition_table bs=512 count=1 where /dev/hdc is the old drive.
      • Run fdisk /dev/hdc where /dev/hdc is the old drive.
      • Type pEnter to view the partition table. You should see no partitions listed.
      • Type uEnter to change the units to sectors.
      • Type cEnter to leave DOS compatibility mode.
      • Type nEnter to create a new partition.
      • Type pEnter to select a primary partition.
      • Type 1Enter to select the first partition.
      • Type 1Enter to set the first sector of the partition.
      • Enter partition_sizenew and then hit Enter to set the last sector of the partition.
      • Type wEnter to write the partition table to disk and exit the program.
    • Add partition to array using raidhotadd as per the main instructions.