openSUSE Leap 16

Configure RAID 12026/01/12

 

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

[1] In this example, we will add new disks [sdb] and [sdc] to configure RAID 1.
Create partitions on the two additional disks and set the RAID flag.
dlp:~ #
parted --script /dev/sdb "mklabel gpt"

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

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

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

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

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

dlp:~ #
zypper -n install mdadm
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

dlp:~ #
cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 vdc1[1] vdb1[0]
      167638016 blocks super 1.2 [2/2] [UU]
      [=>...................]  resync =  8.4% (14097152/167638016) finish=12.9min speed=197006K/sec
      bitmap: 2/2 pages [8KB], 65536KB chunk

unused devices: <none>

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

dlp:~ #
cat /proc/mdstat

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

unused devices: <none>
[3] To use RAID device, Ceate any filesystem and mount it as usual.
# for example, format with btrfs and mount it on /mnt

dlp:~ #
mkfs.btrfs /dev/md0

btrfs-progs v6.14
See https://btrfs.readthedocs.io for more information.

Performing full device TRIM /dev/md0 (159.87GiB) ...
NOTE: several default settings have changed in version 5.15, please make sure
      this does not affect your deployments:
      - DUP for metadata (-m dup)
      - enabled no-holes (-O no-holes)
      - enabled free-space-tree (-R free-space-tree)

Label:              (null)
UUID:               94428a4f-0045-4588-a8a0-2b398f3b43a3
Node size:          16384
Sector size:        4096        (CPU page size: 4096)
Filesystem size:    159.87GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP               1.00GiB
  System:           DUP               8.00MiB
SSD detected:       no
Zoned device:       no
Features:           extref, skinny-metadata, no-holes, free-space-tree
Checksum:           crc32c
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1   159.87GiB  /dev/md0

dlp:~ #
mount /dev/md0 /mnt

dlp:~ #
df -hT /mnt

Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/md0       btrfs  160G  5.8M  158G   1% /mnt

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

dlp:~ #
blkid | grep md

/dev/md0: UUID="94428a4f-0045-4588-a8a0-2b398f3b43a3" UUID_SUB="6af28951-43a7-4ac1-a5ca-320a5144b130" BLOCK_SIZE="4096" TYPE="btrfs"

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

.....
.....
UUID=579cbec6-00f9-420a-b025-5dc2c4e15275  swap                    swap   defaults                      0  0
UUID=a4cf22d2-1ad1-40de-8b5a-fa9cc08dae4a  /.snapshots             btrfs  subvol=/@/.snapshots          0  0
UUID=94428a4f-0045-4588-a8a0-2b398f3b43a3  /mnt                    btrfs  defaults                      0  0

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

dlp:~ #
df -hT /mnt

Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/md127     btrfs  160G  5.8M  158G   1% /mnt
[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

dlp:~ #
cat /proc/mdstat

Personalities : [raid1]
md0 : active (auto-read-only) raid1 sdb1[0]
      167638016 blocks super 1.2 [2/1] [U_]
      bitmap: 0/2 pages [0KB], 65536KB chunk

unused devices: <none>

# after swapping new disk, re-configure like follows

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

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

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      167638016 blocks super 1.2 [2/2] [UU]
      [=>...................]  resync =  6.3% (10603904/167638016) finish=12.6min speed=206316K/sec
      bitmap: 2/2 pages [8KB], 65536KB chunk

unused devices: <none>
Matched Content