Linux Home Server Build

Linux Home Server Build

On this blog I have posted many times about my home server configuration and seeing as I’ve recently updated it I thought I’d give a quick overview of the changes made and provide some tips for setting up a Linux home server.

My home server (an HP MicroServer) is used for NAS file storage, running Plex Media server and a few other ativites including client backups. Previously my server was running Windows Home Server 2011 which was an excellent Home Server OS from Microsoft based on Windows Server 2008 R2. In additon to file sharing it also allowed for easy server administration and client PC backups. Client PCs would backup images to the server allowing for client files or whole systems to be restored. Unfortunately Microsoft discontinued Windows Home Server and it is no longer supportrd and Windows Server 2008 R2 updates will stop in July 2019. In terms of replacement options there were several, whilst all Windows offerings are too expensive and seem overkill for a home server, serious Linux and BSD options include Free NAS, Amahi, Ubuntu Server and numerous Linux desktop distros. I would also recommend looking at a Synology if you have the budget.

In the end I chose Lubuntu 18.04 (LTS) desktop distro for my needs. Why a desktop distro for a server? Well I dont need to squeeze every onunce of performance from the server and the Lubuntu desktop is so lightweight and efficient I can have a graphcial desktop enviroment as well as great server performance. It is handy to have the option to be able to RDP into the box and use the Lubuntu desktop as an alternative to SSH when required.

I installed the OS, and checked for updates:

sudo apt-get update
sudo apt-get dist-upgrade

After installing the OS I inserted the data drives and mounted them under a /mydata mount point so that I can easily access all the files on those drives. To make these mount points persistent I edited /etc/fstab to add each one using the UUID of the partition (which is found in Disks app or the GParted app)

sudo nano /etc/fstab

Then add an entry for each parition to mount …

 UUID=YOUR_OWN_PARTITION_UUID /mydata/d1/ ext4 defaults 0 0
UUID=YOUR_OWN_PARTITION_UUID /mydata/d2/ ext4 defaults 0 0

Configure The FireWall

The ufw (uncomplicated firewall) firewall is installed on Lubuntu by default but is turned off so turn it on and check its status:

sudo ufw status 

If inactive then activate it with:

sudo ufw enable

To see its status and current rules:

sudo ufw status verbose

Add new rules with:

sudo ufw allow PORTNUMBERHERE 

Install XRDP Remote Desktop Service

Next I set up XRDP for remote access to this headless server.

sudo apt-get -y install xrdp
sudo ufw allow 3389/tcp
sudo systemctl enable xrdp
sudo systemctl restart xrdp

At this point I hit may issues but this hack below seemed to be the one that led to a working XRDP session but using this command to create a .xsession in home directory of connecting user:

 echo "lxsession -s Lubuntu -e LXDE" > ~/.xsession 

For more information see this article.

Setup Cockpit Web Interface

For more remote administration and monitoring goodness I installed Cockpit which is a web based interface for servers with lots of useful features.

sudo apt-get install cockpit
sudo ufw allow 9090

Then browse to https://yourserverip:9090

For a useful Cockpit install guide check out this link.

Setup Samba for file sharing

The whole point of a file server is to share files and in order to support file sharing with Windows devices on the network you’ll need to setup Samba. A good link for setting up Samba can be found here.

sudo apt-get install samba

Set a password for your user in Samba.

sudo smbpasswd -a        

All the folder shares and their configuration are stored in the smb.conf file which can be edited by opening it up in a text editor like nano.

 sudo nano /etc/samba/smb.conf 

In the smb.conf file you may want to change the workgroup name to the same as that used by your window PCs and then add each of your folder shares.

[<folder_name>]
    path = /folder/path
    valid users = <user_name>
    read only = no

Once you have made the required changed restart the smb daemon service

sudo service smbd restart

You’ll also likely need to punch a hole in the ufw firewall for samba

sudo ufw allow Samba

Once Samba has restarted, use this command to check your smb.conf for any syntax errors with testparm

testparm

For a good guide on more complex permissions check out this guide here.

It’s worth noting that users need to have Unix perms on the underlying folders in order to be able to access them. Amend Linux file permissions as required.

Scheduled Tasks with Cron

For scheduled tasks (backup jobs etc) I have configured Cron jobs to run bash scripts (although I could have kept my existing PowerShell scripts as PowerShell now runs on Linux too) but they needed a rewrite anyway.

Open your cron job file with…

sudo crontab -e 

then add entries like this example:

# run test job at 11:15 every day 
15 11 * * * . /etc/profile; /bin/bash /home/me/testjob.sh > /tmp/cron.out

For more info on Cron check out this guide and for an awesome helper tool for building the Cron schedule times check out corntab.com.

Summary

So I’ve covered the basics of how I’ve set up my Home Server using Lubuntu which others may find useful. I’ve been running this setup for a few months and so far I am very pleased with its performance and stability.

Future steps are to install Plex Media Server and configure client PC backups. As I want to use the Snaps for Plex I am waiting for the offical Plex Snap Package to come out of BETA as I’m not in a rush. Alternatively I may use Docker to run Plex. To replace the client PC backup feature I previously had with Windows Home Server I will soon be moving to a client imaging tool such as CloneZilla, Acronis or Windows Backup and then copying the images to the server.

Advertisements

Calculate a file hash without 3rd party tools on Windows & Linux.

Calculate a file hash without 3rd party tools on Windows & Linux.

If you need to generate a hash of a file (e.g. MD5, SHA256 etc) then there are numerous 3rd party tools that you can download but if you are restricted to only built in tools or don’t need to do this often enough to install something then there are built in OS tools for Windows and Linux that can be used.

Windows:

For Windows there is “certUtil” which can be used from the command prompt console with  the “-hashfile” option to generate a hash for a supplied file:

CertUtil [Options] -hashfile filePath [HashAlgorithm]

The [HashAlgorithm] options are MD2, MD4, MD5, SHA1 (default), SHA256, SHA384 and SHA512.

For example to get an MD5 hash of a file use:

CertUtil -hashfile C:\ExampleFile1.txt MD5

More documentation for CertUtil can be seen here.

For those with access to PowerShell v4  and above (Windows 8.1 & Win Server 2012 R2) you can use the built in commandlet called get-filehash like this:

Get-FileHash C:\ExampleFile1.txt  -Algorithm MD5 | Format-List

The algorithms supported are SHA1, SHA256 (default), SHA384, SHA512, MACTripleDES, MD5 & RIPEMD160.

For Powershell versions prior to V4 there are numerous scripts available on the web that will work out the hash for you using various methods.

Linux:

For Linux use the correct  hashalgorithmSUM command in the terminal for the algorithm you are looking for, i.e. for an MD5 hash use md5sum or for SHA512 hash use sha512sum.

For example:

md5sum /home/rich/Documents/ExampleFile1.txt 
sha1sum /home/rich/Documents/ExampleFile1.txt
sha512sum /home/rich/Documents/ExampleFile1.txt

 

 

Using a Sure Electronics LCD with the Raspberry Pi using Python

Using a Sure Electronics LCD with the Raspberry Pi using Python

After receiving a new Raspberry Pi 3 at Christmas I quickly set off looking for uses for this wonderful machine, and quickly found myself hooking it up to an LCD display. This post covers the Python driver I used and modified, as well as some other useful resources.

RPi3

Firstly as an owner of the original Raspberry Pi model B I was pleasantly surprised how capable the Raspberry Pi version 3 is. The performance is much improved and the new built in wireless is a superb addition which makes this version of the Pi more  usable and reduces the friction caused by having too many USB devices hanging off it like a mutant spider. The Pi v3 is powerful enough to be used as a basic workstation and I found myself working on it directly (within Raspbian OS) making the coding workflow more enjoyable as a result than the previous models. Also the as VNC Server is now built into the Raspbian OS it makes setting up the Pi as headless very easy. In fact once you have installed Raspbian and setup VNC then you can run it with just the power supply connected which makes it use little space and you can locate it anywhere.

SureElecLCD1Once my Pi3 was up and running I decided to connect an old LCD matrix screen to it. This LCD is Sure Electronics 20×4 screen which I bought years ago to attach to my HomeServer but never got around to it. The LCD has a USB interface and was used on Windows via the LCD Smartie application. A quick google showed that LCDProc is an equivalent tool for using LCD screens with Linux, and I found some useful tutorials (e.g. here & here). You can install LCDProc via “apt-get install lcdproc”.

I only had limited success with LCDProc but soon realised what I really needed was a programmatic way of controlling the LCD as opposed to a general display tool, so after some more googling I found a few variations of python drivers were being used to control similar LCDs, and this “Smartie” driver by Steve Davis worked best for me, which in turn was inspired by this driver. These drivers use the “pyserial” Python module, easily installable via Python PIP package manager:

“apt-get install python-pip” or “apt-get install python3-pip” (for python v3 pip)
followed by “pip install pyserial==3.0”.

RaspberryPiWhilst the smartie driver initially worked I found that it failed to work after a reboot. After some serious head scratching I realised that it would always work after running LCDProc, meaning the initalisation code for LCDProc setup up the LCD successfully for the Python driver to communicate.  After digging into the Sure Electronics manual and digging into the source code for the SureElec driver for LCDProc (here & here) I was able to find the initisiation command codes for the LCD and add this to the smartie python driver. This enabled the Python driver to be used without relying at all on LCDproc or similar software.

 I have also added some new functionality to the driver which includes flashing, wrapping text and scrolling multiple lines etc. Also included is a demo function that runs through the various functions provided by the driver to show what’s possible and to help testing after making any modications. My updated driver can be found on my GitHub repo (https://github.com/RichHewlett/smartie). With this driver i was able to control my LCD backlight, display text and get a temperature reading. The fact that it was writen in Python was a bonus as I find Python a great langage for coding fun projects.

SureElecLCD2

If you have a Sure Electronics LCD you may be able to take this and use it, or modify it as required, although there are many variations of these devices. Once you have connected your LCD and rebooted the machine just check that the LCD is on the right USB port in Linux (e.g. /dev/ttyUSB0) and that the user has permissions on that port. If you have a Sure 16×4 screen then this will probably work by modifying the SCREEN_WIDTH constant to 16. If you have a different LCD Screen then you may need to modify the initalisation codes and command strings that get sent to the LCD by each method. A good source of refercence is to check out the LCDProc source code for their bundled drivers as they support many screens.

In the next post I’ll cover my next step of building Python Web App using Flask to control the LCD screen from a browser.

Using Ubuntu via VirtualBox Seamless Mode

Using Ubuntu via VirtualBox Seamless Mode

I like Ubuntu and I enjoy using it, although I’m still a windows guy at heart (at least for the time being anyhow but we’ll see if Win8 ever grows on me) and I use a lot of Windows only apps. The approach I’ve been using for the last few months with great success is VirtualBox’s Seamless mode.

SeamlessModeImage

I run Ubuntu in a VirtualBox guest VM on top of a Windows 8 host (although it could be the other way around) and when its running I run it in Seamless Mode. My virtual Linux PC is then running in a normal desktop window and my mouse and keyboard works seamlessly between them.

SeamlessDesktop

I effectively have two desktops here, my Windows one and my Ubuntu one. If you set up a shared folder between the two machines within VirtualBox its easy to share files too. Of course you don’t get the performance benefit of running Linux directly on the hardware as you would with a dual boot configuration but dual booting doesn’t provide the ability to interact between the OS’s.

This approach is the best way I’ve found yet to run Linux and Windows together.

You can also go further for some OS configurations and use Seamless Windows if your setup allows, which enables your guest OS windows to be displayed side by side with the host OS’s windows.

Hello Linux – Again

Hello Linux – Again

I’ve been increasingly interested in the Linux OS again recently and have re-discovered it’s power and flexibility. I’m a Windows guy primarily, always have been, but I’m writing this on the new Ubuntu 11.04 (Natty Narwhal) release and I must say I am enjoying the experience.image

This is by no means my first foray into the world of Linux, in fact my first exposure was way back 1999 (wow was it that long ago?) when I heard about this magical version of Unix  that ran on PC hardware. At that point my home PC was running Windows NT on a Pentium 166 with a heady 64MB Ram. I purchased a Linux book that came with a Linux distribution on CD (downloading was not really an option for me back then with a slow dial-up connection). It was Caldera OpenLinux 2.2 and installing it was a nerve racking and sadly enjoyable journey of re-sizing partitions, configuring drivers and general frustration. Eventually I had a dual boot NT and Linux PC and a sense of self satisfaction, but Linux didn’t capture my imagination much further at that point. Much like playing with Lego as a child (or an adult Smile) the fun is in the building and configuring it how you want but not the playing with it afterwards, my fun with Linux was over. The UI felt like a poor relative to Windows and I booted into it less and less. As I moved further into Windows development there was less of a desire for me to explore Linux more. Over the last 12 years I have played with a few distributions on and off but never really for any reason other than curiosity and none of them really stuck. Lately though I’ve started to get the Linux itch again so I got downloading and I’m very pleased with what I’ve found.

Firstly it is now so incredibly quick and easy to get Linux distributions installed and setup on your machine of choice. There are so many options to get you up and running, and with most drivers automatically detected you should get few issues. Of course Virtualisation has made it easy to try out various OSs and Linux is no different. VirtualBox is a joy to use if you want to try out a Linux installation, but there is also the LiveCD option that enables you to run your Linux distribution of choice off a USB or DVD drive without touching your hard drive. Whilst this is not very practical for everyday use its good for getting a real feel for what a Linux distribution is like and what it will be like on your hardware. The best option for me with it’s ease and practicality is Wubi whereby you can install Ubuntu within your Windows OS and it creates a virtual disk on your Windows drive for installation. This means all your files are sitting isolated in a Linux virtual disk file within Windows. You boot into Linux normally (via the Windows dual boot loader screen) and it is completely transparent to your Linux OS that it’s disk is actually virtual. Of course there is a performance overhead around disk access but its not noticeable even on my netbook. This approach allows you to get all the benefits of a Linux installation without having to go full hog straight away with partitioning your disk. I’ve been running Ubuntu for a while using this approach and its working a charm. I do intend to go the full hog soon and install a fresh install of Ubuntu onto its own partition when I get around to it but as it works so well I’m in no rush. In the meantime I can try out some other Linux distro’s to find the one for me (Linux Mint and Tiny Core are on my list to checkout).

Ubuntu Unity DesktopUbuntu is certainly a relatively user friendly Linux distribution and whilst the switch to the new Unity desktop for  the latest 11.04 version is very controversial within the Linux community there is little doubting that it is a friendly experience to new Linux users. It is also a very good desktop experienced for Netbooks, which is probably why it’s working so well for me on my netbook. I’m not sure how it will scale up to my desktop yet and do understand the negative comments that have been pitched at it. Regardless it is a way of Ubuntu differentiating itself from Windows and Mac, whilst making itself as user friendly as possible. It does appear as though Unity is a first step towards Ubuntu becoming a touch friendly device like Linux distribution. I’ve commented before on this blog how i see devices replacing the PC for all but “power user” type consumers and yet I still feel that a light friendly Ubuntu (with the power still underneath for those that want it) can do well. My wife is happy using Ubuntu on my netbook because like many consumers she does almost everything in the browser and this is where Linux on a Netbook seems to shine, as its capable, light and fast. A key advantage for Ubuntu is the Ubuntu Software Centre which is ideal for new users to get up to speed quickly. Overall I have been pleased with how Ubuntu plays with my Windows network shares and was pleased that I haven’t even needed to install a Remote Desktop client to logon onto my Windows servers as there is one included (type rdesktop servername at the terminal).

It’s still early days with my latest affair with Linux but so far it’s going well and this time I might get totally hooked.