Difference between revisions of "RAID"

From Vague Hope Wiki
Jump to: navigation, search
(Created page with "== References == * https://help.ubuntu.com/10.04/serverguide/C/advanced-installation.html * http://warfieldninjas.com/2010/11/ubuntu-software-raid5-and-raid6-with-mdadm/ * http:/...")
 
(Mount)
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== Set up ==
 +
 +
* [[Postfix]]
 +
 +
<pre>
 +
sudo aptitude install mdadm
 +
</pre>
 +
 +
== Create ==
 +
 +
=== Set disc type ===
 +
 +
For each disc:
 +
 +
<pre>
 +
sudo fdisk /dev/sdb
 +
 +
n          ; for a new partition
 +
enter
 +
p          ; for a primary partition
 +
enter
 +
1          ; number of partition
 +
enter    ; accept the default
 +
enter    ; accept the default
 +
t          ; to change the type
 +
fd        ; sets the type to be “Linux raid auto detect” (83h)
 +
w        ; write changes to disk and exit
 +
</pre>
 +
 +
=== GUID type ===
 +
 +
parted /dev/sda
 +
mklabel gpt
 +
mkpart primary 0GB 3001GB
 +
set 1 raid on
 +
 +
https://www.gnu.org/software/parted/manual/html_chapter/parted_7.html
 +
 +
=== Create array ===
 +
 +
RAID 1 with 1 drive:
 +
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing
 +
 +
RAID 6 with 4 drives:
 +
mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
 +
 +
Monitor:
 +
watch cat /proc/mdstat
 +
 +
=== mdadm.conf ===
 +
 +
sudo -i
 +
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
 +
 +
Though the above does not quite work.  Make it look more like this: (remove name or get weird md127 issues)
 +
ARRAY /dev/md0 level=raid6 num-devices=4 metadata=1.2 UUID=659ec2c1:6631ccfd:08dbd99b:5bf050a3
 +
 +
Remember: test by rebooting.
 +
 +
REMEMBER: run `sudo update-initramfs -u` after editing mdadm.conf.
 +
 +
=== Format ===
 +
 +
<pre>
 +
sudo mkfs.ext4 /dev/md0
 +
</pre>
 +
 +
=== Mount ===
 +
 +
Add to `/etc/fstab'.  'nobootwait' is IMPORTANT.
 +
/dev/md0 /media/yama ext4 defaults,errors=remount-ro,nobootwait 0 2
 +
 +
nobootwait has been replace with nofail:
 +
/dev/md0 /media/yama ext4 defaults,errors=remount-ro,nofail,user_xattr 0 2
 +
 +
=== Extra ===
 +
 +
Test email:
 +
sudo mdadm --monitor --scan --test --oneshot
 +
 +
Set the mdadm configuration to send an Email on startup:
 +
sudo vim /etc/default/mdadm
 +
Add the --test parameter to the DAEMON_OPTIONS:
 +
DAEMON_OPTIONS="--syslog --test"
 +
 +
=== Removing ===
 +
 +
lsblk
 +
sudo mdadm --stop /dev/md0
 +
sudo mdadm --zero-superblock /dev/sda1
 +
sudo mdadm --zero-superblock /dev/sdb1
 +
sudo fdisk /dev/sda (and delete part)
 +
sudo fdisk /dev/sdb (and delete part)
 +
lsblk
 +
 +
=== Growing ===
 +
 +
RAID1 to RAID5
 +
<create partition sdc1>
 +
<stop crons that use md0>
 +
umount /dev/md0
 +
mdadm --stop /dev/md0
 +
mdadm --create /dev/md0 --level=5 --raid-devices=2 /dev/sda1 /dev/sdb1
 +
<wait>
 +
mdadm --add /dev/md0 /dev/sdc1
 +
mdadm --grow /dev/md0 --raid-devices=3 --backup-file=/root/grow_md0_3.bak
 +
<wait>
 +
sudo fsck -f /dev/md0
 +
sudo resize2fs /dev/md0
 +
sudo fsck -f /dev/md0
 +
 +
Recovery if needed:
 +
e2fsck -cc /dev/md0
 +
resize2fs /dev/md0
 +
fsck -f /dev/md0
 +
 +
RAID5 to RAID6
 +
<create partition sdd1>
 +
mdadm --add /dev/md0 /dev/sdd1
 +
mdadm --grow /dev/md0 --level=6 --raid-devices=4 --backup-file=/root/grow_md0_4.bak
 +
<wait>
 +
<fsck>
 +
 +
* http://neil.brown.name/blog/20090817000931
 +
* https://raid.wiki.kernel.org/index.php/Growing
 +
* http://ubuntuforums.org/showthread.php?t=1852476
 +
 +
== Fixing ==
 +
 +
mdadm --detail --scan
 +
(fix uuid in /etc/mdadm/mdadm.conf)
 +
sudo update-initramfs -u
 +
 +
* http://ubuntuforums.org/showthread.php?t=1764861
 +
 
== References ==
 
== References ==
 
* https://help.ubuntu.com/10.04/serverguide/C/advanced-installation.html
 
* https://help.ubuntu.com/10.04/serverguide/C/advanced-installation.html
Line 4: Line 139:
 
* http://www.howtogeek.com/51873/how-to-setup-software-raid-for-a-simple-file-server-on-ubuntu/
 
* http://www.howtogeek.com/51873/how-to-setup-software-raid-for-a-simple-file-server-on-ubuntu/
 
* http://www.ainer.org/raid-5-6-install-setup-configuration-guide-for-ubuntu-10-04-lts-lucid-lynx/2
 
* http://www.ainer.org/raid-5-6-install-setup-configuration-guide-for-ubuntu-10-04-lts-lucid-lynx/2
 +
* http://ubuntuforums.org/showthread.php?t=884556

Latest revision as of 09:24, 15 April 2018

Set up

sudo aptitude install mdadm

Create

Set disc type

For each disc:

sudo fdisk /dev/sdb

n          ; for a new partition
enter
p          ; for a primary partition
enter
1          ; number of partition
enter    ; accept the default
enter    ; accept the default
t          ; to change the type
fd        ; sets the type to be “Linux raid auto detect” (83h)
w         ; write changes to disk and exit

GUID type

parted /dev/sda
mklabel gpt
mkpart primary 0GB 3001GB
set 1 raid on

https://www.gnu.org/software/parted/manual/html_chapter/parted_7.html

Create array

RAID 1 with 1 drive:

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing

RAID 6 with 4 drives:

mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

Monitor:

watch cat /proc/mdstat

mdadm.conf

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

Though the above does not quite work. Make it look more like this: (remove name or get weird md127 issues)

ARRAY /dev/md0 level=raid6 num-devices=4 metadata=1.2 UUID=659ec2c1:6631ccfd:08dbd99b:5bf050a3

Remember: test by rebooting.

REMEMBER: run `sudo update-initramfs -u` after editing mdadm.conf.

Format

sudo mkfs.ext4 /dev/md0

Mount

Add to `/etc/fstab'. 'nobootwait' is IMPORTANT.

/dev/md0 /media/yama ext4 defaults,errors=remount-ro,nobootwait 0 2

nobootwait has been replace with nofail:

/dev/md0 /media/yama ext4 defaults,errors=remount-ro,nofail,user_xattr 0 2

Extra

Test email:

sudo mdadm --monitor --scan --test --oneshot

Set the mdadm configuration to send an Email on startup:

sudo vim /etc/default/mdadm

Add the --test parameter to the DAEMON_OPTIONS:

DAEMON_OPTIONS="--syslog --test"

Removing

lsblk
sudo mdadm --stop /dev/md0
sudo mdadm --zero-superblock /dev/sda1
sudo mdadm --zero-superblock /dev/sdb1
sudo fdisk /dev/sda (and delete part)
sudo fdisk /dev/sdb (and delete part)
lsblk

Growing

RAID1 to RAID5

<create partition sdc1>
<stop crons that use md0>
umount /dev/md0
mdadm --stop /dev/md0
mdadm --create /dev/md0 --level=5 --raid-devices=2 /dev/sda1 /dev/sdb1
<wait>
mdadm --add /dev/md0 /dev/sdc1
mdadm --grow /dev/md0 --raid-devices=3 --backup-file=/root/grow_md0_3.bak
<wait>
sudo fsck -f /dev/md0
sudo resize2fs /dev/md0
sudo fsck -f /dev/md0

Recovery if needed:

e2fsck -cc /dev/md0
resize2fs /dev/md0
fsck -f /dev/md0

RAID5 to RAID6

<create partition sdd1>
mdadm --add /dev/md0 /dev/sdd1
mdadm --grow /dev/md0 --level=6 --raid-devices=4 --backup-file=/root/grow_md0_4.bak
<wait>
<fsck>

Fixing

mdadm --detail --scan
(fix uuid in /etc/mdadm/mdadm.conf)
sudo update-initramfs -u

References