Skip to content

Instantly share code, notes, and snippets.

@kiyotune
Created August 7, 2020 06:25
Show Gist options
  • Save kiyotune/818be738c3867eb5bd744b70b1e0ba57 to your computer and use it in GitHub Desktop.
Save kiyotune/818be738c3867eb5bd744b70b1e0ba57 to your computer and use it in GitHub Desktop.

RAID Volume Setting Manual

2020/08/05 K.Tsunezumi

How to activate Software RAID

Preparing the devices for the RAID

Initialize the devices you want to RAID and set the RAID flag to ON. The sample code is for the device /dev/sdb.

# parted /dev/sdb
(parted) print                                                            
Error: /dev/sdb: unrecognised disk label
Model: ATA TOSHIBA MD05ACA8 (scsi)                                        
Disk /dev/sdb: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: unknown
Disk Flags: 

(parted) mklabel gpt
(parted) unit GB
(parted) mkpart primary xfs 0 8002
(parted) set 1 raid on

(parted) print
Model: ATA TOSHIBA MD05ACA8 (scsi)
Disk /dev/sdb: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      0.00GB  8002GB  8002GB               primary  raid
(parted) quit

Creating and servicing a RAID array

To build a new RAID0 (mirror) with 4 new disks from device sdb to sde.

# mdadm --create /dev/md0 --level=0 --raid-devices=4 /dev/sd[bcde]1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

RAID Volume formatting

ext4 has a bug in dealing with areas over 10TB, so initialize it with xfs.

# mkfs -t xfs /dev/md0
meta-data=/dev/md0               isize=512    agcount=32, agsize=244184192 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=7813894144, imaxpct=5
         =                       sunit=128    swidth=512 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Check the UUID

# blkid /dev/md0
/dev/md0: UUID="0aaf1f16-c156-4c09-a481-43f9f630c526" TYPE="xfs"

Auto mount setting

Add a configuration of auto-mounting to fstab with the UUID specified by blkid. Create a mount point in advance. In the example, create an empty folder named /DATA (permission 777).

# vi /etc/fstab
/dev/disk/by-uuid/0aaf1f16-c156-4c09-a481-43f9f630c526 /DATA xfs nosuid,nodev,nofail,x-gvfs-show 0 0

How to deactivate Software RAID

  1. Unmounting RAID Volumes
  2. Disabling the fstab mount setting
  3. Shut down the RAID array
  4. Check (stop) RAID information
  5. Set the RAID flag on the disk to OFF【IMPORTANT】
# umount /DATA
# vi /etc/fstab
	delete description about auto-mount
# mdadm --stop /dev/md127
# cat /proc/mdstat
Personalities : [raid0] 
unused devices: <none>
# mdadm --misc --zero-superblock /dev/sda1 /dev/sdc1 /dev/sdd1

If you forget to turn off the RAID flag and try to format the disk as a normal disk, an error will occur during the formatting process and you will not be able to use the disk again. If you format it normally and it is impossible to turn off the RAID flag and complete the formatting process, you can use it by writing all areas 0 as follows (it will take a long time and put a lot of strain on the disk).

# dd if=/dev/zero of=/dev/sdb

How to reassemble RAID array

If the RAID array does not start automatically, such as when you move a disk to another machine, enable the services as follows

Manually start the RAID array

# mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 ...

Add new RAID array information to the configuration file

mdadm --scan --detail >> /etc/mdadm.conf

Check the contents of the configuration file and comment out the old ones.

Resetting the mount information in fstab

(previously mentioned)

== EOF ==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment