Managing RAID on Linux - Derek Vadala [50]
nr-raid-disks indicates that there are two disks in the array /dev/md0. Later in the file, each disk is defined by identifying its device name and its order in the array, using the device/raid-disk pair. To use more than two disks, you need only add additional device and raid-disk entries and increment the nr-raid-disks value.
Once /etc/raidtab is created, the mkraid program is used to build and activate the array:
# mkraid /dev/md0
handling MD device /dev/md0
analyzing super-block
disk 0: /dev/sdb1, 17920476kB, raid superblock at 17920384kB
disk 1: /dev/sdc1, 17920476kB, raid superblock at 17920384kB
The array was created successfully.
If you use mdadm, you don't need a configuration file. The array we showed previously can be created with the following command:
# mdadm -Cv -llinear -n2 /dev/md0 /dev/sd{b,c}1
mdadm: array /dev/md0 started.
The options are simple.
-C, --create
Create a new array.
-v, --verbose
Be more verbose.
-l, --raid-level
Select the RAID level: linear, 0, 1, 4, or 5.
-n, --raid-disks
Set the number of member disks in the array.
In addition to the options, mdadm takes a RAID device and a list of member partitions as its parameters. Note that the member disks are specified using standard shell expansions. The disk letters encapsulated in braces are expanded into /dev/sdb1 and /dev/sdc1 when mdadm is run. Consult the manual pages for your shell as needed; I use bash.
Increasing the number of member disks using -n or --raid-devices allows you to specify additional disks to be included in the array. List more disks on the command line individually, or as part of the glob (/dev/sd{b,c,d}1, for example). You could also use the long form of the command to accomplish the same task.
# mdadm --create --verbose --level=linear --raid-devices=2 \
/dev/md0 /dev/sdb1 /dev/sdc1
I'll use the short form of the command through the rest of this chapter. Chapter 4 contains a complete reference to all of the options in mdadm.
Both mkraid and mdadm automatically activate newly created arrays. Information about the array and its member disks is now available via the /proc/mdstat pseudofile.
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid5]
read_ahead 1024 sectors
md0 : active linear sdc1[1] sdb1[0]
35840768 blocks 64k rounding
unused devices: Next, create a filesystem on the new array. In this example, and throughout the rest of this chapter, I'll use the ext2 filesystem. If you want to use another filesystem, then simply substitute that command in place of mke2fs. Chapter 6 covers some newer filesystems available for Linux. # mke2fs /dev/md0 mke2fs 1.27 (8-Mar-2002) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 4480448 inodes, 8960192 blocks 448009 blocks (5.00%) reserved for the super user First data block=0 274 block groups 32768 blocks per group, 32768 fragments per group 16352 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, / 4096000, 7962624 Writing inode tables: done Writing superblocks and filesystem accounting information: done The preceding commands (mkraid or mdadm, and mke2fs) need to be executed only once. Each time the system boots, mount the array like any normal hard disk partition: # mount /dev/md0 /mnt/raid/linear # df -h /mnt/raid/linear Filesystem Size Used Avail Use% Mounted on /dev/md0 34G 20k 31G 1% /mnt/raid/linear You can modify your rc scripts to mount the array after it has been activated by using raidstart or mdadm. If you are using RAID autodetection, then an entry for the array can also be added to /etc/fstab so it will be mounted automatically when the system restarts. /dev/md0 /mnt/raid/linear ext2 defaults 1 2 Now, when the system restarts, the array (containing an ext2 filesystem)