Migrating a Linux boot partition to RAID-1
Alexander Hajnal
5 Copying files and making the array bootable
-
Reboot the system. As the computer starts up, hold down the
Control key until you get the
lilo
boot
prompt. At the prompt, type
linux single boot=/dev/hdc root=/dev/hdc1
where
/dev/hdc
reflects the location of the
old drive. When prompted, enter
root
's password.
-
Mount the raid array by running
mount /dev/md0 /raid
-
Copy the files from the old partition to the
array by running
cp -ax / /raid
-
Update the array's copy of
lilo.conf
to reflect the array's
presence by running
cp -a /raid/etc/lilo.conf.raid /raid/etc/lilo.conf
-
Create a swapfile on the array. For a 256M swap file run
dd if=/dev/zero of=/raid/swapfile bs=1024 count=262144
and then mskwap /raid/swapfile
-
Alter the array's
fstab
file (/raid/etc/fstab
to
specify the array as the root filesystem and the swap file. For example,
if /etc/fstab
on the old disk looked
like this:
/dev/hda1 / ext3 errors=remount-ro 0 0
proc /proc proc defaults 0 0
/dev/fd0 /floppy auto user,noauto 0 0
/dev/cdrom /cdrom iso9660 ro,user,noauto 0 0
/dev/hda2 none swap sw 0 0
then you should change /raid/etc/fstab
to the following:
/dev/md0 / ext3 errors=remount-ro 0 0
proc /proc proc defaults 0 0
/dev/fd0 /floppy auto user,noauto 0 0
/dev/cdrom /cdrom iso9660 ro,user,noauto 0 0
/swapfile none swap sw 0 0
Note that the swap partition has been changed to the swap file created in
the previous step.
-
Mount the array's
/boot
directory onto the root partition by
running mount --bind /raid/boot /boot
This step is very important. If the directory is not
mounted then lilo
will not write a correct bootloader and the
array will not be bootable. The bind
option was first
introduced in the 2.4.0 kernel.
-
Mark the the first partition of the new disk as
bootable:
- Run
cfdisk /dev/hda
- Select [Bootable] and press Enter
- Select [Write] and press Enter
- Type
yes
Enter
- Select [Quit] and press Enter
-
Install a bootloader onto the array by running
/sbin/lilo -v2 -C /raid/etc/lilo.conf.raid
-
Reboot the computer. It should now boot off of the array.
-
Once your system has booted, log in as
root
and check that
you are running off of the array by running mount
. You should
see that the root partition (/
) is physically located on
/dev/md0
-
Add the old drive to the array:
-
Edit
/etc/raidtab
and change failed-disk
to
raid-disk
-
Activate partition in the array by running
/sbin/raidhotadd /dev/md0 /dev/hdc1
-
The array should begin to rebuild itself automatically. The array is
immediately usable; you do not have to wait for the rebuild to finish. You
can track the rebuild process by running
cat /proc/mdstat
-
When the array has finished rebuild a message will be printed to the
console and to syslog. You should see something similar to the following
(the sizes and offsets will vary):
md: md0: sync done.
RAID1 conf printout:
--- wd:1 rd:2 nd:3
(many lines not shown)
RAID1 conf printout:
--- wd:2 rd:2 nd:3
(many lines not shown)
md: updating md0 RAID superblock on device
md: hdc1 [events: 00000013]<6>(write) hdc1's sb offset: 4210816
md: hda1 [events: 00000013]<6>(write) hda1's sb offset: 4210816
md: recovery thread finished ...
-
Verify that the array has been built correctly by running
cat /proc/mdstat
. You should see the following (sizes will
vary):
Personalities : [raid1]
read_ahead 1024 sectors
md0 : active raid1 hdc1[1] hda1[0]
4210816 blocks [2/2] [UU]
unused devices: <none>
Make sure that the drives listed are hdc1
and hda1
if you see the drives listed as hdc1
and hda
,
see the FAQ.
-
Now that the array has finished rebuilding, the install process is
complete. Enjoy your new array!