lsmod 列出模块:
[[email protected] mnt]# lsmod
Module Size Used by
ext2 58683 1
raid1 28564 1
autofs4 20405 3
ipt_REJECT 1867 2
nf_conntrack_ipv4 7694 2
nf_defrag_ipv4 1039 1 nf_conntrack_ipv4
iptable_filter 2173 1
ip_tables 9567 1 iptable_filter
ip6t_REJECT 3987 2
nf_conntrack_ipv6 7207 2
nf_defrag_ipv6 8897 1 nf_conntrack_ipv6
watch:周期性地执行指定的命令,并以全屏方式显示结果
-n #:指定周期长度,单位为秒,默认为2
格式: watch -n # ‘COMMAND‘
[[email protected] mnt]# watch -n 5 ‘cat /proc/mdstat‘ -n指定每隔几秒,不指定-n默认为每隔2秒
Every 5.0s: cat /proc/mdstat Fri Nov 4 17:12:06 2016
Personalities : [raid1]
md0 : active raid1 sdc[1] sdb[0]
5238720 blocks super 1.2 [2/2] [UU]
unused devices: <none>
mdadm命令简介:
此命令用于将任何块设备做成RAID。
1.命令格式:
mdadm [mode] <raiddevice> [options] <component-devices>
mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sda{5,6}
创建一个RAID0名称为md0, -l指定raid级别为0,-n设备个数为2 ,-a yes 表示自动创建
/dev/sda{5,6}表示设备sda5和sda6 组成一个raid0 首先必须把sda5和sda6分区为fd软RAID格式。
2.命令功能:
在linux系统中实现软RAID功能
3.命令参数:
默认模式为:管理模式
--add|-a : mdadm /dev/md0 -a /dev/sda9 把sda9加入到md0阵列中
--remove|-r: mdadm /dev/md0 -r /dev/sda7 把sda7从md0阵列中移除
--fail|-f: mdadm /dev/md0 -f /dev/sda8 使sda8在阵列卡中显示错误,无法利用该分区
mdadm /dev/md# -f /dev/sda7 模拟RAID阵列md#中的/dev/sda7设备损坏。
-C:创建模式
专用选项:
-l:指定RAID级别
-n #:指定设备个数 #为数字
-a {yes|no}:是否自动为其创建设备文件
-c:指定CHUNK数据块大小,大小需为2^n 方大小,不指定默认为64KB
-x #:指定空闲设备个数 #为数字当阵列中有分区故障,
空闲分区直接替代故障分区
-F:监控模式
-G:增长模式
-A:装配模式 启用阵列 mdadm -A /dev/md1 /dev/sda7 /dev/sda8 启用阵列必须指 定启用那个阵列以及阵列中所包含的设备或分区
-S|--stop:停止阵列 mdadm -S /dev/md# 停止使用阵列
-D|--detail:查看RAID阵列的详细信息
mdadm -D --scan > /etc/mdadm.conf 把阵列信息保存至阵列配置文件中,以后装配启 用阵列卡时会自动读取该配置文件中的信息。
[[email protected] mnt]# mdadm -D --scan
ARRAY /dev/md0 metadata=1.2 name=xuelinux:0 UUID=1d7eaf6f:25dc204f:9c8d9857:170bc4cc
mdadm -D /dev/md# 查看md# RAID阵列信息,#为数字
[[email protected] mnt]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Nov 4 16:28:30 2016
Raid Level : raid1
Array Size : 5238720 (5.00 GiB 5.36 GB)
Used Dev Size : 5238720 (5.00 GiB 5.36 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Fri Nov 4 16:37:51 2016
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : xuelinux:0 (local to host xuelinux)
UUID : 1d7eaf6f:25dc204f:9c8d9857:170bc4cc
Events : 17
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4.命令实例:
1、创建一个2G的软RAID1;
[[email protected] ~]# fdisk /dev/sda
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 首先创建2个2G的分区
First cylinder (2296-2611, default 2296):
Using default value 2296
Last cylinder, +cylinders or +size{K,M,G} (2296-2611, default 2611): +2G
Command (m for help): n
First cylinder (2296-2611, default 2296):
Using default value 2296
Last cylinder, +cylinders or +size{K,M,G} (2296-2611, default 2611): +2G
Command (m for help): t 修改分区格式
Partition number (1-9): 8
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): fd 把新建的2个分区修改为linux raid
Changed system type of partition 8 to fd (Linux raid autodetect)
Command (m for help): t 修改分区格式
Partition number (1-9): 9
Hex code (type L to list codes): fd 把新建的2个分区修改为linux raid
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f2a2b
Device Boot Start End Blocks Id System
/dev/sda1 * 1 256 2048000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 256 893 5120000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 893 1403 4096000 83 Linux
/dev/sda4 1403 2611 9706496 5 Extended
/dev/sda5 1403 1786 3072000 83 Linux
/dev/sda6 1786 2041 2048000 82 Linux swap / Solaris
/dev/sda7 2041 2296 2048000 83 Linux
/dev/sda8 2296 2557 2101951 fd Linux raid autodetect
/dev/sda9 2557 2818 2101951 fd Linux raid autodetect
[[email protected] ~]# partprobe 通知内核重新读取分区
[[email protected] ~]# cat /proc/partitions 查看内核是否读取到分区
major minor #blocks name
8 0 20971520 sda
8 1 2048000 sda1
8 2 5120000 sda2
8 3 4096000 sda3
8 4 1 sda4
8 5 3072000 sda5
8 6 2048000 sda6
8 7 2048000 sda7
8 8 1057726 sda8 2个分区已经识别
8 9 1060258 sda9
[[email protected] ~]# mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sda{8,9} 把sda8和sda9创建为 raid1,-C表示创建,-a yes表示自动应答,-l表示raid级别,-n表示设备个数
mdadm: array /dev/md0 started 创建完成并启动
[[email protected] ~]# cat /proc/mdstat 查看系统中启用的raid设备
Personalities : [raid0]
md0 : active raid0 sda9[1] sda8[0]
4048685 blocks 64k chunks
unused devices: <none>
[[email protected] ~]# mkfs -t ext4 /dev/md0 格式化raid设备为ext4类型
[[email protected] ~]# mount /dev/md0 /mnt 挂载raid设备,从而可以利用该raid设备