Ubuntu 26.04

Configure RAID 12026/06/22

 

Configure RAID 1 to add 2 new Disks on a computer.

[1] This example is based on the environment like follows.
It shows to install new Disks [sdb] and [sdc] on this computer and configure RAID 1.
root@dlp:~#
df -h

Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              3.1G  1.1M  3.1G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   77G  6.9G   66G  10% /
tmpfs                              7.6G     0  7.6G   0% /dev/shm
none                               1.0M     0  1.0M   0% /run/credentials/systemd-journald.service
none                               1.0M     0  1.0M   0% /run/credentials/systemd-resolved.service
tmpfs                              7.6G     0  7.6G   0% /tmp
/dev/vda2                          2.0G   96M  1.7G   6% /boot
none                               1.0M     0  1.0M   0% /run/credentials/systemd-networkd.service
none                               1.0M     0  1.0M   0% /run/credentials/serial-getty@ttyS0.service
none                               1.0M     0  1.0M   0% /run/credentials/getty@tty1.service
tmpfs                              1.6G  8.0K  1.6G   1% /run/user/0
[2] Create a partition on new Disks and set RAID flag.
root@dlp:~#
apt -y install parted
root@dlp:~#
parted --script /dev/sdb "mklabel gpt"

root@dlp:~#
parted --script /dev/sdc "mklabel gpt"

root@dlp:~#
parted --script /dev/sdb "mkpart primary 0% 100%"

root@dlp:~#
parted --script /dev/sdc "mkpart primary 0% 100%"

root@dlp:~#
parted --script /dev/sdb "set 1 raid on"

root@dlp:~#
parted --script /dev/sdc "set 1 raid on"
[3] Configure RAID 1.
# install required tools

root@dlp:~#
apt -y install mdadm
root@dlp:~#
mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1

To optimalize recovery speed, it is recommended to enable write-indent bitmap, do you want to enable it now? [y/N]? y
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
Continue creating array [y/N]? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

# show status

root@dlp:~#
cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 vdc1[1] vdb1[0]
      83817472 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  2.1% (1801344/83817472) finish=6.0min speed=225168K/sec
      bitmap: 1/1 pages [4KB], 65536KB chunk

unused devices: <none>

# status turns like follows if syncing finished
# that's OK to configure RAID 1

root@dlp:~#
cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 vdc1[1] vdb1[0]
      83817472 blocks super 1.2 [2/2] [UU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

unused devices: <none>
[4] If a member Disk in RAID array would be failure, re-configure RAID 1 like follows after swapping new Disk.
# the status is like follows in failure

root@dlp:~#
cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      83817472 blocks super 1.2 [2/1] [U_]
      bitmap: 1/1 pages [4KB], 65536KB chunk

unused devices: <none>

# after swapping new disk, re-configure like follows

root@dlp:~#
mdadm --manage /dev/md0 --add /dev/sdc1

mdadm: added /dev/sdc1
root@dlp:~#
cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      83817472 blocks super 1.2 [2/2] [UU]
      [====>................]  resync = 24.9% (20902592/83817472) finish=7.4min speed=140632K/sec
      bitmap: 1/1 pages [4KB], 65536KB chunk

unused devices: <none>
[5] To use RAID partition, format with a filesystem and mount it on a directory as usual.
# for example, format with ext4 and mount on /mnt

root@dlp:~#
mkfs.ext4 /dev/md0

root@dlp:~#
mount /dev/md0 /mnt

root@dlp:~#
df -hT

Filesystem                        Type   Size  Used Avail Use% Mounted on
tmpfs                             tmpfs  3.1G  1.1M  3.1G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4    77G  6.9G   66G  10% /
tmpfs                             tmpfs  7.6G     0  7.6G   0% /dev/shm
none                              tmpfs  1.0M     0  1.0M   0% /run/credentials/systemd-journald.service
none                              tmpfs  1.0M     0  1.0M   0% /run/credentials/systemd-resolved.service
tmpfs                             tmpfs  7.6G     0  7.6G   0% /tmp
/dev/vda2                         ext4   2.0G   96M  1.7G   6% /boot
none                              tmpfs  1.0M     0  1.0M   0% /run/credentials/systemd-networkd.service
none                              tmpfs  1.0M     0  1.0M   0% /run/credentials/serial-getty@ttyS0.service
none                              tmpfs  1.0M     0  1.0M   0% /run/credentials/getty@tty1.service
tmpfs                             tmpfs  1.6G  8.0K  1.6G   1% /run/user/0
/dev/md0                          ext4    79G  2.1M   75G   1% /mnt

# to set in fstab
# because the name of md*** sometimes changes when hardwares are changed, set it with UUID

root@dlp:~#
blkid | grep md

/dev/md0: UUID="69c55c65-ae4d-4f87-930e-7472cfc01cca" BLOCK_SIZE="4096" TYPE="ext4"

root@dlp:~#
vi /etc/fstab
# set with UUID

/dev/disk/by-id/dm-uuid-LVM-erWnsN0Pa3zr88v013HdtnpuhTNEzusmYQKNhgpZWV85w8vRYJ9V95j6XDZoejBm / ext4 defaults 0 1
# /boot was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/69d717a4-94be-4d65-b2fd-0205c466f245 /boot ext4 defaults 0 1
/swap.img       none    swap    sw      0       0
/dev/disk/by-uuid/69c55c65-ae4d-4f87-930e-7472cfc01cca /mnt  ext4 defaults 0 0

# that's OK, even if the name of md*** are changed, it is mounted normally

root@dlp:~#
df -hT /mnt

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md127     ext4   79G  2.1M   75G   1% /mnt
Matched Content