Linux Software RAID Management - NL
- Details
- Hoofdcategorie: ROOT
- Categorie: Linux Items - NL
- Gepubliceerd: zaterdag 21 februari 2015 18:35
- Hits: 2566
mdadm: A New Tool For Linux Software RAID Management
Ik ging dit draaien onder Debian 5.02 Lenny echter onderstaande info is algemeen voor Linux!
mdadm (=> multiple devices admin):
http://en.wikipedia.org/wiki/Mdadm
mdadm is a Linux utility by Neil Brown that is used to manage software RAID devices, previously known as mdctl. Besides managing, it can create, delete, or monitor Linux software RAIDs. Available under version 2 or later of the GNU General Public License, mdadm is free software.
mdadm derives its name from the “md” (multiple disk) device nodes it “adm”inisters or manages.
http://neil.brown.name/git/mdadm/ < Hier staan de tags en logs over de ontwikkelingen.
http://packages.debian.org/nl/sid/mdadm < package 3.0-2
http://linuxmanpages.com/man8/mdadm.8.php < Manual mdadm.
Quick reference:
mdadm [mode] <raiddevice> [options] <component-devices>
Create a RAID 1 (mirror) volume from two partitions of exactly or nearly exactly the same size:
mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sdc1 /dev/sde1
If you receive an error, such as: "mdadm: RUN_ARRAY failed: Invalid argument", make sure your kernel supports (either via a module or by being directly compiled in) the raid mode you are trying to utilize.
To add RAID device md0 to /etc/mdadm.conf so that it is recognized the next time you boot.
mdadm -Es | grep md0 >>/etc/mdadm.conf
View the status of a multi disk array.
mdadm --detail /dev/md0
View the status of all multi disk arrays.
cat /proc/mdstat
INSTALLATIE:
Op de Debian v5.02 DVD ook een versie, maar ik heb de laatste gedraaid.
mdadm-3.0.tar.gz staat onderin op:
ftp://ftp.kernel.org/pub/linux/utils/raid/mdadm/
Vervolgens uitpakken in /etc/
En dan:
# sudo apt-get update
# sudo apt-get install mdadm
Hier vraagt ie om de 1ste DVD van Debian
HESTIA:/etc/mdadm-3.0# sudo apt-get install mdadm Pakketlijsten
worden ingelezen... Klaar
Boom van vereisten wordt opgebouwd
De status informatie wordt gelezen... Klaar De volgende NIEUWE
pakketten zullen genstalleerd worden:
mdadm
0 pakketten opgewaardeerd, 1 pakketten nieuw genstalleerd, 0 te verwijderen en 42 niet opgewaardeerd.
Er moeten 0B/275kB aan archieven opgehaald worden.
Door deze operatie zal er 799kB extra schijfruimte gebruikt worden.
Medium wisselen: Gelieve de schijf met label 'Debian GNU/Linux
5.0.2 _Lenny_ - Official i386 DVD Binary-1 20090628-15:08'
in het station '/cdrom/' te plaatsen en op 'enter' te drukken
Hierna plaats je dus de 1ste installatie DVD van Debian5.02
Bij mij kreeg ik uiteraard in eerste instantie een error:
_______________________________________________________________
Error:
E: Could not open lock file /var/cache/apt/archives/lock - open (2 No such file or directory)
E: Unable to lock the download directory
It seems that lock must be a file, not a directory. So make:
sudo rm -rf /var/cache/apt/archives/lock To delete the directory. Then make sudo touch /var/cache/apt/archives/lock To create an empty file After that:
#sudo apt-get update
HESTIA:/etc/mdadm-3.0# sudo apt-get install mdadm Pakketlijsten worden ingelezen... Klaar
Boom van vereisten wordt opgebouwd
De status informatie wordt gelezen... Klaar De volgende NIEUWE pakketten zullen genstalleerd worden:
mdadm
0 pakketten opgewaardeerd, 1 pakketten nieuw genstalleerd, 0 te verwijderen en 42 niet opgewaardeerd.
Er moeten 0B/275kB aan archieven opgehaald worden.
Door deze operatie zal er 799kB extra schijfruimte gebruikt worden.
debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Hulpbron is tijdelijk onbeschikbaar Selecteren van voorheen niet geselecteerd pakket mdadm.
(Database inlezen ... 96543 bestanden en mappen genstalleerd.) Uitpakken van mdadm (uit .../mdadm/mdadm_2.6.7.2-3_i386.deb) ...
Processing triggers for man-db ...
Instellen van mdadm (2.6.7.2-3) ...
debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Hulpbron is tijdelijk onbeschikbaar
dpkg: fout bij afhandelen van mdadm (--configure):
subproces post-installation script gaf een foutwaarde 1 terug Fouten gevonden tijdens behandelen van:
mdadm
E: Sub-process /usr/bin/dpkg returned an error code (1)
Uiteindelijk kreeg ik de installatie toch voor elkaar:
# HESTIA:/home/johfrael# sudo apt-get install mdadm
Pakketconfiguratie
Bezig met configureren van mdadm
Als het basisbestandssysteem van uw systeem zich op een RAID-volume
bevindt, dient dit vroeg in de opstartcyclus geactiveerd te worden. Als het zich op een logisch volume (LVM) op RAID bevindt, dienen alle betrokken reeksen geactiveerd te worden.
Als u precies weet welke reeksen benodigd zijn voor het
basisbestandssysteem en u het activeren van alle overige reeksen wilt
uitstellen tot later in de opstartprocedure, geef dan hier de te
activeren reeksen in. Anders kunt u 'all' ingeven om alle beschikbare
reeksen te activeren.
Als u geen reeksen hoeft of wenst te activeren voor het
basisbestandssysteem, laat dan het antwoord leeg (of geef 'none' in).
Dit kan het geval zijn als u "kernel autostart" gebruikt of geen
reeksen nodig heeft om uw systeem op te starten.
Geef in 'all' (alle), 'none' (geen) of n of meerdere apparaatbestanden (gescheiden door spaties), bijvoorbeeld "md0 md1" of "md/1 md/d0" (de
prefix '/dev/' kan dus worden weggelaten).
<Ok>
_______________________________________________________
Na installatie:
HESTIA:/home/johfrael# mdadm --monitor
mdadm: Cannot monitor: need --scan or at least one device HESTIA:/home/johfrael# mdadm --scan
mdadm: --scan does not set the mode, and so cannot be the first option.
HESTIA:/home/johfrael# mdadm --help
mdadm is used for building, managing, and monitoring Linux md devices (aka RAID arrays)
Usage: mdadm --create device options...
Create a new array from unused devices.
mdadm --assemble device options...
Assemble a previously created array.
mdadm --build device options...
Create or assemble an array without metadata.
mdadm --manage device options...
make changes to an existing array.
mdadm --misc options... devices
report on or modify various md related devices.
mdadm --grow options device
resize/reshape an active array
mdadm --incremental device
add a device to an array as appropriate
mdadm --monitor options...
Monitor one or more array for significant changes.
mdadm device options...
Shorthand for --manage.
Any parameter that does not start with '-' is treated as a device name or, for --examine-bitmap, a file name.
The first such name is often the name of an md device. Subsequent names are often names of component devices.
For detailed help on the above major modes use --help after the mode e.g.
mdadm --assemble --help
For general help on options use
mdadm --help-options
_______________________________________________________________
Zie volgende pagina voor het gebruik van mdadm!
{mospagebreak}
mdadm has five major modes of operation. The first two modes, Create and Assemble, are used to configure and activate arrays. Manage mode is used to manipulate devices in an active array. Follow or Monitor mode allows administrators to configure event notification and actions for arrays. Build mode is used when working with legacy arrays that use an old version of the md driver. I will not cover build mode in this article. The remaining options are used for various housekeeping tasks and are not attached to a specific mode of operation, although the mdadm documentation calls these options Misc mode.
Creating an Array
Create (mdadm --create) mode is used to create a new array. In this example I use mdadm to create a RAID-0 at /dev/md0 made up of /dev/sdb1 and /dev/sdc1:
# mdadm --create --verbose /dev/md0 --level=0
--raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: chunk size defaults to 64K
mdadm: array /dev/md0 started.
The --level option specifies which type of RAID to create in the same way that raidtools uses the raid-level configuration line. Valid choices are 0,1,4 and 5 for RAID-0, RAID-1, RAID-4, RAID-5 respectively. Linear (--level=linear) is also a valid choice for linear mode. The --raid-devices option works the same as the nr-raid-disks option when using /etc/raidtab and raidtools.
In general, mdadm commands take the format:
mdadm [mode] [options]
Each of mdadm's options also has a short form that is less descriptive but shorter to type. For example, the following command uses the short form of each option but is identical to the example I showed above.
# mdadm -Cv /dev/md0 -l0 -n2 -c128 /dev/sdb1 /dev/sdc1
-C selects Create mode, and I have also included the -v option here to turn on verbose output. -l and -n specify the RAID level and number of member disks. Users of raidtools and /etc/raidtab can see how much easier it is to create arrays using mdadm. You can change the default chunk size (64KB) using the --chunk or -c option. In this previous example I changed the chunk size to 128KB. mdadm also supports shell expansions, so you don't have to type in the device name for every component disk if you are creating a large array. In this example, I'll create a RAID-5 with five member disks and a chunk size of 128KB:
# mdadm -Cv /dev/md0 -l5 -n5 -c128 /dev/sd{a,b,c,d,e}1
mdadm: layout defaults to left-symmetric
mdadm: array /dev/md0 started.
This example creates an array at /dev/md0 using SCSI disk partitions /dev/sda1, /dev/sdb1, /dev/sdc1, /dev/sdd1, and /dev/sde1. Notice that I have also set the chunk size to 128 KB using the -c128 option. When creating a RAID-5, mdadm will automatically choose the left-symmetric parity algorithm, which is the best choice.
Use the --stop or -S command to stop running array:
# mdadm -S /dev/md0
/etc/mdadm.conf
/etc/mdadm.conf is mdadms' primary configuration file. Unlike /etc/raidtab, mdadm does not rely on /etc/mdadm.conf to create or manage arrays. Rather, mdadm.conf is simply an extra way of keeping track of software RAIDs. Using a configuration file with mdadm is useful, but not required. Having one means you can quickly manage arrays without spending extra time figuring out what array properties are and where disks belong. For example, if an array wasn't running and there was no mdadm.conf file describing it, then the system administrator would need to spend time examining individual disks to determine array properties and member disks.
Unlike the configuration file for raidtools, mdadm.conf is concise and simply lists disks and arrays. The configuration file can contain two types of lines each starting with either the DEVICE or ARRAY keyword. Whitespace separates the keyword from the configuration information. DEVICE lines specify a list of devices that are potential member disks. ARRAY lines specify device entries for arrays as well as identifier information. This information can include lists of one or more UUIDs, md device minor numbers, or a listing of member devices.
A simple mdadm.conf file might look like this:
DEVICE /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
ARRAY /dev/md0 devices=/dev/sda1,/dev/sdb1
ARRAY /dev/md1 devices=/dev/sdc1,/dev/sdd1
In general, it's best to create an /etc/mdadm.conf file after you have created an array and update the file when new arrays are created. Without an /etc/mdadm.conf file you'd need to specify more detailed information about an array on the command in order to activate it. That means you'd have to remember which devices belonged to which arrays, and that could easily become a hassle on systems with a lot of disks. mdadm even provides an easy way to generate ARRAY lines. The output is a single long line, but I have broken it here to fit the page:
# mdadm --detail --scan
ARRAY /dev/md0 level=raid0 num-devices=2
UUID=410a299e:4cdd535e:169d3df4:48b7144a
If there were multiple arrays running on the system, then mdadm would generate an array line for each one. So after you're done building arrays you could redirect the output of mdadm --detail --scan to /etc/mdadm.conf. Just make sure that you manually create a DEVICE entry as well. Using the example I've provided above we might have an /etc/mdadm.conf that looks like:
DEVICE /dev/sdb1 /dev/sdc1
ARRAY /dev/md0 level=raid0 num-devices=2
UUID=410a299e:4cdd535e:169d3df4:48b7144a
Starting an Array
Assemble mode is used to start an array that already exists. If you created an /etc/mdadm.conf you can automatically start an array listed there with the following command:
# mdadm -As /dev/md0
mdadm: /dev/md0 has been started with 2 drives.
The -A option denotes assemble mode. You can also use --assemble. The -s or --scan option tells mdadm to look in /etc/mdadm.conf for information about arrays and devices. If you want to start every array listed in /etc/mdadm.conf, don't specify an md device on the command line.
If you didn't create an /etc/mdadm.conf file, you will need to specify additional information on the command line in order to start an array. For example, this command attempts to start /dev/md0 using the devices listed on the command line:
# mdadm -A /dev/md0 /dev/sdb1 /dev/sdc1
Since using mdadm -A in this way assumes you have some prior knowledge about how arrays are arranged, it might not be useful on systems that have arrays that were created by someone else. So you may wish to examine some devices to gain a better picture about how arrays should be assembled. The examine options (-E or --examine) allows you to print the md superblock (if present) from a block device that could be an array component.
# mdadm -E /dev/sdc1
/dev/sdc1:
Magic : a92b4efc
Version : 00.90.00
UUID : 84788b68:1bb79088:9a73ebcc:2ab430da
Creation Time : Mon Sep 23 16:02:33 2002
Raid Level : raid0
Device Size : 17920384 (17.09 GiB 18.40 GB)
Raid Devices : 4
Total Devices : 4
Preferred Minor : 0
Update Time : Mon Sep 23 16:14:52 2002
State : clean, no-errors
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Checksum : 8ab5e437 - correct
Events : 0.10
Chunk Size : 128K
Number Major Minor RaidDevice State
this 1 8 33 1 active sync /dev/sdc1
0 0 8 17 0 active sync /dev/sdb1
1 1 8 33 1 active sync /dev/sdc1
2 2 8 49 2 active sync /dev/sdd1
3 3 8 65 3 active sync /dev/sde1
mdadm's examine option displays quite a bit of useful information about component disks. In this case we can tell that /dev/sdc1 belongs to a RAID-0 made up of a total of four member disks. What I want to specifically point out is the line of output that contains the UUID. A UUID is a 128-bit number that is guaranteed to be reasonably unique on both the local system and across other systems. It is a randomly generated using system hardware and timestamps as part of its seed. UUIDs are commonly used by many programs to uniquely tag devices. See the uuidgen and libuuid manual pages for more information.
When an array is created, the md driver generates a UUID for the array and stores it in the md superblock. You can use the UUID as criteria for array assembly. In the next example I am going to activate the array to which /dev/sdc1 belongs using its UUID.
# mdadm -Av /dev/md0 --uuid=84788b68:1bb79088:9a73ebcc:2ab430da /dev/sd*
This command scans every SCSI disk (/dev/sd*) to see if it's a member of the array with the UUID 84788b68:1bb79088:9a73ebcc:2ab430da and then starts the array, assuming it found each component device. mdadm will produce a lot of output each time it tries to scan a device that does not exist. You can safely ignore such warnings.
Managing Arrays
Using Manage mode you can add and remove disks to a running array. This is useful for removing failed disks, adding spare disks, or adding replacement disks. Manage mode can also be used to mark a member disk as failed. Manage mode replicates the functions of raidtools programs such as raidsetfaulty, raidhotremove, and raidhotadd.
For example, to add a disk to an active array, replicating the raidhotadd command:
# mdadm /dev/md0 --add /dev/sdc1
Or, to remove /dev/sdc1 from /dev/md0 try:
# mdadm /dev/md0 --f ail /dev/sdc1 --remove /dev/sdc1
Notice that I first mark /dev/sdc1 as failed and then remove it. This is the same as using the raidsetfaulty and raidhotremove commands with raidtools. It's fine to combine add, fail, and remove options on a single command line as long as they make sense in terms of array management. So you have to fail a disk before removing it, for example.
Monitoring Arrays
Follow, or Monitor, mode provides some of mdadm's best and most unique features. Using Follow/Monitor mode you can daemonize mdadm and configure it to send email alerts to system administrators when arrays encounter errors or fail. You can also use Follow mode to arbitrarily execute commands when a disk fails. For example, you might want to try removing and reinserting a failed disk in an attempt to correct a non-fatal failure without user intervention.
The following command will monitor /dev/md0 (polling every 300 seconds) for critical events. When a fatal error occurs, mdadm will send an email to sysadmin. You can tailor the polling interval and email address to meet your needs.
# mdadm --monitor --mail=sysadmin --delay=300 /dev/md0
When using monitor mode, mdadm will not exit, so you might want to wrap it around nohup and ampersand:
# nohup mdadm --monitor --mail=sysadmin --delay=300 /dev/md0 &
Follow/Monitor mode also allows arrays to share spare disks, a feature that has been lacking in Linux software RAID since its inception. That means you only need to provide one spare disk for a group of arrays or for all arrays. It also means that system administrators don't have to manually intervene to shuffle around spare disks when arrays fail. Previously this functionality was available only using hardware RAID. When Follow/Monitor mode is invoked, it polls arrays at regular intervals. When a disk failure is detected on an array without a spare disk, mdadm will remove an available spare disk from another array and insert it into the array with the failed disk. To facilitate this process, each ARRAY line in /etc/mdadm.conf needs to have a spare-group defined.
DEVICE /dev/sd*
ARRAY /dev/md0 level=raid1 num-devices=3 spare-group=database
UUID=410a299e:4cdd535e:169d3df4:48b7144a
ARRAY /dev/md1 level=raid1 num-device=2 spare-group=database
UUID=59b6e564:739d4d28:ae0aa308:71147fe7
In this example, both /dev/md0 and /dev/md1 are part of the spare group database. Just assume that /dev/md0 is a two-disk RAID-1 with a single spare disk. If mdadm is running in monitor mode (as I showed earlier), and a disk in /dev/md1 fails, mdadm will remove the spare disk from /dev/md0 and insert it into /dev/md1.
mdadm has many other options that I haven't covered here. I strongly recommend reading its manual page for further details. Remember, you don't have to switch to mdadm. raidtools is still in development, and it has the benefit of many years of development. But, I find that mdadm is a worthy replacement. It is both feature rich and intuitive, and there's no harm in trying out alternatives.
Derek Vadala is the author of O'Reilly's upcoming book, "Managing RAID on Linux."
Managing RAID on Linux covers everything system administrators need to know to put together a system that can support RAID. You will learn about the different types of RAID, along with associated technologies and issues, and how to choose the best RAID system for your needs. With a step-by-step, hands-on approach, the author guides you through the installation of either Linux software RAID or a hardware RAID card. |
http://linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html
ftp://ftp.kernel.org/pub/linux/utils/raid/mdadm/
http://linuxmanpages.com/man8/mdadm.8.php