Raspberry Pi – RAID 1 with NFS
I decided to give my Raspberry Pi a new life and installed the latest version of Raspbian.
I also ordered two similar usb sticks of the same size to make a raid 1 (mirrored) device with mdadm which I want to export with NFS.
Note that you should be knowing what you are doing since any of these steps might lead to data loss.
# Short session as root sudo -i # Determine where the usb sticks are. fdisk -l # Remove existing partitions and create the new Linux partitions. Combination of the following commands: p, d, n and w fdisk /dev/<usb-device1> fdisk /dev/<usb-device2> # Install adm. When asked about installing it to the root os answer with 'none' since we will keep booting from the sd card. apt-get install mdadm mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/<usb1-partition1> /dev/<usb2-partition1> # Check if everything is ok. mdadm --detail /dev/md0 # Write stuff to the mdadm config mdadm --detail --scan >> /etc/mdadm/mdadm.conf # Create the fs (-m 0 = no reserved blocks) mkfs.ext4 -m 0 /dev/md0 mkdir /mnt/raid mount /dev/md0 /mnt/raid # I copied the directories I wanted to move over to the raid device (/var, /tmp, /opt, /root) # copy var without the symlinks use the same command for the other directories. find /var -depth -type f -o -type d | cpio -pamVd /mnt/raid # Determine the uuid of the raid device to be used in fstab blkid /dev/md0 |
Edit fstab to mount everything from the raid device.
UUID="<your_raid_uuid>" /mnt/raid ext4 defaults,noatime 0 2 /mnt/raid/var /var none defaults,bind 0 0 /mnt/raid/tmp /tmp none defaults,bind 0 0 /mnt/raid/root /root none defaults,bind 0 0 /mnt/raid/home /home none defaults,bind 0 0 /mnt/raid/opt /opt none defaults,bind 0 0 |
Next I installed nfs and created a dir for the nfs shares.
apt-get install nfs-kernel-server # Don't forget to start rpcbind. Otherwise you will have strange problems connecting to your nfs share from other machines. (Connection timed out most probably) service start rpcbind |
mkdir /mnt/raid/share mkdir /export cd /export ln -s /mnt/raid/share |
Edited /etc/exports
/export/share 192.168.1.0/24(rw,sync,no_subtree_check) |
# export everything. Restart nfs to be certain our changes made it. exportfs -r service nfs-kernel-server restart |
Well that’s it for now. I will be testing this to see how it holds up on my Raspberry.
Categories: Linux