分类: LINUX
2009-07-14 13:57:16
dd if=/dev/zero of=a1 bs=1024k count=100 dd if=/dev/zero of=a2 bs=1024k count=100 dd if=/dev/zero of=a3 bs=1024k count=100 losetup /dev/loop1 a1 losetup /dev/loop2 a2 losetup /dev/loop3 a3 [root@max max]# losetup -a /dev/loop1: [0801]:1338287 (a1) /dev/loop2: [0801]:1403539 (a2) /dev/loop3: [0801]:1403540 (a3) [root@max max]# |
mdadm -Cv /dev/md0 -l1 -n2 /dev/loop1 /dev/loop2 |
[root@max max]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 loop2[1] loop1[0] 102336 blocks [2/2] [UU] [=====>...............] resync = 25.0% (26112/102336) finish=0.3min speed=3264K/sec unused devices: [root@max max]# |
[root@max max]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 loop2[1] loop1[0] 102336 blocks [2/2] [UU] unused devices: [root@max max]# |
[root@max max]# echo DEVICE /dev/loop[12] >> /etc/mdadm.conf [root@max max]# mdadm --detail --scan >> /etc/mdadm.conf [root@max max]# cat /etc/mdadm.conf DEVICE /dev/loop1 /dev/loop2 ARRAY /dev/md0 level=raid1 num-devices=2 UUID=2d820f8b:e4a9455d:0f27158d:bf48c47c [root@max max]# |
[root@max max]# mdadm --detail /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 13:51:37 2009 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Events : 0.2 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 1 7 2 1 active sync /dev/loop2 |
[root@max max]# mdadm -E /dev/loop2 /dev/loop2: Magic : a92b4efc Version : 00.90.00 UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Device Size : 102336 (99.95 MiB 104.79 MB) Array Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Update Time : Tue Jul 14 13:51:37 2009 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Checksum : 1e8047f4 - correct Events : 0.2 Number Major Minor RaidDevice State this 1 7 2 1 active sync /dev/loop2 0 0 7 1 0 active sync /dev/loop1 1 1 7 2 1 active sync /dev/loop2 |
[root@max max]# mdadm /dev/md0 --fail /dev/loop2 --remove /dev/loop2 mdadm: set /dev/loop2 faulty in /dev/md0 mdadm: hot removed /dev/loop2 以上命令是定义一个盘失效。并把它移走。 [root@max max]# mdadm --detail --scan /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 1 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 14:03:59 2009 State : clean, degraded Active Devices : 1 Working Devices : 1 Failed Devices : 0 Spare Devices : 0 UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Events : 0.6 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 1 0 0 1 removed |
[root@max max]# mdadm /dev/md0 --add /dev/loop3 mdadm: added /dev/loop3 [root@max max]# mdadm --detail --scan /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 14:05:34 2009 State : clean, degraded, recovering Active Devices : 1 Working Devices : 2 Failed Devices : 0 Spare Devices : 1 Rebuild Status : 21% complete UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Events : 0.8 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 2 7 3 1 spare rebuilding /dev/loop3 |
[root@max max]# mdadm /dev/md0 --add /dev/loop2 mdadm: added /dev/loop2 [root@max max]# mdadm --detail --scan /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 3 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 14:06:33 2009 State : clean Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Events : 0.10 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 1 7 3 1 active sync /dev/loop3 2 7 2 - spare /dev/loop2 [root@max max]# mdadm --detail --scan /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 13:50:59 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 3 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 14:06:33 2009 State : clean Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 UUID : 2d820f8b:e4a9455d:0f27158d:bf48c47c Events : 0.10 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 1 7 3 1 active sync /dev/loop3 2 7 2 - spare /dev/loop2 [root@max max]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 loop2[2](S) loop3[1] loop1[0] 102336 blocks [2/2] [UU] unused devices: [root@max max]# |
[root@max max]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 loop3[2](S) loop2[1] loop1[0] 102336 blocks [2/2] [UU] [======>..............] resync = 31.0% (32640/102336) finish=0.4min speed=2720K/sec unused devices: [root@max max]# mdadm --detail /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Jul 14 14:12:15 2009 Raid Level : raid1 Array Size : 102336 (99.95 MiB 104.79 MB) Device Size : 102336 (99.95 MiB 104.79 MB) Raid Devices : 2 Total Devices : 3 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Jul 14 14:12:15 2009 State : clean, resyncing Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Rebuild Status : 46% complete UUID : 6b4eab79:fbca64ef:6e8aa6df:9992a62f Events : 0.1 Number Major Minor RaidDevice State 0 7 1 0 active sync /dev/loop1 1 7 2 1 active sync /dev/loop2 2 7 3 - spare /dev/loop3 |
mdadm --monitor --mail=my-mail --delay=300 /dev/md0 |
[root@max max]# mdadm -A /dev/md0 /dev/loop[123] |
mdadm是linux下用于管理软件 raid 的工具 以下内容来自 manpage 页: 基本语法 : mdadm [mode] [options] [mode] 有7种: Assemble:将以前定义的某个阵列加入当前在用阵列。 Build:Build a legacy array ,每个device 没有 superblocks Create:创建一个新的阵列,每个device 具有 superblocks Manage: 管理阵列,比如 add 或 remove Misc:允许单独对阵列中的某个 device 做操作,比如抹去superblocks 或 终止在用的阵列。 Follow or Monitor:监控 raid 1,4,5,6 和 multipath 的状态 Grow:改变raid 容量或 阵列中的 device 数目 可用的 [options]: -A, --assemble:加入一个以前定义的阵列 -B, --build:Build a legacy array without superblocks. -C, --create:创建一个新的阵列 -Q, --query:查看一个device,判断它为一个 md device 或是 一个 md 阵列的一部分 -D, --detail:打印一个或多个 md device 的详细信息 -E, --examine:打印 device 上的 md superblock 的内容 -F, --follow, --monitor:选择 Monitor 模式 -G, --grow:改变在用阵列的大小或形态 -h, --help:帮助信息,用在以上选项后,则显示该选项信息 --help-options -V, --version -v, --verbose:显示细节 -b, --brief:较少的细节。用于 --detail 和 --examine 选项 -f, --force -c, --config= :指定配置文件,缺省为 /etc/mdadm/mdadm.conf -s, --scan:扫描配置文件或 /proc/mdstat以搜寻丢失的信息。配置文件/etc/mdadm/mdadm.conf create 或 build 使用的选项: -c, --chunk=:Specify chunk size of kibibytes. 缺省为 64. --rounding=: Specify rounding factor for linear array (==chunk size) -l, --level=:设定 raid level. --create可用:linear, raid0, 0, stripe, raid1,1, mirror, raid4, 4, raid5, 5, raid6, 6, multipath, mp. --build可用:linear, raid0, 0, stripe. -p, --parity=:设定 raid5 的奇偶校验规则:eft-asymmetric, left-symmetric, right-asymmetric, right-symmetric, la, ra, ls, rs.缺省为left-symmetric --layout=:类似于--parity -n, --raid-devices=:指定阵列中可用 device 数目,这个数目只能由 --grow 修改 -x, --spare-devices=:指定初始阵列的富余device 数目 -z, --size=:组建RAID1/4/5/6后从每个device获取的空间总数 --assume-clean:目前仅用于 --build 选项 -R, --run:阵列中的某一部分出现在其他阵列或文件系统中时,mdadm会确认该阵列。此选项将不作确认。 -f, --force:通常mdadm不允许只用一个device 创建阵列,而且创建raid5时会使用一个device作为missing drive。此选项正相反。 -a, --auto{=no,yes,md,mdp,part,p}{NN}: |