Linux 磁盘管理~~~~RAID1
实验环境
Linux操作系统的pc机上添加2块30g大小的磁盘
实施步骤:
1.0
对磁盘进行分区
[[email protected]~]# fdisk /dev/sdb
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0x5a1d7a13.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon‘t be recoverable.
Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)
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)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-3916, default 3916): +300M
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# fdisk /dev/sdc
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xa5a6acdf.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon‘t be recoverable.
Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)
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)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-3916, default 3916): +400M
Command (m for help): w
安装mdadm包
[[email protected] ~]# mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom/mnt/cdrom/
mount: block device /dev/sr0 iswrite-protected, mounting read-only
[[email protected] ~]# cd /mnt/cdrom/Packages/
[[email protected] Packages]# ls mdadm*
mdadm-3.2.5-4.el6.x86_64.rpm
[[email protected] Packages]# rpm -Uvhmdadm-3.2.5-4.el6.x86_64.rpm
创建RAID1
[[email protected] Packages]# mdadm-Cv /dev/md0 -l1 -n2 /dev/sdc /dev/sdb
mdadm: /dev/sdc appears to bepart of a raid array:
level=raid0 devices=0 ctime=Thu Jan 1 08:00:00 1970
mdadm: partition table existson /dev/sdc but will be lost or
meaningless after creating array
mdadm: Note: this array hasmetadata at the start and
may not be suitable as a boot device. If you plan to
store ‘/boot‘ on this device please ensurethat
your boot-loader understands md/v1.xmetadata, or use
--metadata=0.90
mdadm: /dev/sdb appears to bepart of a raid array:
level=raid0 devices=0 ctime=Thu Jan 1 08:00:00 1970
mdadm: partition table existson /dev/sdb but will be lost or
meaningless after creating array
mdadm: size set to 31440768K
Continue creating array? y
mdadm: Defaulting to version1.2 metadata
mdadm: array /dev/md0 started.
[[email protected] Packages]# ls/dev/md0
/dev/md0
查看
[[email protected] Packages]# mdadm--detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Aug 14 16:02:21 2014
Raid Level : raid1
Array Size : 31440768 (29.98 GiB 32.20 GB)
Used Dev Size : 31440768 (29.98 GiB 32.20 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Aug 14 16:04:40 2014
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Resync Status : 89% complete
Name : host129.localdomain:0 (local to host host129.localdomain)
UUID : 10fa6c5d:1afaebc6:85f51847:e1f0b2ed
Events : 14
Number Major Minor RaidDevice State
0 8 32 0 active sync /dev/sdc
1 8 16 1 active sync /dev/sdb
格式化
[[email protected] Packages]# mkfs.ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripewidth=0 blocks
1966080 inodes, 7860192 blocks
393009 blocks (5.00%) reservedfor the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
240 block groups
32768 blocks per group, 32768fragments per group
8192 inodes per group
Superblock backups stored onblocks:
32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,
4096000
正在写入inode表: 完成
Creating journal (32768blocks): 完成
Writing superblocks andfilesystem accounting information: 完成
This filesystem will beautomatically checked every 39 mounts or
180 days, whichever comesfirst. Use tune2fs -c or -i to override.
创建一个系统文件
[[email protected] ~]# mkdir /qq
[[email protected] ~]# mount /dev/md0/qq/
[[email protected] ~]# ll /qq
[[email protected] ~]# vi /etc/txt
查看 和写入到配置=文件
[[email protected] ~]# mdadm -Ds
ARRAY/dev/md0 metadata=1.2 name=host129.localdomain:0UUID=10fa6c5d:1afaebc6:85f51847:e1f0b2ed
[[email protected] ~]# mdadm -Ds >>/etc/mdadm.conf
重启PC机 进行验证
[[email protected]~]# reboot
[[email protected] ~]# mount
[[email protected] ~]# cat /proc/mdstat
删除硬盘2 进行 模拟故障
查看日志
[[email protected] ~]# dmesg
重组RAID1 模拟恢复,还是30GB的硬盘,添加新的磁盘文件将30GBC.VMDK
fdisk-l /dev/sdb
加入新的
[[email protected] ~]# mdadm /dev/md0 -a /dev/sdc
mdadm:added /dev/sdc
[[email protected] ~]# cat /proc/mdstat
在日志中可以查看到重建的过程
Linux 磁盘管理~~~~RAID1