Convert a devfs single drive system to RAID

From ArchWiki

Jump to: navigation, search
Image:Tango-dialog-warning.png This article is out of date.
It may contain old, confusing and wrong information. Please help improve the wiki by updating the article and correcting mistakes.
Image:Tango-two-arrows.png This article is a candidate for merging.
It has been suggested that this page or section be merged with Convert a single drive system to RAID. (Discuss)
devfs is gone; this needs to be adapted to the current /dev/sd? devices


This covers installing a second drive after a system is already up and running a single drive. Make sure you backup all your data. You have been pre warned.

  • Primary Disc, lets get its info and record it. cfdisk is used in the example.
  • NOTE: Do not change anything, just TAB to QUIT.
  • cfdisk /dev/discs/disc0/disc
disc1       Boot, NC    Primary   Linux ext2                          41.13 
disc2                   Primary   Linux swap / Solaris               271.44
disc3                   Primary   Linux ext3                       82030.72

Secondary Disc, setup using cfdisk.

  • cfdisk /dev/discs/disc1/disc
disc1       Boot        Primary   Linux raid autodetect               41.13 
disc2                   Primary   Linux raid autodetect              271.44
disc3                   Primary   Linux raid autodetect            82030.72

Create md devices

[root@svn ~]# mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/discs/disc1/part1 
mdadm: array /dev/md0 started.
[root@svn ~]# mdadm --create /dev/md1 --level 1 --raid-devices=2 missing /dev/discs/disc1/part2 
mdadm: array /dev/md1 started.
[root@svn ~]# mdadm --create /dev/md2 --level 1 --raid-devices=2 missing /dev/discs/disc1/part3
mdadm: /dev/discs/disc1/part3 appears to contain an ext2fs file system
    size=80108120K  mtime=Thu Aug 25 14:10:41 2005
Continue creating array? y
mdadm: array /dev/md2 started.
[root@svn ~]#

Check /proc/mdstat. All devices are intact, but they are degraded.

[root@svn ~]# cat /proc/mdstat 
Personalities : [linear] [raid0] [raid1] [raid5] [multipath] [raid6] [raid10] 
md2 : active raid1 sdb3[1]
      80108032 blocks [2/1] [_U]
      
md1 : active raid1 sdb2[1]
      264960 blocks [2/1] [_U]
      
md0 : active raid1 sdb1[1]
      40064 blocks [2/1] [_U]
      
unused devices: <none>
[root@svn ~]#

Create filesystems.

  • NOTE: our /boot is ext2, / is ext3.
[root@svn ~]# mke2fs -j /dev/md0
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
10040 inodes, 40064 blocks
2003 blocks (5.00%) reserved for the super user
First data block=1
5 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
        8193, 24577

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Create swap partition:

[root@svn ~]# mkswap /dev/md1   
Setting up swapspace version 1, size = 271314 kB
no label, UUID=9d746813-2d6b-4706-a56a-ecfd108f3fe9

Create ext3 filesystem on /

[root@svn ~]# mkfs.ext3 -j /dev/md2
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
10027008 inodes, 20027008 blocks
1001350 blocks (5.00%) reserved for the super user
First data block=0
612 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
       4096000, 7962624, 11239424
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@svn ~]#

Mount and Copy Data.

[root@svn ~]# mount /dev/md2 /mnt/
[root@svn ~]# mkdir /mnt/boot
[root@svn ~]# mount /dev/md0 /mnt/boot/
!!! Note by Wild: [root@svn ~]# cd /mnt
[root@svn mnt]# tar -C / -clspf - . | tar -xlspvf - 
!!! Note by Wild: [root@svn ~]# cd /mnt/boot
!!! Note by Wild: [root@svn boot]# tar -C /boot -clspf - . | tar -xlspvf - 

This is a crucial step!

Edit /boot/grub/menu.lst and make it look like this (add "fallback 1" to menu.lst):

----- snip -----
default   0
color light-blue/black light-cyan/blue

## fallback disc1
fallback 1

# (0) Arch Linux
title  Arch Linux  [Disc0: /boot/vmlinuz26]
root   (hd0,0)
#kernel /vmlinuz26 root=/dev/discs/disc0/part3 ro
kernel /vmlinuz26 root=/dev/md2 ro

# (1) Arch Linux
title  Arch Linux  [Disc1: /boot/vmlinuz26]
root   (hd1,0)
#kernel /vmlinuz26 root=/dev/discs/disc1/part3 ro
kernel /vmlinuz26 root=/dev/md2 ro
----- snip -----

Now we will boot off disc1 and repair our degraded RAID devices. Edit /mnt/etc/fstab to add new md devices. You can just comment your old ones out.

#/dev/discs/disc0/part3 / ext3 defaults 0 1
/dev/md2 / ext3 defaults 0 1
#/dev/discs/disc0/part1 /boot ext2 defaults 0 1
/dev/md0 /boot ext2 defaults 0 1
#/dev/discs/disc0/part2 swap swap defaults 0 0
/dev/md1 swap swap defaults 0 0 

Reboot

/sbin/reboot

Cross fingers ;) Once the machine comes back up you will need to setup grub and make sure the RAID is being built.

Disc1 setup

[root@svn /]#grub
grub> root (hd1,0)
 Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd1)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd1)"...  16 sectors are
embedded.
succeeded
 Running "install /boot/grub/stage1 (hd1) (hd1)1+16 p
(hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done
grub>quit
[root@svn /]#

Reboot 1 more time.

Coming up on 2nd drive.

/sbin/reboot

Add md devices to RAID.

[root@svn ~]# mdadm /dev/md0 -a /dev/discs/disc0/part1
mdadm: hot added /dev/discs/disc0/part1
[root@svn ~]# mdadm /dev/md1 -a /dev/discs/disc0/part2
mdadm: hot added /dev/discs/disc0/part2
[root@svn ~]# mdadm /dev/md2 -a /dev/discs/disc0/part3
mdadm: hot added /dev/discs/disc0/part3
[root@svn ~]

Check mdstat. Verify that your RAID is being built.

[root@svn ~]# cat /proc/mdstat 
Personalities : [linear] [raid0] [raid1] [raid5] [multipath] [raid6] [raid10] 
md1 : active raid1 sda2[0] sdb2[1]
      264960 blocks [2/2] [UU]
      
md2 : active raid1 sda3[2] sdb3[1]
      80108032 blocks [2/1] [_U]
      [>....................]  recovery =  1.2% (1002176/80108032) finish=42.0min speed=31318K/sec
md0 : active raid1 sda1[0] sdb1[1]
      40064 blocks [2/2] [UU]
      
unused devices: <none>
[root@svn ~]#

You're done.

Personal tools