參考網頁:
Creating Software RAID0 (Stripe) on 'Two Devices' Using 'mdadm' Tool in Linux - Part 2
Debian RAID-0 (等量模式) | JR 的網路日誌
OS:Debian Linux 5.8.0
HDD:
10G*1 Debian Linux System
20G *4 (/dev/sdb,sdc,sdd,sde)
1. 安裝 mdadm 套件
# apt-get install mdadm
2. 查看目前磁碟狀態
# fdisk -l | grep '^Disk /dev'
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdd: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk /dev/sde: 20 GiB, 21474836480 bytes, 41943040 sectors
3. 建立磁碟分割區
# fdisk /dev/sdb
不一定要更改成 fd
重複上面的動作,完成所有的磁碟
# fdisk /dev/sdc
# fdisk /dev/sdd
# fdisk /dev/sde
4. 建立 /dev/md0 磁碟陣列分割區
# mdadm --create /dev/md0 --level=stripe --raid-devices=4 /dev/sd[b-e]1
或
# mdadm -C /dev/md0 -l raid0 -n 4 /dev/sd[b-e]1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
mdadm -C /dev/md0 -a yes -l 1 -n 2 /dev/sdb1 /dev/sdb2
5. 查看建置結果
# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sde1[3] sdd1[2] sdc1[1] sdb1[0]
83816448 blocks super 1.2 512k chunks
unused devices: <none>
/dev/sdb1:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : 7d559d15:91cc1bec:54dcd941:8f10e5ff
Name : debian:0 (local to host debian)
Creation Time : Mon Jun 27 19:09:38 2016
Raid Level : raid0
Raid Devices : 4
Avail Dev Size : 41908224 (19.98 GiB 21.46 GB)
Data Offset : 32768 sectors
Super Offset : 8 sectors
Unused Space : before=32680 sectors, after=0 sectors
State : clean
Device UUID : b77c8a2f:aad8c146:6da755a5:6f3db3e3
Update Time : Mon Jun 27 19:09:38 2016
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : 37037bb0 - correct
Events : 0
Chunk Size : 512K
Device Role : Active device 0
Array State : AAAA ('A' == active, '.' == missing, 'R' == replacing)
# fdisk -l | grep /dev/md0
Disk /dev/md0: 80 GiB, 85828042752 bytes, 167632896 sectors
# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Jun 27 19:09:38 2016
Raid Level : raid0
Array Size : 83816448 (79.93 GiB 85.83 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon Jun 27 19:09:38 2016
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : debian:0 (local to host debian)
UUID : 7d559d15:91cc1bec:54dcd941:8f10e5ff
Events : 0
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 3 active sync /dev/sde1
6. 進行 RAID 磁碟分割
# fdisk /dev/md0
7. 格式化分割區
mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/xxx
# mkfs.ext4 /dev/md0p1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 20953600 4k blocks and 5242880 inodes
Filesystem UUID: a89c1629-75b4-4660-b5cd-cbcf72595fe8
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
8. 建立掛載目錄並掛載
# mkdir /mnt/raid0
# mount /dev/md0p1 /mnt/raid0
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.3G 1.1G 7.8G 12% /
udev 10M 0 10M 0% /dev
tmpfs 400M 5.9M 394M 2% /run
tmpfs 999M 0 999M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 999M 0 999M 0% /sys/fs/cgroup
/dev/md0p1 79G 56M 75G 1% /mnt/raid0
9. 查看硬碟的 UUID
# blkid | grep /dev/md0p1
/dev/md0p1: UUID="b57de29c-9210-48bc-9ba6-1f5224feb42f" TYPE="ext4"
10. 修改 /etc/fstab
# vim /etc/fstab
加入下面一行
UUID=b57de29c-9210-48bc-9ba6-1f5224feb42f /mnt/raid0 ext4 errors=remount-ro 0 0
11. 編輯 /etc/mdadm/mdadm.conf 設定檔
# mdadm -E -s -v >> /etc/mdadm/mdadm.conf
或
# mdadm --detail --scan --verbose >> /etc/mdadm/mdadm.conf
# cat /etc/mdadm/mdadm.conf
ARRAY /dev/md/0 level=raid0 metadata=1.2 num-devices=4 UUID=7d559d15:91cc1bec:54dcd941:8f10e5ff name=debian:0
devices=/dev/sde1,/dev/sdd1,/dev/sdc1,/dev/sdb1
12. 磁碟分割資訊
# fdisk -l | grep /dev/sd
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sdb1 2048 41943039 41940992 20G 83 Linux
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sda1 * 2048 20013055 20011008 9.6G 83 Linux
/dev/sda2 20015102 20969471 954370 466M 5 Extended
/dev/sda5 20015104 20969471 954368 466M 82 Linux swap / Solaris
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sdc1 2048 41943039 41940992 20G 83 Linux
Disk /dev/sdd: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sdd1 2048 41943039 41940992 20G 83 Linux
Disk /dev/sde: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sde1 2048 41943039 41940992 20G 83 Linux
13. 檢查是否有正確掛載
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.3G 1.1G 7.8G 12% /
udev 10M 0 10M 0% /dev
tmpfs 400M 5.9M 394M 2% /run
tmpfs 999M 0 999M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 999M 0 999M 0% /sys/fs/cgroup
/dev/md0p1 79G 56M 75G 1% /mnt/raid0
沒有留言:
張貼留言