Ubuntu16.04配置软raid
1.查看磁盘情况
这里推荐两种查看磁盘情况的命令:
# 1.使用fdisk -l查看磁盘
root@local:/home/data# fdisk -l
Disk /dev/loop0: 55.39 MiB, 58073088 bytes, 113424 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 /dev/loop1: 69.9 MiB, 73277440 bytes, 143120 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 /dev/loop2: 31.9 MiB, 32600064 bytes, 63672 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 /dev/sde: 14.57 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM000J-2T
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdc: 14.57 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM000J-2T
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdb: 14.57 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM000J-2T
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 870
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A73AF7A2-5DD9-473C-90BE-4E1A3384F04C
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 3147775 2097152 1G Linux filesystem
/dev/sda3 3147776 1953521663 1950373888 930G Linux filesystem
Disk /dev/sdf: 14.57 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM000J-2T
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 200 GiB, 214748364800 bytes, 419430400 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 /dev/sdd: 14.57 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM000J-2T
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.使用lsblk查看磁盘情况
root@local:/home/data# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55.4M 1 loop /snap/core18/1944
loop1 7:1 0 69.9M 1 loop /snap/lxd/19188
loop2 7:2 0 31.1M 1 loop /snap/snapd/10707
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 930G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 200G 0 lvm /
sdb 8:16 0 14.6T 0 disk
sdc 8:32 0 14.6T 0 disk
sdd 8:48 0 14.6T 0 disk
sde 8:64 0 14.6T 0 disk
sdf 8:80 0 14.6T 0 disk
# 这里就可以看到,lsblk查看的是设备信息,虽然简洁明了,但是查不到例如谁是主分区等信息等等。。。
2.进行磁盘分区
这里在进行磁盘分区的时也推荐两个方法
# 1.首先是最简单明了,所有linux都可用的分区方法 fdisk /dev/sdb
fdisk /dev/sdb
# 输入n创建新的分区
# 输入p创建主分区
# 输入p查看分区设置
# 输入w保存修改
# 这个fdisk如果修改失误了可以随时输入q退出修改不保存
# 但是这个fdisk也有一个非常致命的缺点,就是当磁盘容量大于2TB的时候,分区的大小默认最大值就是2TB,也就是只能给你分区出来一个个2TB的分区,局限性很强
# 2.当磁盘容量很大的时候,这里推荐使用parted进行分区或者Gpart可以根据个人喜好来使用
parted /dev/sdc
# 当你进入分区时,你感到迷茫可以输入一个help,就会告诉你所有的用法
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices,
free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
# 接下来开始分区
root@local:/home/data# parted /dev/sdd
GNU Parted 3.3
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT # 输入这个给分区打个标签
(parted) mkpart primary 0% 100% # 创建主分区,将全部空间都分给主分区
(parted) print # 打印出分区情况
Model: ATA ST16000NM000J-2T (scsi)
Disk /dev/sdd: 16.0TB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 16.0TB 16.0TB primary
(parted) quit # 退出分区
Information: You may need to update /etc/fstab. # 提示你别忘了更新fstab
# 分区完了可以用lsblk检查一下或者fdisk -l
3.创建raid阵列
按照上述方法为所有需要分区的磁盘分区完事儿之后,我们就可以来创建软raid阵列了,这里以创建raid5阵列为例
mdadm --create --verbose /dev/md5 --level=5 --raid-devices=5 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
# --create --verbose /dev/md5------表示创建磁盘名/dev/md5
# --level=5------表示创建raid5阵列。(这里可以等于0表示创建raid0,等于1表示创建raid1)
# --raid-devices=5------表示将这5块分区都加到raid阵列中去
# 等待创建完毕之后需要对磁盘进行格式化,一般采用ext4的文件模式
mkfs.ext4 -F /dev/md5
# 看一下执行情况
root@local:/home/data# mkfs.ext4 -F /dev/md5
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 15625745408 4k blocks and 976609280 inodes
Filesystem UUID: 3cd36c2e-66d5-4e3e-88ae-a372ff4cb62d
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, 644972544, 1934917632,
2560000000, 3855122432, 5804752896, 12800000000
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
root@local:/home/data# echo $?
0
# 最后用echo $?打印上一次命令是否执行成功,0表示成功,1表示失败
# 格式化完毕之后就需要进行挂载了
mkdir -p /mnt/md5
mount /dev/md5 /mnt/md5
df -h
lsblk
4.保存raid
软raid阵列创建完毕之后需要对其进行保存,这样重启机器之后也会自动进行挂载,之前也提示过要更新fstab
mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf
update-initramfs -u
echo '/dev/md5 /mnt/md5 ext4 defaults,nofail,discard 0 0' | tee -a /etc/fstab
可以重启测试一下是否生效了。