Jack Wallen walks you through the process of creating a RAID1 mirror on Ubuntu 19.10, using ZFS.
ZFS is an advanced file system that is capable of managing data that spans across devices. ZFS uses virtual storage pools, called zpools. A zpool can contain numerous directories and can provide redundancy for your data.
That redundancy is crucial in data centers, where you might be storing customer information and more. The last thing you want is a drive containing that data to go bad. How do you avoid that? You could either setup a backup system or employ a standard RAID configuration. However, if you're making use of Linux as the platform used for the processing and storing of that data you could make use of ZFS pools.
I want to show you how to set up a ZFS mirror (RAID1) pool using two external disks. I'll be demonstrating on Ubuntu 19.10, via a VirtualBox virtual machine. I've created two new disks through the VirtualBox GUI to be used for the mirror. To find out how to add a new drive to a VirtualBox VM, read How to add new drives to a VirtualBox virtual machine.
SEE: 10 things companies are keeping in their own data centers (TechRepublic download)
What you'll need
To make this work you'll need the following:
A running instance of Ubuntu (desktop or server) 19.10
Two unformatted drives attached to the machine
A user with sudo privileges
How to create the mirror
We first need to find out the names of our two disks. Do that issue the command:
sudo fdisk -l
You should see your devices listed. In my case they are /dev/sdb and /dev/sdc. With those names, we can now create the mirror. We'll create a mirror named trtest. The command for this is:
sudo zpool create trtest mirror /dev/sdb /dev/sdc
That command should complete fairly quickly. Once it's done, you'll get your terminal back. Let's make sure the mirror was created with the command:
sudo zpool status
You should see that both sdb and sdc are now listed under the pool trtest (Figure A).
The newly created mirror is mounted at /trtest (because that's what we named our pool). If you issue the command ls -l /, you'll see the directory is owned by root (Figure B).
Because the mirror is owned by root, users and applications will not be able to modify or save files within that directory. To fix that, we need to change the permissions. How you do this will depend on what you need the mirror for. For example, if you have a group named data that contains all of the users and apps who need to be able to access that directory. You could change the group ownership and permissions. To change the group to data, issue the command:
sudo chgrp data /trtrest
Next we need to change the group permissions to read, write, and execute. This is done with the command:
sudo chmod g+rwx /trtest
At this point any user or app that belongs to the data group will be able to access the ZFS mirror pool mounted at /trtest.
And that's all there is to creating a RAID1 mirror using ZFS. Enjoy that improved data integrity.
- How to become a database administrator: A cheat sheet (TechRepublic)
- Hiring kit: Database administrator (TechRepublic Premium)
- How to manage ZFS pools in Ubuntu 19.10 (TechRepublic)
- How to use ZFS in Ubuntu 19.10 (TechRepublic)
- How to create a ZFS storage pool on Ubuntu Server 18.04 (TechRepublic)
- How to properly automount a drive in Ubuntu Linux (TechRepublic)
- Netflix: BPF is a new type of software we use to run Linux apps securely in the kernel (ZDNet)
- Best cloud services for small businesses (CNET)
- DevOps: More must-read coverage (TechRepublic on Flipboard)