title: Ubuntu組建陣列
date: 2022/12/26
tags: Linux
背景
迫于準備組建一臺家庭服務器狼纬,且服務器上需搭建陣列存放重要資料
所以先在 VMware 中組建 Raid 1 練練手。
VMware 環(huán)境
創(chuàng)建虛擬機骂际,安裝
Ubuntu 22.04.1 LTS
系統(tǒng)關機
-
給虛擬機添加硬盤
進入虛擬機
-
查看磁盤是否已添加疗琉,可以看到兩個 5G 的 sdb/sdc
root@abc:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 1.8G 0 part /boot └─sda3 8:3 0 18.2G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 10G 0 lvm / sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part sdc 8:32 0 5G 0 disk └─sdc1 8:33 0 5G 0 part sr0 11:0 1 1.4G 0 rom
root@abc:~# fdisk -l Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual S 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: dos Disk identifier: 0x7ed5d1e4 Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 10485759 10483712 5G 83 Linux Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual S 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: dos Disk identifier: 0x4f29486a Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 10485759 10483712 5G 83 Linux
-
格式化磁盤
root@abc:~# fdisk /dev/sdb n(新建分區(qū)) p(主分區(qū)) 回車默認 w(保存) root@abc:~# fdisk /dev/sdc n(新建分區(qū)) p(主分區(qū)) 回車默認 w(保存)
-
創(chuàng)建陣列
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
命令解釋:
-
--create
:創(chuàng)建陣列 -
--verbose
:輸入詳細信息 -
/dev/md0
:創(chuàng)建后的陣列的設備名 -
level
:要創(chuàng)建的 RAID 的級別,這里使用模式 1 -
raid-devices
:指定 RAID 副本的磁盤數(shù)歉铝。在這里指定了 2 盈简,意思是平時有兩個磁盤在工作。- 如果以后添加了第三塊硬盤太示,那么第三塊硬盤將作為備用磁盤柠贤。當工作中的兩塊磁盤有一塊壞了,第三塊將立刻啟動类缤,并將完好的一塊的內(nèi)容復制到新的盤中臼勉。
mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 mdadm: size set to 5236736 Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started.
-
-
查看陣列是否創(chuàng)建成功
由于上面命令創(chuàng)建后的陣列設備名為:
/dev/md0
,所以直接使用fdisk -l
命令查看即可餐弱。root@abc:~# fdisk -l Disk /dev/md0: 4.99 GiB, 5362417664 bytes, 10473472 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 byte
-
創(chuàng)建文件系統(tǒng)并掛載
-
創(chuàng)建文件系統(tǒng)
root@abc:~# mkfs.ext4 -F /dev/md0 mke2fs 1.46.5 (30-Dec-2021) Creating filesystem with 1309184 4k blocks and 327680 inodes Filesystem UUID: ced9057b-01c8-4f66-939b-c8aa22ebd4ea Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
-
掛載存儲到 /data 目錄
mount /dev/md0 /data
-
查看是否掛載成功
root@abc:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/md0 4.9G 24K 4.6G 1% /data
-
保存陣列布局
完成以上步驟后宴霸,將陣列保存下來囱晴,在下次啟動的時候自動加載,
因此需要將陣列信息保存到 /etc/mdadm/mdadm.conf
文件中瓢谢』矗可以通過以下命令來自動掃描活動陣列并追加文件:
mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
更新初始RAM文件系統(tǒng)(initramfs)
update-initramfs -u
保存掛載信息,修改 /etc/fstab
文件
/dev/md0 /data ext4 defaults 0 0
參考文檔:
http://www.reibang.com/p/3e6d5da2db81