Wednesday, December 27, 2017

Designing and Building a File Vault

Actually, make that two file vaults. I'm making a large file vault for myself and a smaller one for my parents. The specs of the machines will be similar, but the biggest difference is the amount of storage each will have. The best part: they'll both go into an almost identical case to the almost complete Game Console (I should really figure out what I need to do to finish that...). The only difference is that these are a little shorter. But I'll still use the power buttons and lights, I'll still remove the display boards (assuming they're still separate from the main logic boards) and I'll do everything very similarly. That's why this probably will be one long post instead of broken up into several posts like it was initially.
I'll describe building my parents box, since that's the one I'll be making first. I may make a supplemental post when I build mine slightly differently.

The first thing to do was to gut the boards and the power supply out of the box. They were far simpler than the one from the game console, I'll try to reverse these later. The power supply consisted of massive capacitors (what fun) and a an unknown transformer.



I was left with a beautiful empty case and, alas, a bolt that I didn't have the tools to cut sticking from the side. I don't think this will be a problem yet.



We then lay it all out. I got a MicroATX motherboard to save on space (we'll talk about specs later), so we can have a proper power supply and the hard drives.


Just as before, I drilled holes into a piece of wood to adapt it to the box. Some from the bottom, some from the top. I only needed four screw holes to secure the motherboard because I was hanging it off the edge of the wood. After adding nuts to the screws, we had standoffs and then we had a finished adapter. The power supply and hard drives would be fastened in place with velcro. I put velcro in between the hard drives to remove vibration transmission.


I threw in the processor and some memory and turned it on. I got into the BIOS just fine which is a convincing first step.


I also added a small 80GB hard drive to act as the boot volume so I didn't have to rely on booting from a RAID array. I then hooked up the RAID array to a RAID card. I removed the metal part from the card so it would fit in the case. I went into the RAID setup utility and set up a RAID5 logical drive.



Next, I installed Ubuntu 17.10 Desktop. It should have been straight forward and from a USB stick, but the installer seemed to hang when I had the logical drive set up and completely crash when I didn't. The only way I could get Ubuntu installed was without the RAID controller plugged in. This was very worrying. When I put the controller back in and turned it on, Ubuntu saw all of the individual drives, but nowhere was it banding them all together in one RAID volume.

I came to the conclusion that this was because the SY-PCI40100 is actually a fakeraid controller, meaning I've essentially added a few extra SATA ports. I guess I'm using software RAID which in Linux isn't exactly the worst thing in the world. I've read some really amazing reviews about it, and it will support RAID6. This should have been the plan all along.

So I deleted the logical volume and set up Linux software RAID with a RAID6 array and formatted it with ext4. Now I have a single large volume with a mount point in /srv. Inside of that directory we'll have a few file directories (one of which is for Media and well have a well defined structure). This is where Kodi, Samba, and Plex will eventually look for its media.

This actually turned out to be a horrible thing - the fakeraid card was so slow. It was so bad that I decided to make just a 3 drive RAID5 array and plug everything in right to my motherboard. The speed increase was immediate. Suddenly I was getting resync speeds of 150MB/s. Finally. But in order for any of this to work, I have to add a WiFi adapter. I went with a cheap TP-Link WiFi card that I knew would have no issues working with Ubuntu.

So, now with the setup more or less set up (there's still one big crucial part we're missing here that we'll get back to), it may be a good time to talk about what hardware I have in this machine. The biggest factor in deciding the hardware for this machine was that it needed to support 4K (when I say 4K I really mean UHD) video with integrated graphics. My parents don't own a 4K TV yet, but I do and I wanted it to be slightly future proof. So I had to find a processor and motherboard that could handle 4K output over HDMI. I also wanted to stay with AMD because I sorta have loyalty to that brand.

So, after some research, I went with the AMD A10-7860K. It should have no problem playing back 4K@30FPS video. It features 4 CPU cores and 8 GPU cores. I also went with the Gigabyte GA-F2A68HM-H as it explicitly states native 4K support on its HDMI 1.4 output. So this configuration should work fairly well. As for the memory, I put in what I had: 10GB of DDR3. I stayed in the DDR3 family of RAM because I wanted to use what I had. The power supply is a Corsair CX550. There's nothing special about the hard drives or the wifi card I'm using.

Now that the hardware is ready to go, we can install software. The first thing to do is to install Samba and an easy way to manage it. Webmin seems to have just what we need, so we'll install that after we install Samba. We follow these directions taken from the debian install instructions for Webmin and tweaked a little bit.

sudo apt install samba perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.870_all.deb
dpkg --install webmin_1.870_all.deb

It installed very very easily.


First, I used the users panel to create my parents users so they can have their own protected shares on the server, and then I created their Samba shares in the Samba Server panel. Then I made a photos and a media directory. You have to be careful with permissions here. With enough finagling I managed to get it to work, but I'd suggest learning the correct way to do this. I had some weird exclusion rules in the end and I suspect there's an easier way to do this.



Now that all of the shares were created, I started putting data onto it. I put some movies and TV shows I had that I thought they'd like into the media directory (well organized, of course), and loaded all of the family pictures onto it.

Next, I installed the Plex Media Server. This was very easy - it was just a single package I downloaded from their website and then magically all of my media showed up! Nice! Next, I installed Kodi. Kodi was super easy to install and even easier to set up. Follow the instructions on their website if you want to know more about that step.

Finally, it came time to solve the final problem I had been putting off for so long... how was I to convert a toggle power button switch into a momentary switch's pulse? It's easy to go from momentary to toggle with a latch, but it's harder to go the otherway. How could we do this?

The first option was to use an XOR gate with two inputs: The first input would come straight from the switch while the other would be buffered by a capacitor. While the cap was charging and still outputting a logical zero, the unbuffered input would be high, causing the XOR to output a high signal until the cap charged. This time delay would easily convert the toggle to a pulse, but I didn't have an XOR gate on hand and getting one online would have been expensive given the time crunch.

So I went with the next best thing: an ATTiny85. I had one just sitting here, and I figured this would ba great time to learn how to use it!

I followed the instructions given here (although the ATTiny core files they suggest are outdated and don't work with the IDE) and managed to load the blinking program onto the chip with no problem at all. It was at this point I realized I needed more of these ATTiny chips because this was a nice and small general purpose chip. I don't believe in cutting a sandwich with a chainsaw, so I always shoot for the minimal amount of processing power for any given task so as to not waste hardware potential. I felt bad because that was exactly what I was doing here, but I had a deadline.


Nice! So then I wrote the power management code. The power management code would fire a 500ms pulse on one of the output pins if there was a change interrupt on one of the input pins (I chose PB4 for testing purposes and stuck with it). Then it would go to sleep until it got another pulse. Ugh, just typing that I feel wasteful. On my version I will use a more specific circuit to avoid being wasteful of microcontrollers. I don't know why I feel this way, I just do. The code for the microcontroller is here.

Next, I have to actually wire it up. The first thing to do was to find how to get the continuity of the switch of the box. It turned out to be these two pins on the connector:


Okay, so now how do I power the thing? I know there's a standby always-on 5V that comes from the power supply, but I don't want to modify the 24-pin connector. So I checked the USB header on the motherboard and found that it's also always on! This is where I'd get my 5V power! I soldered everything to some perf-board and attached it to the inside of the computer. It's not pretty, but it works very well. We also have to hook up the power LED to the motherboard. The motherboard generally uses 3.3V for LEDs, so we probably don't need a resistor here.

Okay, so far so good. Now let's set up Kodi.

Installing Kodi is very easy. It also configures itself to run on start up. Setting it up is just as easy. The interface is very intuitive. Once Kodi was all set up and ready to go, it was time to put it to the ultimate test: 4K playback of a 4K file on a 4K screen.

The only verified true 4K movie I have is The Revenant. What I was looking for here was full framerate and no decompression artifacts. I wanted flawless real time playback. The results? Flawless real time playback at what looked like 4K and audio that sounded wonderful.

So, that's basically it for this build. It looks really well and does everything I want it to. It's a great HTPC build for about $200-300 that's capable of 4K playback without a graphics card. I think it's a slick looking build - never underestimate what you can shove a computer in.

No comments:

Post a Comment