Showing posts with label lessons. Show all posts
Showing posts with label lessons. Show all posts

Saturday, August 10, 2019

Guide NAS on Raspberry Pi 4

I wanted to get a NAS solution for my apartment. The requirements were simple: it needs to serve my external USB's over the network and to be cheap. So when the Raspberry Pi 4 was announced I was curious if that would be able to be a cheaper alternative.

I ended up going with it because it was the smallest monetary upfront cost. $80 for a computer was not as big a commitment to the $200 i would need to at minimum spend. But if you were to factor in the costs of my external hard drives as compared to a more modern, durable, brand new set of drives. And a more streamlined setup process to boot. I'd say the conventional in store NAS solutions have a strong argument.

For this guide I will step through setting up a new Raspberry Pi 4, installing Rasbian lite and then OMV 5 beta, setting up OMV, ssh, and associated users, mounting an external usb HDD 280 GB and sharing it over SMB. I won't get into RAID configurations or other sharing protocols in this guide.

For this setup you will need:
  • This Guide uses MacOS X Mojave 10.14.5

Process Steps:

Imaging Raspbian
  1. Download the latest version of Rasbian Lite. The version I downloaded is Buster.
  2. Plug in your MicroSD card.
  3. Open Disk Utility
  4. Select your sd card in disk utility and look at the device field to find the device associated with your disk.
    If your device field says Disk2s1 then your dev is at /dev/rdisk2.
    Disk Utility with the system drive selected.
  5. Open terminal.
  6. sudo dd bs=1m if=~/Downloads/2019-07-10-raspbian-buster-lite.img of=/dev/rdisk2 conv=sync
    Obviously matching for the exact img you downloaded from raspbian. Let it run.
  7. When that finishes open the sd card in finder. (mount it in disk utility if its not mounted already).
Enabling SSH and Connecting
Before we start up the new raspbian boot sector on the pi, we need to make sure we can access the pi remotely by enabling ssh.
  1. In terminal navigate to the boot partition of the newly minted microsd card
  2. Mine is in /Volumes/boot
  3. In terminal type touch ssh to create an empty file named ssh
  4. Eject your microsd card
  5. Insert into rpi and power up.
  6. After a min to boot and initialize, in the terminal type  ssh pi@192.168.1.6 (use the address of your raspberry pi. You may need to find it in your by scanning your network or logging into your router and finding the network lease.)
  7. Use the default password 'raspberry'
  8. You should see a new terminal prompt from the raspberry pi. (accept the unsafe connection)
Modify deb repos and install armbian
  1. Follow the steps in this forum post in summary you will:
    • Add an apt repo
    • Install armbian
    • Use armbian-config to install OMV 5
      • Let it run
Log in to OMV web
  1. In your favorite browser go to the ip of your raspberry pi. 
  2. Log in using admin and default password openmediavault.
Configure Users
  1. Add any new users or modify passwords as needed here.
Enable SSH Again.
  1. While in rights management > users, be sure any users you want to be able to ssh in with are a part of the group ssh.
  2. Navigate to services SSH and be sure it's enabled. 
Enable Root Account
  1. While logged into the pi over ssh, in terminal enable the root account and change the password as in here.
Connecting, mounting and configuring external
  1. Plug in your external hard drive.
  2. Go to Storage > File systems
  3. Select your disk, it will have a name like /dev/sda1.
  4. Click Mount
  5. Click the apply changes button.
    Creating shared folder from external
    1. When the task finishes, go to Access rights managment > Shared Folders
    2. Click add, select your file system from devices and configure the share with a path.
    3. Click save.
    Creating SMB share from shared folder
    1. Click services > SMB/CIFS
    2. Enable it and set the workgroup name to something.
    3. Click shares
    4. Click add
    5. Select your shared folder
    Before we connect and access our NAS we need to name it.
    1. Go to system > network and set the hostname.
    2. In finder click go
    3. Click connect to server
    4. Type smb://nas-hostname
    Et voila!

    Pitfalls:
    HDMI
    Dont forget that the rspberry pi 4 uses micro HDMI cables. But you don't need them for this guide since we are able to SSH to the device and configure it remotely without a HDMI attached monitor.
    USB powered external drives
    Raspberry pi will apparently not power external HDD's without their own power source. If yours isn't working that's why.
    Relabeling
    Coming from the windows world my very mass produced external has always been named 'My Book'. But I suspect that space caused a lot of grief as I received the following error when applying the configuration change.
    Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; omv-salt deploy run fstab 2>&1' with exit code '1': /usr/lib/python3/dist-packages/salt/utils/path.py:265: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working if not isinstance(exes, collections.Iterable): /usr/lib/python3/dist-packages/salt/utils/decorators/signature.py:31: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly *salt.utils.args.get_function_argspec(original_function) raspberrypi: ---------- ID: create_filesystem_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7 Function: file.accumulated Result: True Comment: Accumulator create_filesystem_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7 for file /etc/fstab was charged by text Started: 21:58:46.603232 Duration: 1.485 ms Changes: ---------- ID: append_fstab_entries Function: file.blockreplace Name: /etc/fstab Result: True Comment: No changes needed to be made Started: 21:58:46.606017 Duration: 6.132 ms Changes: ---------- ID: mount_no_bind_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7 Function: mount.mounted Name: /srv/dev-disk-by-label-My Book Result: False Comment: mount: bad usage Try 'mount --help' for more information. Started: 21:58:46.613705 Duration: 539.445 ms Changes: Summary for raspberrypi ------------ Succeeded: 2 Failed: 1 ------------ Total states run: 3 Total run time: 547.062 ms


    Error #0:
    OMV\ExecException: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; omv-salt deploy run fstab 2>&1' with exit code '1': /usr/lib/python3/dist-packages/salt/utils/path.py:265: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
      if not isinstance(exes, collections.Iterable):
    /usr/lib/python3/dist-packages/salt/utils/decorators/signature.py:31: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
      *salt.utils.args.get_function_argspec(original_function)
    raspberrypi:
    ----------
              ID: create_filesystem_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7
        Function: file.accumulated
          Result: True
         Comment: Accumulator create_filesystem_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7 for file /etc/fstab was charged by text
         Started: 21:58:46.603232
        Duration: 1.485 ms
         Changes:
    ----------
              ID: append_fstab_entries
        Function: file.blockreplace
            Name: /etc/fstab
          Result: True
         Comment: No changes needed to be made
         Started: 21:58:46.606017
        Duration: 6.132 ms
         Changes:
    ----------
              ID: mount_no_bind_mountpoint_0b89de0f-125a-47d9-bbd1-58a3a7da4ef7
        Function: mount.mounted
            Name: /srv/dev-disk-by-label-My Book
          Result: False
         Comment: mount: bad usage
                  Try 'mount --help' for more information.
         Started: 21:58:46.613705
        Duration: 539.445 ms
         Changes:
    To fix this error change the format label using fatlabel to something without a space, unmount and unplug the USB external.  Delete the reference to the file system. Apply the changes then start over with the new label. It should work fine now.

    Closing Thoughts
    It's simple and cheap and it does what I wanted. But it can't really be taken seriously without looking at it's performance and whether it can manage an effective RAID. Also I'd love to get it all into one case.

    Tuesday, October 16, 2018

    Silicon Valley Code Camp 2018


    This weekend I attended Silicon Valley Code Camp. Code Camp is a conference on its 12th year held in San Jose California and put on by volunteers. I’ve known about it for many years (I found the earliest email I got from them is from 2009), but this was my first year of attendance.

    In this post I give quick play by play of my weekend, with summaries, impressions and/or takeaways from each of the talks I attended.

    Saturday I arrived late and had no problem getting my pass as I had registered early. I arrived late to my first talk. It was about IoT with Edge. I’m very disappointed I missed as much as I did. I was able to glean how Edge devices and routers interact to communicate with the cloud. How twins of the device status are mirrored on the cloud and what role hubs perform when connection to the cloud is severed. It seems that it runs on raspberry pi, I was not aware of that. 

    The second talk was on C++ server API’s. The speaker was really entertaining and explained things well. He went on a few tangents which took a lot of his time, but they were entertaining so I forgive him. However, he couldn’t finish the talk on time so a few things were skipped over. I’m really not criticizing him for this. I don’t think that not getting the full talk made my experience on Saturday any less vaLuable. More than anything this talk was more a discussion on best practices when beginning new projects.

    The third talk I went to was on java and Kubernetes. This one was tough. I do not know enough about docker to have gotten as much as I’d like from this. I got a general idea of workflow, of setup, of Java through docker with Kubernetes within IntelliJ.

    Next was a talk on Recursion and Dynamic programming for technical interviews. This was really just a talk. It represented recursion and dynamic programming with simplified language as opposed to any detailed implementation or code. Dynamic programming fit into the talk really smoothly. Again, it used the same simple explanation technique as used for recursion. What’s more it seemed very natural to explain DP directly after explaining recursion as he had built up the concepts in such a way that the two example problems were nearly identical.

    The final talk was not technical. It was about human learning techniques. Worth the time and part of the reason I’m writing this. The speaker was really good and covered some things that hold back learning, techniques students and educators could use (like a learning journal) and some myths.

    Sunday was more laid back: fewer people, less prepared speakers, for lack of a better description, less popular topics.

    I started by going to an intro to mongoDB. My take from the talk was that It sounds like a great way to get away from SQL tables and a carefully planned DB before implementation aka. prototyping. 

    For the rest of most of Sunday I attended a series of talks by 3 gentlemen. The series was ostensibly about creating drivers for android. That’s not what it was. It was implement Android’s Binder Inter-process communication as a linux device drivers.

    The first talk was the best for anyone who went for an education on android. It covered concepts of binder which would help any Android programmer to better understand and better utilize the technology.
    The second in the series was an introductory tutorial on writing kernel mods for linux and a bit on the Android Linux kernel.

    The third talk was the curve ball. Where the speaker showed his implementation of Binder on an Ubuntu AWS machine. A little bit of a letdown but overall a really excellent series but for the expectations set. Now looking at the schedule I can see the signs. 

    Finally a talk on interfacing with C from Lua and Ruby. in all directions: Lua to C, C to Lua, Ruby to C, and C to Ruby. It’s apparently really easy to call C libraries in Ruby. The speaker spent more time than was needed on summarizing each language. I don’t believe anyone actually attended the talk which didn’t know one of the languages and so the subject of actually interfacing seemed to not get enough attention while the majority of the talk was used to educate everyone on the properties of Lua and Ruby which weren’t necessarily relevant to interfacing with C.

    Food and drink were provided in the morning, at lunch each day with occasional snacks set out, and ice cream in the afternoon on Sunday. There were raffled prizes donated by the event’s sponsors. It was well worth the money paid. In fact it was worth far more than the money paid. I’m really kicking myself for 9 years of stupidity for not attending.

    - Victor F.