关于linux下raid的设备文件和格式化

概述

今天给dell t20装了zstack,没错zstack镜像底层其实就是centos,服务器里面有四块硬盘,一块300g的我是做系统盘的,三块1T的硬盘我是打算用来存数据的,还可以做dell r410的存储,因为dell t20是只有软raid的,我给这三块硬盘做的是raid0,做完raid之后安装完系统之后,我才发现我没有给这个raid格式化,我百度了一下找到了查看raid的方式,下面是操作

操作

首先我的dev目录是下面这样子的

1
2
3
4
5
6
7
8
9
[root@MiWiFi-R1CM-srv ~]# ls /dev
autofs cpu fd kvm mei oldmem rfkill sdc3 snd tty11 tty19 tty26 tty33 tty40 tty48 tty55 tty62 ttyS3 usbmon4 vcsa3 zstack
block cpu_dma_latency full log mem port rtc sdd stderr tty12 tty2 tty27 tty34 tty41 tty49 tty56 tty63 uhid vcs vfio
bsg crash fuse loop-control mqueue ppp rtc0 sg0 stdin tty13 tty20 tty28 tty35 tty42 tty5 tty57 tty7 uinput vcs1 vga_arbiter
btrfs-control disk hpet mapper net ptmx sda sg1 stdout tty14 tty21 tty29 tty36 tty43 tty50 tty58 tty8 urandom vcs2 vhost-net
bus dm-0 hugepages mcelog network_latency ptp0 sdb sg2 tty tty15 tty22 tty3 tty37 tty44 tty51 tty59 tty9 usbmon0 vcs3 watchdog
char dm-1 initctl md network_throughput pts sdc sg3 tty0 tty16 tty23 tty30 tty38 tty45 tty52 tty6 ttyS0 usbmon1 vcsa watchdog0
console dri input md126 null random sdc1 shm tty1 tty17 tty24 tty31 tty39 tty46 tty53 tty60 ttyS1 usbmon2 vcsa1 watchdog1
core fb0 kmsg md127 nvram raw sdc2 snapshot tty10 tty18 tty25 tty32 tty4 tty47 tty54 tty61 ttyS2 usbmon3 vcsa2 zero

重点是下面几个 sda,sdb,sdc,sdc1,sdc2,sdc3,sdd
很明显sdc是系统盘,sda和sdb,sdd是没有分区的,所以他们三个是组了raid,然后我们看一下raid信息
cat /proc/mdstat

1
2
3
4
5
6
7
8
9
[root@MiWiFi-R1CM-srv disk]#  cat /proc/mdstat
Personalities : [raid0]
md126 : active raid0 sda[2] sdb[1] sdd[0]
2930245632 blocks super external:/md127/0 32k chunks

md127 : inactive sda[2](S) sdb[1](S) sdd[0](S)
9459 blocks super external:imsm

unused devices: <none>

可以看到设备文件是md126和md127,所以我们只要格式化md126就可以了,但是因为是大于2T的,所以我们要把他格式化成gpt分区表才可以,所以不能使用fdisk格式化,要使用gdisk,具体流程如下

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
[root@MiWiFi-R1CM-srv disk]# gdisk /dev/md126
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-5860491230, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-5860491230, default = 5860491230) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap
a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated
a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot
af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline
af03 Apple label af04 AppleTV recovery af05 Apple Core Storage
be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z
bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var
bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1
bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4
bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service
ed00 Sony system partitio ef00 EFI System ef01 MBR partition scheme
ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved
fc00 VMWare kcore crash p fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/md126.
The operation has completed successfully.

之后我们要做的就是格式化分区
mkfs.ext4 /dev/md126p1
格式化成ext4分区之后挂载
因为是共享存储,所以我就在根目录新建一个文件夹
mkdir /data
挂载
sudo mount /dev/md126p1 /data/
之后查看挂载的情况

1
2
3
4
5
6
7
8
9
10
11
12
[root@MiWiFi-R1CM-srv data]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/zstack-root 290G 5.9G 284G 3% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 4.0K 7.8G 1% /dev/shm
tmpfs 7.8G 8.7M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sdc2 477M 99M 349M 23% /boot
/dev/sdc1 200M 9.5M 191M 5% /boot/efi
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/1000
/dev/md126p1 2.7T 89M 2.6T 1% /data

没错,有2.7个T

欢迎关注Bboysoul的博客www.bboy.app
Have Fun

欢迎关注我的其它发布渠道