首页 > 代码库 > RAID0创建

RAID0创建

[root@ZQ ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x1a13ee0f.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x1a13ee0f

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x1a13ee0f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-20971519, default 2099200): 
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



开始创建raid0
[root@ZQ ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  4 05:47 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  4 05:47 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Jun  4 05:47 /dev/sdb2
[root@ZQ ~]# ll /dev/sda*
brw-rw----. 1 root disk 8, 0 Jun  4 05:35 /dev/sda
brw-rw----. 1 root disk 8, 1 Jun  4 05:35 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun  4 05:35 /dev/sda2
brw-rw----. 1 root disk 8, 3 Jun  4 05:35 /dev/sda3
[root@ZQ ~]# mdadm -C -v /dev/md0 -l 0 -n 2 /dev/sdb1 /dev/sdb2  #-C --creat创建一个新阵列 -v 显示详细信息(-verbose) -l --level设定磁盘阵列的级别  -n --raid device 指定阵列成员的数量
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@ZQ ~]# mdadm -Ds
ARRAY /dev/md0 metadata=http://www.mamicode.com/1.2 name=ZQ:0 UUID=00d9284f:6fd6b3b0:afc571c6:c5441608



[root@ZQ ~]# mdadm -D /dev/md0      #查看具体信息
/dev/md0:
        Version : 1.2
  Creation Time : Sun Jun  4 05:51:54 2017
     Raid Level : raid0
     Array Size : 2095104 (2046.00 MiB 2145.39 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Sun Jun  4 05:51:54 2017
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

     Chunk Size : 512K

           Name : ZQ:0  (local to host ZQ)
           UUID : 00d9284f:6fd6b3b0:afc571c6:c5441608
         Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2


需要自己手动生成配置文件
[root@ZQ ~]# mdadm -Ds > /etc/mdadm.conf
[root@ZQ ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=http://www.mamicode.com/1.2 name=ZQ:0 UUID=00d9284f:6fd6b3b0:afc571c6:c5441608
[root@ZQ ~]# 


使用raid0,先分区
[root@ZQ ~]# fdisk /dev/md0
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x60e13d32.

Command (m for help): p

Disk /dev/md0: 2145 MB, 2145386496 bytes, 4190208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0x60e13d32

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4190207, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4190207, default 4190207): 
Using default value 4190207
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/md0: 2145 MB, 2145386496 bytes, 4190208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0x60e13d32

    Device Boot      Start         End      Blocks   Id  System
/dev/md0p1            2048     4190207     2094080   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ZQ ~]# ll /dev/md0
brw-rw----. 1 root disk 9, 0 Jun  4 06:03 /dev/md0
[root@ZQ ~]# ll /dev/md0*
brw-rw----. 1 root disk   9, 0 Jun  4 06:03 /dev/md0
brw-rw----. 1 root disk 259, 1 Jun  4 06:03 /dev/md0p1


[root@ZQ ~]# mkfs.ext4 /dev/md0p1     #格式化,生成文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
131072 inodes, 523520 blocks
26176 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@ZQ ~]# mkdir /raid0
[root@ZQ ~]# mount /dev/md0p1 /raid0/
[root@ZQ ~]# ls !$
ls /raid0/
lost+found
[root@ZQ ~]# cp /etc/passwd /raid0/
[root@ZQ ~]# ls !$
ls /raid0/
lost+found  passwd


[root@ZQ ~]# mkdir /raid0
[root@ZQ ~]# mount /dev/md0p1 /raid0/
[root@ZQ ~]# ls !$
ls /raid0/
lost+found
[root@ZQ ~]# cp /etc/passwd /raid0/
[root@ZQ ~]# ls !$
ls /raid0/
lost+found  passwd
[root@ZQ ~]# vim /etc/fstab 
[root@ZQ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        15G  3.6G   12G  24% /
devtmpfs        474M     0  474M   0% /dev
tmpfs           489M  156K  489M   1% /dev/shm
tmpfs           489M  7.0M  482M   2% /run
tmpfs           489M     0  489M   0% /sys/fs/cgroup
/dev/sda1       197M  131M   67M  67% /boot
tmpfs            98M  8.0K   98M   1% /run/user/1000
/dev/sr0        4.1G  4.1G     0 100% /run/media/zq/CentOS 7 x86_64
tmpfs            98M     0   98M   0% /run/user/0
/dev/md0p1      2.0G  6.1M  1.9G   1% /raid0

 

RAID0创建