背景
一直想组一个raid0来做个人云盘的基础,现在正好2块希捷2T到手,所以开始动手。
安装
在机箱上安装好,然后开机。
首先看看是否安装成功:1
2
3
4
5
6
7$ sudo ll /dev | grep sd
brw-rw---- 1 root disk 8, 0 Oct 30 18:27 sda
brw-rw---- 1 root disk 8, 16 Oct 30 18:27 sdb
brw-rw---- 1 root disk 8, 32 Oct 30 18:27 sdc
brw-rw---- 1 root disk 8, 33 Oct 30 18:27 sdc1
brw-rw---- 1 root disk 8, 34 Oct 30 18:27 sdc2
brw-rw---- 1 root disk 8, 35 Oct 30 18:27 sdc3
已经分区了的是系统所在的SSD,可以看到新硬盘被识别为了sda和sdb。然后看一下硬盘信息:1
2
3
4
5
6
7
8
9
10
11$ sudo fdisk -l /dev/sda
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
没有问题,可用容量2个都是1.8TB。
配置
分区
给硬盘分一个区,全部用上。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.27.1).
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.
Created a new DOS disklabel with disk identifier 0x1e8a796d.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-3907029167, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-3907029167, default 3907029167):
Created a new partition 1 of type 'Linux' and of size 1.8 TiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
接下来格式化一下,1
2
3
4$ sudo mkfs -t ntfs -f /dev/sdb1
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
sda就照葫芦画瓢,这样前缀为sd的硬盘应该会增加sda1和sdb1,1
2
3
4
5
6
7
8
9$ ll /dev | grep sd
brw-rw---- 1 root disk 8, 0 Oct 30 21:13 sda
brw-rw---- 1 root disk 8, 1 Oct 30 21:13 sda1
brw-rw---- 1 root disk 8, 16 Oct 30 21:15 sdb
brw-rw---- 1 root disk 8, 17 Oct 30 21:23 sdb1
brw-rw---- 1 root disk 8, 32 Oct 30 21:02 sdc
brw-rw---- 1 root disk 8, 33 Oct 30 21:02 sdc1
brw-rw---- 1 root disk 8, 34 Oct 30 21:02 sdc2
brw-rw---- 1 root disk 8, 35 Oct 30 21:02 sdc3
没有问题,然后挂载这2个硬盘
挂载
1 | $ sudo mkdir /mnt/hdd1 #挂sda1 |
检查一下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23$ sudo fdisk -lu
...
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x1873f8e8
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 3907029167 3907027120 1.8T 83 Linux
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x1e8a796d
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 3907029167 3907027120 1.8T 83 Linux
...
没有问题,umount这2个。 接下开始做RAID0:
安装必要软件
1 | $ sudo apt install mdadm |
生成RAID0
1 | $ sudo mdadm -C /dev/md0 --level=0 --raid-devices=2 /dev/sda1 /dev/sdb1 |
这里先用2.5T来做存储用,其他的先暂时留着。
因为容量会大于2T,所以不能使用fdisk了,要用parted,1
2
3
4
5
6
7
8
9
10
11
12
13
14$ sudo parted /dev/md0
GNU Parted 3.2
Using /dev/md0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
(parted) p
Model: Linux Software RAID Array (md)
Disk /dev/md0: 4001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
这样就可以开始了
分区给普通的存储盘
1 | (parted) mkpart |
分区给Mac备份用
就是用来做time machine1
2
3
4
5
6
7(parted) mkpart
Partition name? \[\]? apple
File system type? \[ext2\]? ext4
Start? 2501G
End? 3000G
(parted) quit
Information: You may need to update /etc/fstab.
格式化
先做这2个分区,然后看看设备情况,1
2
3
4$ sudo ll /dev/md*
brw-rw---- 1 root disk 9, 0 Oct 30 22:31 /dev/md0
brw-rw---- 1 root disk 259, 2 Oct 30 22:31 /dev/md0p1
brw-rw---- 1 root disk 259, 3 Oct 30 22:31 /dev/md0p2
开始格式化1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27$ sudo mkfs -t ext4 /dev/md0p1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 610351360 4k blocks and 152592384 inodes
Filesystem UUID: fef49738-6977-493f-ae1b-105d1801d970
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
$ sudo mkfs -t ext4 /dev/md0p2
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 121826304 4k blocks and 30457856 inodes
Filesystem UUID: 1674157f-bc29-4469-aa1c-3e40b5b29008
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
记录此时的UUID,准备添加到/etc/fstab里面,
建立挂载点
1 | $ sudo mkdir /mnt/storage |
添加到/etc/fstab
1 | UUID=fef49738-6977-493f-ae1b-105d1801d970 /mnt/storage ext4 defaults 0 0 |
挂载
1 | $ sudo mount -a |
检查
1 | $ df -h /dev/md0p* |
没有问题,操作一下文件看看1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 建文件夹
sudo mkdir test && cd test
写入文件,用rsync获取速度信息
sudo rsync -ah --progress /home/orzorc/Downloads/WebStorm.dmg .
sending incremental file list
WebStorm.dmg
207.63M 100% 445.90MB/s 0:00:00 (xfr#1, to-chk=0/1)
读取文件
sudo rsync -ah --progress WebStorm.dmg /home/orzorc/Documents/
sending incremental file list
WebStorm.dmg
207.63M 100% 444.90MB/s 0:00:00 (xfr#1, to-chk=0/1)
删除文件
sudo rm WebStorm.dmg
删除文件夹
cd .. && sudo rm -r test
上面的读写速度可能有点问题,或者文件太小,没有什么参考价值,因为暂时没有什么大文件可以操作。