RAID and Mdadm command two

Source: Internet
Author: User
Tags hex code

Hardware RAID: The motherboard contains a RAID card, to enable the raid must enter the BIOS boot RAID card function, and in the designated RAID level and the hard disk, when we enable hardware RAID, when we install the operating system, the system must contain a RAID driver, Because at this point in the hardware level, it is not considered to have a hard disk, but is considered to have raid.


Software RAID: Simulate RAID with software

Condition: The kernel contains the MD (Multi disk) module (Linux through the device file access device, but our hard disk in Linux is simulated into SDA,HDA, etc., is not a raid setting, so the MD module to simulate the hard disk as a/dev/md# file, The operating system uses it to operate the raid device, and the stored access process of the data is completed by the function provided by the module.

Performance: Performance depends on the ability of the CPU,CPU itself and idle or not, etc.

Note: Hard disks that do soft raid must be identified as the type that the kernel recognizes: the FD type, so that when the operating system uses the RAID device, some metadata is stored on the hard disk to record the soft raid information, otherwise, when the system hangs, the data inside the raid will no longer be used. resulting in data loss


How to use:

Mdadm: Make any block device raid

Modal Commands:

Create a pattern

-C

-L: Level

-N: Number of devices

-A {yes|0}: whether to automatically create a device file for it

-c|--chunk: Default 64kB (chunk refers to the size of each segmented chunk in stripe technology)

-X: Specify the number of free disks

Management mode

--add--del

Monitoring mode

-F

Growth model

-G

Assembly mode

-A

To view detailed information about a RAID array:

Mdadm-d (--detail)/dev/md#

Cat/proc/mdstat

Stop array

Mdadm-s/dev/md#

--stop


Save the current RAID information to a configuration file for subsequent assembly:

mdamd-d--scan >/etc/mdadm.conf


Watch: Executes the specified command periodically and displays the results in full-screen mode

-N #: Specifies the period length in seconds and defaults to 2

Format: Watch-n # ' COMMAND '


Mke2fs-j-E stride=16-b 4096/dev/md0

When you create a raid, if you do not specify a chunk size, the default is 64k, but 1 chunk default has a few data blocks, this depends on the block size, assuming that block is 4096, the default is 64k/4k=16 block, but the raid every time to calculate the number of blocks, As a result, we specify block and block numbers (also known as stride) when formatting, which optimizes raid performance.


Soft RAID Example:

[Email protected] ~]# mdadm-c/dev/md0-a yes-n 2-l 1/dev/sdb1/dev/sdb2 (Create RAID1)

Mdadm:Note:this array have metadata at the start and

May is suitable as a boot device. If you plan to

Store '/boot ' on this device, ensure that

Your Boot-loader understands md/v1.x metadata, or use

--metadata=0.90

Continue creating array? Y

Mdadm:defaulting to version 1.2 metadata

Mdadm:array/dev/md0 started.

[[email protected] ~]# Cat/proc/mdstat (View raid status)

Personalities: [RAID1]

Md0:active RAID1 sdb1[0] sdb2[1]

2102400 Blocks Super 1.2 [2/2] [UU]

Unused devices: <none>

[Email protected] ~]# mke2fs-j-e stride=16-b 4096/dev/md0 (formatted RAID)

MKE2FS 1.41.12 (17-may-2010)

Filesystem label=

OS Type:linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

(limited to space, the following minor command, only to intercept part of the information to illustrate the problem)

[Email protected] ~]# mkdir/md0

[[email protected] ~]# mount/dev/md0/md0/(Mount RAID)

[Email protected] ~]# cd/md0/

[Email protected] md0]# Cp/etc/inittab.

[email protected] md0]# cat Inittab

# Inittab is a used by upstart for the default runlevel.

#

# ADDING Other CONFIGURATION here would have NO EFFECT on YOUR SYSTEM.

[[email protected] md0]# mdadm-d/dev//md0 (view raid1 details)

Number Major Minor Raiddevice state

0 8 0 Active SYNC/DEV/SDB1

1 8 1 Active SYNC/DEV/SDB2

[[email protected] md0]# mdadm/dev/md0-f/dev/sdb1 (analog sdb1 hung off)

MDADM:SET/DEV/SDB1 Faulty in/dev/md0

[[email protected] md0]#!ca (the file is still accessible at this time)

Cat Inittab

# Inittab is a used by upstart for the default runlevel.

#

# ADDING Other CONFIGURATION here would have NO EFFECT on YOUR SYSTEM.

[Email protected] md0]# mdadm-d/dev//md0

Number Major Minor Raiddevice state

0 0 0 0 removed

1 8 1 Active SYNC/DEV/SDB2


0 8 17-FAULTY/DEV/SDB1



[Email protected] md0]# Fdisk/dev/sdb


Warning:dos-compatible mode is deprecated. It ' s strongly recommended to

Switch off the mode (command ' C ') and change display units to

Sectors (Command ' u ').


Command (M for help): N

Command Action

E Extended

P primary partition (1-4)

3

Invalid partition number for type ' 3 '

Command Action

E Extended

P primary partition (1-4)

P

Partition number (1-4): 3

First cylinder (525-2610, default 525):

Using Default Value 525

Last cylinder, +cylinders or +size{k,m,g} (525-2610, default 2610): +2g


Command (M for help): t

Partition number (1-4): 3

Hex code (type L to list codes): FD

Changed system type of partition 3 to FD (Linux raid AutoDetect)


Command (M for help): P


disk/dev/sdb:21.5 GB, 21474836480 bytes

255 heads, Sectors/track, 2610 cylinders

Units = Cylinders of 16065 * 8225280 bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk identifier:0xddd53329


Device Boot Start End Blocks Id System

/DEV/SDB1 1 262 2104483+ fd Linux raid AutoDetect

/DEV/SDB2 263 524 2104515 FD Linux raid AutoDetect

/DEV/SDB3 525 786 2104515 fd Linux raid AutoDetect


Command (M for help): W

The partition table has been altered!


Calling IOCTL () to re-read partition table.


Warning:re-reading the partition table failed with error 16:device or resource busy.

The kernel still uses the old table. The new table is being used at

The next reboot or after you run Partprobe (8) or KPARTX (8)

Syncing disks.


[[email protected] md0]# mdadm/dev/md0-r/dev/sdb1 (remove sdb1)

Mdadm:hot REMOVE/DEV/SDB1

[Email protected] md0]# mdadm/dev/md0-a/dev/sdb3 (add sdb3)

Mdadm:added/dev/sdb3

[Email protected] md0]# mdadm-d/dev/md0

Number Major Minor Raiddevice state

2 8 0 Active SYNC/DEV/SDB3

1 8 1 Active SYNC/DEV/SDB2

[Email protected]/]# mdadm-s/dev/md0

Mdadm:cannot Get exclusive access to/dev/md0:perhaps a running process, mounted filesystem or active volume group?

[Email protected]/]# umount/dev/md0

[Email protected]/]# mdadm-s/dev/md0

Mdadm:stopped/dev/md0

[[email protected]/]# rm/dev/md0 (md0 completely removed here)

Rm:remove block special file '/dev/md0 '? Y


[Email protected] ~]# mdadm-c/dev/md0-a yes-n 2-l 0/dev/sdb1/dev/sdb2-x 1/dev/sdb3

Mdadm:spare-devices setting is incompatible with RAID level 0

(When creating a raid, set up redundancy, when a disk is broken, the free disk is replaced automatically)


RAID and Mdadm command two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.