ReiserFS and Raid-1

Go Back
Braindump Index
Braindump Home

Configuring Linux to use Reiser FS and software mirroring.

ReiserFS is a journalling filesystem replacement for the standard Linux ext2 fs. It eliminates the need to fsck a disk after a crash. It also eliminates loss of data resulting from a system crash or power failure.

Raid-1 is the mirroring of 2 partitions, duplicating each write opperation to 2 different physical disks. If one disk failes, there is still a complete copy of the data on another disk. I use software mirroring provided by the Linux 2.4 kernel.

Any combination of SCSI and IDE disks are supported.

  1. Install Linux as you normally would, using only 1 disk. Leave the second disk untouched.

  2. Download the latest kernel source from ftp://ftp.kernel.org/pub/linux/kernel/v2.4

  3. Compile and install the new kernel upgrade, enabling ReiserFS support and Raid-1 as part of the kernel

  4. Download, compile and install the ReiserFS tools from ftp://ftp.namesys.com/pub/reiserfsprogs/ The RaidTools package from http://people.redhat.com/~mingo/raid-patches/

  5. Partition the second disk to match the block size of the partitions that you want to enable mirroring on.

    • I don't mirror the / partition! Create it on the second disk, but do not change the type from ext2 (82). Booting and mounting a raid-1 drive is not very straight forward yet.

    • I like to use 2 virtual terminals, in the first I print the partition table from the first disk:
      # fdisk -l /dev/sda

    • I use the second virtual terminal (or shell) to partition the second disk
      # fdisk /dev/sdb

    • You don't need to create a new swap partition, because mirroring the swap is kind of silly.

    • Set the type of each partition on the second disk (which is part of the mirror) to 'fd' (Linux raid autodetect) - so it can be detected when the kernel boots.

    • The (K) block size must match for the partitions to be able to be mirrored.

  6. Create a /etc/raidtab file to outline the layout of the raid devices, add and modify a section for each raid device (mirrored partition) you will have.
    # /usr
    raiddev /dev/md1
            raid-level      1
            nr-raid-disks   2
            nr-spare-disks  0
            chunk-size      4
            persistent-superblock   1
            device          /dev/sda5
            failed-disk       0
            device          /dev/sdb5
            raid-disk       1
    	
    Notice the line that says failed-disk, because that disk still has live data on it - we don't want the raid to interfere with it!

  7. Make each raid device in your raidtab file:
    # mkraid /dev/md1

  8. Using the reiserfs tools you installed earlier, create a Reiser filesystem inside each raid device:
    # mkreiserfs /dev/md1

  9. Mount each raid device so you can duplicate the live data into the raid.
    # mount /dev/md1 /mnt/usr -t reiserfs
    # cd /mnt/usr && tar cf - -C /usr . | tar xf -

    or even better use rsync on the mounted partitions:

    # rsync -axvPS /usr/ /mnt/usr/
    and automate the whole sync:
    # for each in /usr/ /var/ /home/; do rsync -axvPS --delete $each /mnt$each; done

  10. Modify the /etc/fstab and change the mount device for each partition to the new raid device, and set the partition type to reiserfs from ext2.
    /dev/md1               /usr                    reiserfs    defaults        0 0

  11. Reboot the machine so that each partition is now running from the raid device.

  12. Check mount and cat /proc/mdstat to make sure the raid is running, and the drives are mounted as /dev/md?

  13. Now add the second partition to the mirror. Edit the /etc/raidtab file and replace each failed-disk with raid-disk. Now add each original partition into its raid device:
    # raidhotadd /dev/md1 /dev/sda5

  14. Check the progress in your /proc/mdstat
    # while true; do cat /proc/mdstat; sleep 5; done

  15. When the replication process completes, change the partition types of the first disk using fdisk. Only change the types, do not change the size or anything else about the partition! For each partition which is now a raid device, change the type to 'fd'.

  16. Reboot the machine - check mount and cat /proc/mdstat again, to make sure all raid drives are opperational [UU].
    md1 : active raid1 sdb5[0] sda5[1]
          1028032 blocks [2/2] [UU]
     
    md2 : active raid1 sdb6[0] sda6[1]
          1028032 blocks [2/2] [UU]
     
    md3 : active raid1 sdb7[0] sda7[1]
          5751168 blocks [2/2] [UU]
     
    md4 : active raid1 sdb9[0] sda9[1]
          513984 blocks [2/2] [UU]
    	

    Wait! But what about the / partition - we didn't make that a mirror!

  17. I call rsync from cron every hour to duplicate the / partition into the mounted drive /slash/.

  18. Download rsync from ftp://ftp.samba.org/pub/rsync/ and install it.

  19. # mke2fs /dev/sdb1 (the partition you set up as the duplicate for your / partition, but didn't use in the raidtab).

  20. Add the partition to your /etc/fstab:
    /dev/sdb1               /slash                      ext2    defaults        1 1

  21. Mount the new partition:
    # mount -a

  22. Run rsync manually the first time to verify that it works:
    # /usr/local/bin/rsync --delete -xra / /slash/
    and add it to your crontab:
    0 * * * * /usr/local/bin/rsync --delete -xra / /slash/ > /dev/null 2>&1



Last modified: Wednesday, December 31 1969 @ 19:00 EST
Google
WWW braindump.MrZesty.net
© Ian Samuel, 2012
http://braindump.MrZesty.net