Mdadm: Difference between revisions

From Leo's Notes
This page was last edited on 26 April 2017, at 17:36.
m Text replacement - "</code>" to "}}"
formatting
Line 1: Line 1:
== Creating a Raid 1 Mirror ==
mdadm is a Linux utility to manage software RAID.


mdadm --zero-superblock /dev/sdb
== Quick Usage ==
mdadm --zero-superblock /dev/sdc
=== Creating a Raid 1 Mirror ===
{{highlight|lang=terminal|code=
# mdadm --zero-superblock /dev/sdb
# mdadm --zero-superblock /dev/sdc
}}


Create the array:
Create the array:
mdadm --create /dev/md0 --chunk=4 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
{{highlight|lang=terminal|code=
# mdadm --create /dev/md0 --chunk=4 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
}}


That's it! Create the file system and you're done. Using 4k chunk size.
That's it! Create the filesystem and you're done. Using 4k chunk size.


To save your settings, run:
To save your settings, run:


# echo "DEVICES /dev/sdb /dev/sdc" > /etc/mdadm.conf
{{highlight|lang=terminal|code=
# mdadm --detail --scan >> /etc/mdadm.conf
# echo "DEVICES /dev/sdb /dev/sdc" > /etc/mdadm.conf
# cat /etc/mdadm.conf
# mdadm --detail --scan >> /etc/mdadm.conf
DEVICES /dev/sdb /dev/sdc
# cat /etc/mdadm.conf
ARRAY /dev/md/0 metadata=1.2 name=data:0 UUID=5f486d36:37899fcb:99ad8485:088bc180
DEVICES /dev/sdb /dev/sdc
ARRAY /dev/md/0 metadata=1.2 name=data:0 UUID=5f486d36:37899fcb:99ad8485:088bc180
}}


== Creating a Raid 5 ==
=== Creating a Raid 5 ===


Create the array:
Create the array:
mdadm --create /dev/md0 --chunk=128 --level=5 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde
{{highlight|lang=terminal|code=
# mdadm --create /dev/md0 --chunk=128 --level=5 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde
}}


You can specify hot spares with {{code|--spare-devices=N /dev/sdn}}
You can specify hot spares with {{code|1=--spare-devices=N /dev/sdn}}


== Disassemble / stop an array ==
=== Disassemble / stop an array ===
{{highlight|lang=terminal|code=
# mdadm --stop /dev/md0
}}


=== Reassemble an array ===
{{highlight|lang=terminal|code=
# mdadm --assemble --scan
}}


mdadm --stop /dev/md0
You can assemble an array with specific devices using:
 
{{highlight|lang=terminal|code=
== Reassemble an array ==
# mdadm --assemble /dev/md0 /dev/sdb /dev/sdc
mdadm --assemble --scan
}}
 
You can assemble an array like:
mdadm --assemble /dev/md0 /dev/sdb /dev/sdc
 


== Issues ==
== Issues ==
If you're unable to reassemble an array with this error:
{{highlight|lang=terminal|code=
# mdadm -A /dev/md0 /dev/sdb /dev/sdc
mdadm: cannot open device /dev/sdb: Device or resource busy
mdadm: /dev/sdb has no superblock - assembly aborted
}}


# mdadm -A /dev/md0 /dev/sdb /dev/sdc
You probably forgot to define your mdadm.conf settings before rebooting and mdadm probably tried to do something with one of your disks to create {{code|/dev/md127}} (hence the reason the device is busy). To free {{code|/dev/sdb}} in the above example, just stop {{code|/dev/md127}} by running:
mdadm: cannot open device /dev/sdb: Device or resource busy
{{highlight|lang=terminal|code=
mdadm: /dev/sdb has no superblock - assembly aborted
# mdadm --stop /dev/md127
 
}}
If you forgot to define your mdadm.conf settings and rebooted, mdadm probably tried to do something with one of your disks to create {{code|/dev/md127}}. To free {{code|/dev/sdb}} in the above example, just stop {{code|/dev/md127}} by running:
mdadm --stop /dev/md127


And then retry reassembling the array again.
And then retry reassembling the array again.

Revision as of 17:36, 26 April 2017

mdadm is a Linux utility to manage software RAID.

Quick Usage

Creating a Raid 1 Mirror

# mdadm --zero-superblock /dev/sdb
# mdadm --zero-superblock /dev/sdc

Create the array:

# mdadm --create /dev/md0 --chunk=4 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

That's it! Create the filesystem and you're done. Using 4k chunk size.

To save your settings, run:

# echo "DEVICES /dev/sdb /dev/sdc" > /etc/mdadm.conf
# mdadm --detail --scan >> /etc/mdadm.conf
# cat /etc/mdadm.conf
DEVICES /dev/sdb /dev/sdc
ARRAY /dev/md/0 metadata=1.2 name=data:0 UUID=5f486d36:37899fcb:99ad8485:088bc180

Creating a Raid 5

Create the array:

# mdadm --create /dev/md0 --chunk=128 --level=5 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

You can specify hot spares with --spare-devices=N /dev/sdn

Disassemble / stop an array

# mdadm --stop /dev/md0

Reassemble an array

# mdadm --assemble --scan

You can assemble an array with specific devices using:

# mdadm --assemble /dev/md0 /dev/sdb /dev/sdc

Issues

If you're unable to reassemble an array with this error:

# mdadm -A /dev/md0 /dev/sdb /dev/sdc
mdadm: cannot open device /dev/sdb: Device or resource busy
mdadm: /dev/sdb has no superblock - assembly aborted

You probably forgot to define your mdadm.conf settings before rebooting and mdadm probably tried to do something with one of your disks to create /dev/md127 (hence the reason the device is busy). To free /dev/sdb in the above example, just stop /dev/md127 by running:

# mdadm --stop /dev/md127

And then retry reassembling the array again.