sh 使用mdadm管理软RAID

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 使用mdadm管理软RAID相关的知识,希望对你有一定的参考价值。

# Those are advanced techniques about the software RAID managed by mdadm.
# BE VERY CAREFUL when using them!

### Advanced diagnostic commands
# Compare the events counters
mdadm --examine /dev/sd[XY]Z | grep Events
# Examine the disks for RAID information
mdadm --examine /dev/sd[ab][1-4]
# Examine the arrays for RAID information
mdadm --detail /dev/md[X-Y]

### Advanced management commands
# Force a RAID array to mount, even in degraded mode (eg. not enough devices)
mdadm --assemble --run /dev/mdX
# Force a RAID array to mount, even if some superblocks appear out-of-date
mdadm --assemble --force /dev/mdX
# Set a disk state to "failure"
mdadm (--manage) /dev/mdX --fail /dev/sdbY
# Remove a disk partition from an array
mdadm (--manage) /dev/mdX --remove /dev/sdbY
# Add a disk partition to an array (would probably trigger a rebuild automatically)
mdadm (--manage) /dev/mdX --add /dev/sdbY
# Daemon monitoring of the RAID
mdadm --monitor --help

####################

### Advanced data recovery
# ONLY FOR EXTREME SITUATIONS!

# Create a RAID5 array with 3 disks but a missing disk drive (WILL ERASE DATA)
mdadm --verbose --create /dev/mdX --level=5 --chunk=64 --metadata=0.9 --layout=left-symmetric --raid-devices=3 /dev/sdY1 /dev/sdZ1 missing
# ERASE the superblock (be careful with the metadata version)
mdadm (--misc) --zero-superblock /dev/sdX(1,2, ...)
# Rebuild the RAID superblock for last chance data recovery (the assumeclean option means that no rebuild would be triggered; this is very dangerous in case of disynchronization, be careful!)
mdadm --verbose --create /dev/md3 --assume-clean --level=5 --chunk=64 --metadata=0.9 --layout=left-symmetric --raid-devices=3 /dev/sdb4 /dev/sda4 missing
# Note: The --scan option can select the disks and partitions automatically
# for you in most of the operations, except when the superblocks are not
# present or corrupted.

### DISKS
# List the physical disk drives
fdisk -l
# Operate on the disk partitions
fdisk /dev/sdX

### RAID
# See the RAID current state
cat /proc/mdstat
# See the RAID configuration file, used at start-up (Ubuntu only?)
cat /etc/mdadm/mdadm.conf
# Add a RAID array into persistancy (Ubuntu only?)
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
# Assemble a RAID array automatically, by reading superblocks
mdadm --assemble --scan
# Disassemble a RAID array
mdadm --stop /dev/mdX
#mdadm --manage --stop /dev/mdX

### VOLUME
# Mount the array as a disk
mount /dev/mdX /user/mounting/point
# Unmount a disk (needed to disassemble a RAID array)
umount /user/mounting/point
# Procedure to properly replace a disk drive which is part of a RAID array
# Example case: replace /dev/sda by /dev/sdd from which
# the partition 1 is part of the array /dev/md0

# 1) If the drive is still present, attribute a "fail" state to the partition
mdadm (--manage) /dev/md0 --fail /dev/sda1
# 2) Safely remove the disk
mdadm (--manage) /dev/md0 --remove /dev/sda1
# 3) Copy the exact partition table to the new disk (WARNING, this will ERASE THE DATA)
sfdisk -d /dev/sda | sfdisk /dev/sdd
# 4) Add the new disk partition to the array (this will rebuild the disk automatically)
mdadm (--manage) /dev/md0 --add /dev/sdd1

以上是关于sh 使用mdadm管理软RAID的主要内容,如果未能解决你的问题,请参考以下文章

麒麟服务器操作系统管理和配置软RAID

Linux软Raid--mdadm命令

软RAID管理

使用mdadm创建软raid

如何使用linux程序mdadm创建软件RAID1软阵列

Centos 6 软Raid创建与管理