Build Your Own In-Home Cloud Storage (Part 1)
Add sharable storage to your home network
Got an old computer collecting dust in the corner? Turn it into a networked storage solution! I have just such a computer, so my weekend project will be to give it a second life as sharable storage for my network, and for my in-home Kubernetes cluster (yes, I’m a true tech geek).
In a previous article, Playing with Kubernetes, I used an old computer to play around with Kubernetes. Since then, I bought a refurbished server rack to put my Kubernetes sandbox on, and my old little computer started collecting dust again. I felt sorry for the little guy, and even though it’s only got a 150-gigabyte hard drive, I figured I’d give it a purpose.
To follow along, you’ll need a computer not more than about five to ten years old, a home network with access to the internet, a computer that can burn ISO images to a DVD, and a blank DVD to burn the image to. You can also use a thumb drive that has at least one gigabyte of space if your old computer can boot from a thumb drive. I have an external DVD burner, so that can be used to burn the image and hook it up to my old computer. The old computer should have a couple of megabytes of RAM, a DVD reader, or the ability to boot off an external DVD/thumb drive. You will also need to be ready to kiss good-bye any data on the old computer as you’re going to be wiping out everything.
It should go without mentioning that you’ll need a monitor and keyboard, at least at first during installation. I stole a monitor and keyboard from my wife’s computer, promising her I’ll put them back when I’m done.
There are a number of NAS Linux distributions out there, but I’m going to install a normal server installation of Ubuntu. It will give me a chance to try out version 20.04, which will be released shortly (as of this writing. I will be installing GlusterFS as a storage solution so that it can be easily expanded and set up for HA and Fail-over. But for this article, I will be focusing on a single node NFS server and mounting on my Mac.
I’m going to start with the prerelease version of Ubuntu 20.04 (it will probably be released by the time you read this). Download the ISO image here. Once you have the image, burn it onto a DVD, put the DVD in the old computer, reboot to the boot menu or BIOS menu, and select the DVD to boot from. You should see a lot of scrolling lines as it prepares to install. It may ask you if you want to use a new installer. I might recommend not to, as I initially had issues with it and it didn’t work with my computer. But the old installer worked fine.
You’ll be asked a bunch of questions, most of which you can take the default answer. But when you get to the storage configuration, you’ll need to partition the OS portion that’s mounted as
/ and the storage section that’s not mounted. So choose Custom Storage Layout.
First, if your main drive is already partitioned, select it, and choose Reformat. Then select it again and select Add GPT Partition. About 15 gigabytes should be sufficient to hold the OS and software so set that to the size. Format it as
ext4 and mount it at
/. Hit Create, and back on your main screen, you should have your new partition listed.
Select your main drive again, and select Add GPT Partition again. Set the size to the size remaining and under format, select Leave Unformatted. Hit Create, and on your main screen, you should still have only the single mount point listed. Your unformatted partition should be listed as partition 3. At the bottom, partition 1 is listed as the boot area and partition is listed as the
/ mount point. You could make several partitions if you wanted to play with distribution and fail-over, but I’m just making the one. Hit Done, and then confirm that you will be overwriting your disk with these partitions.
On the next screen, give your computer a name, and yourself a user name and password. On the next screen, choose to install the OpenSSH server, import your ssh identity from GitHub if you have an account, and select “Allow Password Authentication over SSH.” We’ll need to allow that because sometimes the SSH identity doesn’t copy over correctly with this installer, and we need to use a password to get our keys over to our new computer. If you have no idea what I’m talking about with SSH and keys, you’ll find instructions on GitHub. You’ll need keys on whatever computer you use to talk to this machine.
On the featured software screen, don’t select anything. Our new root partition is big enough to only install the software we need so that the rest can be used for network storage. Now you can binge-watch a few episodes of your favorite streaming series while you wait for the install to complete.
The installer seems to have trouble installing the SSH keys, so you may have to copy them yourself. If you have the command
ssh-copy-id, that should work, and if not you’ll have to use
scp. The keys are text, so you could just cut-and-paste the keys from your
.ssh/id_rsa.pub to the host’s
.ssh/authorized_hosts file. However you do it, having the keys in place so you can connect without entering your password is important, as a lot of applications rely on SSH to communicate between trusted hosts without passwords. I left a note with the Ubuntu people, and, hopefully, they will get the installation of the keys fixed.
Instead of just a plain old NFS server, which would be too easy, I’m going to try out the GlusterFS system. It provides NFSv3, and I should be able to use it as a storage provider for my Kubernetes cluster. It appears to be a full-fledged member of the Ubuntu family so no need to add to sources or import keys. The command
sudo apt-get install glusterfs-server was sufficient to install it.
Some notes on the terminology used by GlusterFS. A key thing to note is, despite its name, it is not actually a file system. A node is a host computer and a trusted pool is a collection of nodes, one of which is the primary. We’re going to make this very simple since we only have one node. Our trusted pool will only have one node, and that one node is the primary. A brick is a unit of storage, so each node can have multiple bricks. Ours will only have one brick, but it should be easy later on to add external drives and make more bricks. You could also add more nodes if you find another computer and add it to the system.
Let’s make a brick! First, find the disk partition that we created in the installation.
ls /dev should list everything. My device is called
sda3 because it’s the third partition of the first disk (disk “a”). We need to format it and mount it. (We could have done that at install time, but I didn’t read ahead far enough.) Here are the commands:
sudo mkfs.xfs /dev/sda3 # format an xfs filesystem
sudo vi /etc/fstab # add: /dev/sda3 /export/sda3 xfs defaults 0 0
sudo mkdir -p /export/sda3 # make the mount directory
sudo mount -a # mount from /etc/fstab
sudo mkdir -p /export/sda3/brick # make a brick!
For whatever reason, installing GlusterFS didn’t start the daemon, so we need to do that with
systemctl start glusterd. Then we can create our volume and start it:
sudo gluster volume gv0 artful:/export/sda3/brick
sudo gluster volume start gv0
sudo gluster volume info
In the above,
artful is the name I gave my computer during installation and
gv0 is the name I’m giving the volume. The last command should print out something like this:
This shows a bit of an issue. The
nfs.disable is on. If you try to turn it on, it tells you that the Gluster NFS server component has been deprecated in favor of NFS Ganesha. I tried turning it on, but my MacOS NFS client didn’t like the NFS v3 that Gluster was providing, so I will have to install NFS Ganesha.
I could have just installed NFS Ganesha from the start, but it had minimal documentation, so I went with Gluster. Plus, an ulterior purpose of this project was to have storage that I could use on my Kubernetes cluster. Now, I guess I’ll have both. Can you tell I’m making this up as I go along? Sometimes, putting together this type of architecture is like putting together a jigsaw puzzle. At some point, you have to resort to just trying every piece until you find the one that fits.
Enough whining, though. Let’s install NFS Ganesha. It turns out it too is a full member of the Ubuntu family, no need to add sources to install it. Just two pieces to install:
sudo apt-get install nfs-ganesha
sudo apt-get install nfs-ganesha-gluster
This gives us the new NFS server and the interface for it to talk to Gluster. Now we can set up a configuration for NFS Ganesha to export the Gluster volume. The main configuration for Ganesha is in
/etc/ganesha/ganesha.conf We’re going to add an
exports directory, create a configuration file, and include it in the
sudo mkdir /etc/ganesha/exports
sudo vi /etc/ganesha/exports/gv0.conf
Then add the following to the
Then add the line
%include /etc/ganesha/exports/gv0.conf to the end of the
/etc/ganesha/ganesha.conf. Now restart Ganesha with
sudo systemctl restart nfs-ganesha.
Back on your Mac, make a directory to mount into:
mkdir gluster in your home directory, and then you can mount the new mount point with
mount -t nfs -o soft,intr,rsize=8192,wsize=8192,timeo=900,proto=tcp,vers=4 <hostname>:/ /Users/<yourname>/gluster where <hostname> is the name of your new NFS server, and <yourname> is your Mac user name.
Now test it out:
cdto the mounted directory and make a file. Back on your NFS server, you can go to the directory you created for GlusterFS, and you should be able to see the new file.
My weekend project is done, just as the weekend comes to an end. And just in time, too — I have to put my wife’s monitor back so she can work tomorrow. In my next article, I’ll be adding this new storage solution to the Kubernetes cluster I created in Kubernetes from Scratch. Have fun with your new storage box!