Recently accidentally found RAID version gameplay, do not often large thousands of NAS. All it takes is a hard drive box and a raspberry PI 4B.

Consider some partners may not know what RAID is, here I briefly explain a wave. The so-called RAID is the meaning of disk array. In human language, multiple independent hard disks are combined to improve file storage reliability or read/write speed. Different combinations have different effects. Common combinations are: RAID0, RAID1……

Since I have a Hitachi 512gb mechanical hard drive that I disassembled from a laptop ten years ago, I decided to put in a 1tb mechanical hard drive and use it as a RAID1.

RAID1 requires that at least two disks are mirror images of each other. When one disk is damaged, the mirror disk can continue to work, which ensures high data security. However, the capacity of the combination is equal to that of the smaller disk. So when you combine the two disks, you end up with 512 gigabytes of capacity.

Ha ha, although some regret, can still meet my current needs:

1. Use the antique 512G hard drive and turn it into treasure 🐶

2. Place notes and data (mainly those synchronized with Resilio) in a safer storage location. After all, I rarely use cloud services, so I expect more reliability from local storage.

The choose and buy

The hard disk

The first is the hard drive. Solid state disk is not considered, unit capacity price is much higher than mechanical disk; And I this is already beggar version play, the meaning of solid state is not big. But the mechanical plate can not be bought casually, I pursue the ultimate cost performance.

Hard disk is mainly divided into 3.5 inches and 2.5 inches two sizes, the former larger volume, easier to do more capacity, and heat dissipation. But I went for 2.5 inches. My first concern was portability — whether the raspberry PI could fit into the mezzanine of my desktop stand.

After selecting the size, the next step is to consider the disk technical specifications. Mechanical hard disks mainly come in SMR and PMR types. The former have higher track density, so they can pack more capacity into the same volume — and manufacturers can charge more for it. But SMRS are more likely to lose data and seem to break more easily than PMR.

The above arguments are based on Internet search and are not guaranteed to be 100% correct

In my own experience, the PMR is pretty solid indeed. The disassembled hard disk mentioned above is actually Hitachi’S PMR hard disk. It is useful now enough to justify the PMR.

I finally chose the Hitachi 1T PMR mechanical hard disk, which costs about 270.

The hard disk box

Hard disk box options are quite many, I mainly consider the appearance and workmanship. After some comparison, I chose a two-disc box from Mywar that costs about 140.

410 bucks, and we have all the hardware we need.

Raid 1 form

After securing the hard disks according to the hard disk box installation guide, you can configure the hard disks. Generally, the box uses two paddles to control the RAID mode, which is usually described in the manual.

In RAID1 mode, two disks are identified as one disk in the system. Use formatting tools to divide partitions according to your needs.

For formatting operations, DiskGenius, a well-known software on Windows, is recommended

The file system

The file system is explained at the end of this article. This time I chose the NTFS file system. Here’s why:

1. The hard disk box is mainly mounted in Ubuntu and can be read and written using NTFS-3G

2. Both Windows and macOS support reading and writing via Samba sharing

3. NTFS is a journaling file system with better long-term stability

Measures for handling disk damage

In RAID1 mode, two hard disks mirror each other. If a hard disk fails, you only need to insert a new hard disk to automatically mirror the file.

Note: new hard drives generally do not need to be formatted or partitioned, automatic mirroring is the most basic function of the hard drive box, if you do not have this function, then do not buy

The capacity of RAID1 disks varies, so the scenarios are as follows:

After the combination of 512 gb and 1 TB, the RAID1 capacity is 512 gb. If the 512 GB hard disk is damaged, insert a new 1 TB hard disk and only 512 GB of capacity will be obtained. The desired capacity should be 1T. I wonder if this is a feature of the hard drive box.

If you want 1tb of space, you must regroup RAID1. In this case, the file must be copied first because it will be lost when reassembled. 🐶

Automatically mount

Host: Raspberry PI 4B, Ubuntu

Plug the hard disk into the raspberry PI USB3.0 port. Run the following command to check whether the system identifies the device:

sudo fdisk -l
Copy the code

/dev/sda1, /dev/sda2, /dev/sda2, /dev/sda2

Disk /dev/sda: 465.74gib, 500061700096 bytes, 976683008 sectors Disk Model: Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 4096 bytes / 33553920 bytes Disklabeltype: dos
Disk identifier: 0x91fa2779

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 845664255 845662208 403.2G  7 HPFS/NTFS/exFAT
/dev/sda2       845664256 976683007 131018752  62.5G  7 HPFS/NTFS/exFAT
Copy the code

On Linux, you can use fstab to mount USB hard drives automatically. First, query the UUID of each partition:

sudo ls -l /dev/disk/by-uuid/*
Copy the code

The results are as follows:

/dev/disk/by-uuid/3AF4808D7F9B2F74 -> .. /.. /sda2 /dev/disk/by-uuid/818C1D55587307F9 -> .. /.. /sda1Copy the code

The partition UUID is fixed when the Raspberry PI is powered off and restarted, so it can be used as a unique identifier for the disk.

Next, edit the fstab configuration:

sudo vi /etc/fstab
Copy the code

Add the following two lines to the end of the file:

/dev/disk/by-uuid/818C1D55587307F9 < mount point > NTFS rw,auto,user,fmask=133,dmask=022,uid=1000,gid=1000 00 /dev/disk/by-uuid/3AF4808D7F9B2F74 < mount point > NTFS rw,auto,user,fmask=133,dmask=022,uid=1000,gid=1000 00Copy the code

Note that < mount point > needs to be modified as needed and is generally a directory on the system. Remember to create the corresponding directory in advance. The above configuration can be used as the default configuration of NTFS, which supports read and write operations on mounted files.

Because the system on raspberry PI uses NTFS-3G by default to mount NTFS, there is no need to install additional NGFS-3G tools. If you are using another Linux distribution, make sure it supports NTFS-3G.

Next, save the /etc/fstab file and restart the raspberry PI! After the startup, you can view the disk mounting status:

ubuntu@ubuntu:~/rpi-docker-config-common/common$ sudo df -l | grep sda
/dev/sda2       65509372   1983836  63525536   4% /home/ubuntu/data/usb/raid1
/dev/sda1      422831100 227325996 195505104  54% /home/ubuntu/data/usb/time-machine
Copy the code

At this point, RAID1 is formed. Raspberry PI is networked, and with a good RAID, the system looks a lot like an NAS.

If something looks like a duck and walks like a duck, it’s a duck.

So, what does this “NAS” do?

It’s a pity that I haven’t experienced white dress or black dress, so I can’t make a functional comparison.

application

resilio sync

I have the habit of taking notes. The tool I use is Typora + Markdown, and the notes are saved locally. To keep my notes safe and usable, I need to have a synchronization tool that automatically syncs them to other devices when I save and edit them on one device. Resilio is such a tool, and I won’t talk about how to deploy it here, because it’s not the focus of this article. In Resilio, different devices can be interpreted as different nodes in the network. There is a central node, and the general Resilio server acts as this node. In my scenario, the raspberry PI is the central node of any network.

There is also a complete file on the central node, which is stored on the RASPberry PI’S SD card before RAID1 is deployed. With RAID, I migrated them directly. Therefore, there is more security.

samba

Before I introduce Samba, let me talk about my current network environment.

The raspberry PI, which used to make a lot of appearances, is actually a router. The host system is Ubuntu, and then runs a full OpenWRT container in the form of Docker. The router will provide a WIFI signal through a Raspberry PI wireless module, which can be connected to computers, phones and other devices.

In addition to running OpenWRT, Docker also runs the resilio server mentioned above, as well as Samba. And every service and every device connected to raspberry PI WIFI is on the same LAN. Therefore, it is completely possible to share the RAID1 directory with Samba.

TimeMachine

Ooh! With Samba, how can you limit yourself to network file sharing? That’s right, TimeMachine. TM can be backed up via Samba. Here’s a set of configurations I’ve put together:

[global] # if you want to use samba to share valid users = ubuntu @ Ubuntu # VFS Objects = fruit streams_xattr fruit:metadata = stream # guest OK = yes [rpi-time-machine] # time-machine fruit:model = MacSamba fruit:posix_rename = yes fruit:veto_appledouble = no fruit:wipe_intentionally_left_blank_rfork = Yes fruit:delete_empty_adfiles = yes fruit:time machine = yes Tm does not dynamically calculate the available space based on this value, And always display the available space as the maximum # so it is still possible to end up full # fruit:time machine Max size = 350G # time-machine configuration end path = /mount/usb/time-machine/time-machine public = yes read only = no writable = yesCopy the code

The specific function of each line is commented. Except for the TM-specific configuration, other configurations are common to normal file sharing. However, I won’t cover how to deploy the Samba service here either.

Once configured, proceed to configure macOS.

Finder

Open Finder, command + k link to samba server:

You need to enter the IP address of the Samba service. Click connect, enter username and password according to the configuration, and then you can see the shared service:

Locate the TM configuration and select the disk that just appeared:

Then TM will automatically back up.

TM adopts incremental backup, with a large amount of data backed up for the first time. The subsequent backup is based on the previous backup and only saves the modified content. Therefore, the backup data is reduced.

The maximum capacity that TM can take up cannot be set in macOS, nor can Samba be configured according to tutorials on the network. Therefore, using TM will eventually consume the remaining capacity of the partition. Therefore, I had to create a separate partition for TM to fundamentally solve this problem.

The file system

Major operating systems have their own file systems. Such as:

  • MacOS: APFS
  • Windows: NTFS
  • Linux: corruption

For every file system, there is an evolution. Such as:

  • The predecessors of APFS (before 2016) are HFS and HFS+;
  • NTFS was developed to replace FAT32;
  • Ext4 is developed from ext2 and ext3

The FAT32 file system mentioned above is a product of ancient times. As it is a 32-bit system supported, it does not support single file storage of more than 4G. Then came exFat, which was an extension of FAT32 and supported 64-bit systems, but also removed the 4G file size limit.

There are many types of file systems. You can consider compatibility and log support when selecting file systems.

compatibility

File system \ Operating system macOS Linux windows
NTFS Software is needed to support writing, deleting, etc. By default, only file contents can be read. However, NTFS files can be read and written using SMB shares
exFAT
ext4 Use DiskGenius to read and write data. Drive letters are not displayed in Explorer
APFS Did not test Did not test

Log supported or not

For file formats that support logging, metadata is stored along with the file, making the data more secure. Mainstream operating systems support log files. ExFat, which is the most compatible, does not support it

When I set up RAID, I chose NTFS mainly for security and good compatibility. If I had a flash drive, I would choose exFAT without hesitation. After all, the Glory Wisdom Screen is exFAT friendly: