Sunday, July 22, 2012

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 6 - Install and configure Serviio & BubbleUPNP)

The main objectives of this project are already done, but I can't say I've fully replaced my WHS2011 install with Ubuntu without a DNLA server and proxy.

First the server. Although Windows Home Server 2011 did have some built in DNLA functionality I was running Serviio as a replacement for the added functionality.

$ wget http://download.serviio.org/releases/serviio-0.6.2-linux.tar.gz
--2012-07-21 23:55:30--  http://download.serviio.org/releases/serviio-0.6.2-linux.tar.gz
Resolving download.serviio.org (download.serviio.org)... 195.3.138.234
Connecting to download.serviio.org (download.serviio.org)|195.3.138.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14038981 (13M) [application/x-gzip]
Saving to: `serviio-0.6.2-linux.tar.gz'

100%[================================================>] 14,038,981  2.01M/s   in 8.4s   

2012-07-21 23:55:39 (1.59 MB/s) - `serviio-0.6.2-linux.tar.gz' saved [14038981/14038981]

$ tar -xzf serviio-0.6.2-linux.tar.gz
$ mv serviio-0.6.2 serviio
$ sudo mv serviio /usr/share/
$ sudo chown -R serviio:staff /usr/share/serviio/

The rest of the instructions I used are exactly from: http://forum.serviio.org/viewtopic.php?p=11646#p11646

Here is my init.d script:

Saturday, July 21, 2012

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 5 - Install and configure Samba)

While I personally spend the most time on a MacBook both personally and professionally, both my wife and I spend a great deal of time with Windows as well. As such, it is important that the home directories and shared data on the home server be accessible to both Windows, Linux and MacOS. This is especially true as the home server must also serve as a backup repository for the several windows machines in the house as well.

Thus, it's time to configure Samba. As the basis for my smbd config I primarily used: http://www.sitepoint.com/ubuntu-12-04-lts-precise-pangolin-file-sharing-with-samba/ but there are a plethora of resources for configuring Samba and I've only scratched the surface of what's available.

$ sudo apt-get install samba

[global]
    unix charset = UTF-8
    # -------------------------------------------
    # DEFINE YOUR WORKGROUP AND COMPUTER NAME HERE
    workgroup = WORKGROUP
    server string = homeserver-s
    netbios name = homeserver-s
    # -------------------------------------------
    dns proxy = no
    name resolve order = lmhosts wins bcast host
    # -------------------------------------------
    # IF YOU SET BIND INTERFACES TO YES, TO AVOID LOG ERRORS,
      # MAKE SURE YOUR SAMBA SERVICE STARTS AFTER THE ETHERNET CARD IS SWITCHED ON
    # bind interfaces only = no
    # bind interfaces only = yes
    bind interfaces only = no
    # ADD THE ETHERNET CARD AND IP ADDRESSES YOU ALLOW
    interfaces = eth0 127.0.0.0/8 192.168.1.0/24
    # -------------------------------------------
    # SAMBA LOG FILES
    log file = /var/log/samba/log.%m
    max log size = 1000
    syslog only = no
    syslog = 0
    # -------------------------------------------
    panic action = /usr/share/samba/panic-action %d
    # LIMIT ACCESS TO USERS ONLY
    security = user
    # USING TDBSAM
    encrypt passwords = true
    passdb backend = tdbsam
    obey pam restrictions = yes
    unix password sync = yes
    passwd program = /usr/bin/passwd %u
    passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
    pam password change = yes
    map to guest = bad user
    usershare allow guests = no
    # -------------------------------------------
    # INCLUDE THIS SECTION TO DISABLE PRINTERS/CUPS ONLY
    load printers = no
    printing = bsd
    printcap name = /dev/null
    disable spoolss = yes
    # -------------------------------------------
    # DIRECTORIES
    # -------------------------------------------
    # ENABLE HOME FOLDER ACCESS
    [homes]
        comment = Home Directories
        browseable = no
        writable = yes
        valid users = %S
    #    valid users = MYDOMAIN\%S
        create mask =0755
        directory mask =0755
    # -------------------------------------------
    # EXAMPLE FOLDER WITH LIMITED ACCESS, UNCOMMENT AND CUSTOMISE AS NECESSARY
    #[example]
    #   comment = example share folder on my-computer-name
    #   path = /foldername/foldername/
    #   browseable = yes
    #   guest ok = no
    #   writable = yes
    #   create mask = 0755
    #   directory mask = 0755
    #   valid users = @your-username
    #   force group = your-username-or-group
    #   force create mode = 0755
    # -------------------------------------------
    # -------------------------------------------
[Videos]
   comment = Transcoded movies and television shows
   path = /data/external/videos
   browseable = yes
   guest ok = no
   writable = yes 
   valid users = @staff 
   force group = staff
   force create mode = 0664
   force directory mode = 0775

With the shares configured and created, restart smbd and nmbd.
$ sudo server smbd restart && sudo service nmbd restart

Before user authentication will work, the following needs to be run for each user that will be granted access. The user account also needs to be a member of the staff group, which is effectively power users on my system.

$ smbpasswd -a new-username-here
 
This command will prompt for a smb password. As configured I'm assuming the unix and smb passwords are the same.

 

Friday, July 20, 2012

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 4 - Install and configure Netatalk)

One of my primary goals with this conversion is to allow my MacBook with 10.7 to use the home server as a time machine backup destination. Since Apple nerfed the ability to hack time machine into a SMB share I've been looking for a way to get netatalk on this hardware.

I found a few guides for installing netatalk on Ubuntu server, and while this was the best I wound up combining information from a number of places and a little trial and error in a virtual machine before settling on the steps.

  1. First we need to install netatalk and avahi-daemon. The first provides the actual afp daemon and the second the bonjour daemon to allow the MacBook to see the afp shares.
    $ sudo apt-get install netatalk avahi-daemon 
  2. Once installed, configure the netatalk daemon by editing /etc/default/netatalk
    $ sudo nano /etc/default/netatalk
    Ensure that the following options are set:
    ATALKD_RUN=no
    PAPD_RUN=no
    CNID_METAD_RUN=yes
    AFPD_RUN=yes
    TIMELORD_RUN=no
    A2BOOT_RUN=no
  3. Next modify the netatalk shares by editing /etc/netatalk/AppleVolumes.default
    $ sudo nano /etc/netatalk/AppleVolumes.default
    Add "tm" to the default options line:
    DEFAULT: options:tm,upriv,usedots
    And add a line similar to the following to create the Time Machine share. User home directories are shared by default as well but I find having a single share for time machine bundles it more manageble:
    /data/backup/TimeMachine "Time Machine" cnidscheme:dbd allow:@timemachine
  4. Before we forget we should create the timemachine group and folder.
    $ sudo addgroup timemachine
    $ sudo adduser timemachine
    $ sudo mkdir /data/local/backups/timemachine
    $ sudo chgrp timemachine /data/local/backups/timemachine
    $ sudo chmod 775 /data/local/backups/timemachine
  5. Lastly we need to configure avahi. This is done by creating /etc/avahi/services/afpd.service and adding the following XML code:
    $ sudo nano /etc/avahi/services/afpd.service


        %h
       
            _afpovertcp._tcp
            548
       
       
            _device-info._tcp
            0
            model=Xserve
       
  6. Restart netatalk and avahi and test in Finder
    $ sudo /etc/init.d/netatalk restart
    $ sudo service avahi-daemon reload
Next stop, samba...

EDIT: I did find it helped to set the group ownership on the shared folder to something like "users" or "staff" and set the permissions to 2775 to allow the group ownership to automatically propagate to new files added.

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 3 - Configuring RAID5 with LVM)

To meet my capacity requirements, my HP LX195 has 3 external 1TB hard drives. While the Western Digital MyBook drives have proven reliable, I have still had disks fail and take data with them to the grave since I installed my home server unit a few years ago.

With a Linux based solution I decided to bite the bullet and figure out how to configure a RAID5 array out of the three. This reduces my over all available capacity, but should still prove sufficient. Besides, I have one USB port left for an additional drive for non-redundant bulk storage.

To do so I followed the instructions from the following site with only slight modifcation.
 http://dtbaker.com.au/random-bits/ubuntu---howto-easily-setup-raid-5-with-lvm.html

To summarize my personal steps:
  1. $ tail -f /var/log/syslog
  2. Connect drive 1, note device reported by syslog (should be sdb)
  3. Connect drive 2, note device reported by syslog (should be sdc)
  4. Connect drive 3, note device reported by syslog (should be sdd)
  5. Label all 3 drives for future reference
  6. $ sudo apt-get install mdadm smartmontools
  7. $ sudo nano /etc/defaults/smartmontools
  8. uncomment the "start_smartd=yes" line. I'm not sure if smartmontools will work with usb hard drives, but it's worth a shot
  9. $ sudo nano /etc/smartd.conf
  10. Add one line for each new drive:
    /dev/sdb -a -I 194 -W 4,45,55 -R 5

    /dev/sdc -a -I 194 -W 4,45,55 -R 5

    /dev/sdd -a -I 194 -W 4,45,55 -R 5
  11. Since my disks were already partitioned I needed to first delete the existing NTFS partitions and recreate them as Linux raid partitions. Note: be sure to evacuate the data from the disks before you repartition with fdisk! You will lose data. Thankfully I had a couple of spare drives from work that I could dump data on temporarily.
  12. $ sudo fdisk /dev/sdb
  13. In fdisk, the command sequence was "d n p 1 (default start) (default end) t fd w" This is short for delete current partition (only 1 in my case), create new partition, primary, id=1, use all space, change type to Linux RAID Autodetect, write partition table and exit.
  14. Use mdadm to create the RAID5 virtual device
    $ sudo mdadm --create /dev/md0 --level=5 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
  15. Read the description of all running raid instances using mdadm
    $ sudo mdadm --detail --scan
    This will return an output like:
    ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 spares=1
      UUID=b144b150:b3b4ff34:2bababc5:c86c0f3a
  16. Copy and paste that information into /etc/mdadm/mdadm.conf 
  17. Initilize md0 for LVM
    $ sudo pvcreate /dev/md0
  18. Create a volume group
    $ sudo vgcreate vg1 /dev/md0
  19. Before we can create a logical volume that can be mounted, we need to know the available space in the array
    $ sudo vgdisplay vg1 | grep "Total PE"
    Total PE             476932
  20. Now create the logical volume
    $ sudo lvcreate -l 476932 -n -lv1 vg1 /dev/md0
    Logical volume "lv1" created
  21. Format the logical volume with the file system of choice. I opted to use ext4 since that's what ubuntu chose for /
    $ sudo mkfs.ext4 /dev/vg1/lv1
  22. Make a mount point
    $ sudo mkdir /data/external
  23. Add an entry to fstab
    $ sudo nano /etc/fstab
    /dev/mapper/vg1-lv1  /data/external    ext4    errors=remote-ro    0    1
  24. Mount the new volume and verify
    $ sudo mount -a
    $ df -h
    /dev/mapper/vg1-lv1    1.9T   28G  1.7T   2% /data/external
Simply right?

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 2 - Installing Ubuntu Server 12.04)

Before I can jump in and start configuring Ubuntu Server on my LX195 there is some prep work required.

First and formost is migration of data. This is one of the more time consuming aspects of the task as the LX195 isn't speedy to begin with and only supports USB 2.0 for external drives. My first pass was to purge data that would not be making the journey. Its really amazing how much of a digital pack rat one can be. Once legacy and unneeded data is gone, I used the tools in the Home Server Console to migrate the shared folders that remains off the single internal drive and onto the available external drives attached to the server.

While the server busied itself moving bits around, I downloaded the latest version of Ubuntu Server (12.04 LTS at the time of this project). My primary computer is a MacBook Air, so using dd at the command line I wrote the ISO to a 1GB flash drive I had laying around.

1. Use diskutil to list the available disk and identify which /dev/disk# is the target flash drive
$ diskutil list
2. Use dd to bitwise copy the ISO onto the flash drive of choice
$ sudo dd if=./ubuntu-12.04-server-amd64.iso of=/dev/rdisk1
Note that you should you want a progress bar to add some sanity to this process, there is a handy applet called 'pv' that's available for Linux and other platforms. For the Mac it can be installed via Mac ports. The command syntax becomes:
dd if=ubuntu-12.04-server-amd64.iso | pv -p -t -r -e -b -s `stat ubuntu-12.04-server-amd64.iso | awk '{ print $8 }'` | sudo dd of=/dev/disk1
The resulting output resembles:
$ sudo dd if=ubuntu-12.04-server-amd64-extracted.img.dmg | pv -p -t -r -e -b -s `stat ubuntu-12.04-server-amd64-extracted.img.dmg | awk '{ print $8 }'` | sudo dd of=/dev/disk1
 563MB 0:15:39 [ 722kB/s] [====================================>         ] 82% ETA 0:03:22
Once the data migration is complete and the flash drive is ready it's time to get the screw driver. Before a custom OS can be installed on the LX195, it needs to be put into debug mode. This can be done by closing the open J2 jumper. See http://www.mediasmartserver.net/forums/viewtopic.php?f=21&t=5422 for pictures and other relevant information.

There are two ways to manage the actual install for Ubuntu Server. The more complicated method is to preseed the ubuntu install (see: https://help.ubuntu.com/12.04/installation-guide/amd64/preseed-using.html#preseed-auto). Alternatively a keyboard and monitor can be used in conjunction with a debug board (see: http://www.mediasmartserver.net/forums/viewtopic.php?f=6&t=8066). As I still had a debug board from my WHS2011 install adventure I opted to take the easy path.

For the actual install of Ubuntu Server 12.04, I stuck with the default install options until prompted for automatic updates. As this machine is a home server and not something truly important I opted to enable automatic security updates.

At the end of the install, Ubuntu prompts for additional modules. As this is going to be a headless server I chose to install OpenSSH during the install. If you want to skip this and install OpenSSH after the first boot, run the following command:
sudo apt-get install openssh-server
Regardless of how OpenSSH is installed, the default config will not do for anyone remotely conerned with security. As such the next thing on the list is to reconfigure OpenSSH to lock down access. First create a backup of the existing configuration file, just in case.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.old
Then edit is with the console based text editor of your choice.
sudo nano /etc/ssh/sshd_config
In the configuration file, edit, uncomment and/or add the following:
PasswordAuthentication no
PermitRootLogin no
AuthorizedKeysFile      %h/.ssh/authorized_keys
I've been using SSH for a while so I already had an extra RSA key pair I could use. After saving the sshd configuration I created the authorized_keys file and added my public key to it. Once that was done I restarted sshd with init.d and tested the connection.
$ sudo /etc/init.d/ssh restart
From my MacBook:
$ ssh -i ~/.ssh/id username@homeserver.home.local
Take a look at http://www.debuntu.org/ssh-key-based-authentication-p2 and http://www.debuntu.org/ssh-key-based-authentication-p2 for more guidance on key based authentication for OpenSSH

Lastly for good measure I updated the server manually.
$ sudo apt-get update
$ sudo apt-get upgrade
 That's enough for one night. Tasks for tomorrow include evacuating the data from the external USB drives, configuring the 3 1TB drives as a RAID5 using LVM and ensuring the three will mount correctly on a reboot. Time permitting, I will also start work on the install and configuration of Netatalk and Samba and creation of user accounts for family members. Once those tasks are complete, it'll be time to install java, serviio and beyondupnp.

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 1 - Introduction)

Never content to leave well enough alone, I decided to take a good hard look at my windows home server and see if I could make better use of that hardware.

I have an aging HP Media Smart LX195 running Windows Home Server 2011. This wasn't a supported update from HP, but since when have I ever let that slow me down?

The system came with an Atom N270 on board and I've upgraded it with 2GB of RAM, 1 internal 1TB drive and 3 external 1TB drives. Last years OS X 10.7 upgrade left me without the use of this server for time machine based backups but it still serves as a reliable and quite media storage for my music and movie libraries. In addition to acting as basic file storage I also run Kiwi syslog server, Serviio DNLA server and BeyondUPNP services on this machine.

All of this I can do, and probably better, on a *nix based OS, without the overhead a GUI provides. I consider this a personal challenge and a good learning experience. As such the next few posts will walk through my experience installing and configuring:
  1. Ubuntu Server 12.04
  2. RAID5 with LVM
  3. Netatalk 3.0
  4. Samba
  5. Serviio 
  6. BeyondUPNP
It's worth mentioning that while BeyondUPNP is a great tool for accessing your DNLA based media servers from the internet, I prefer to use it as a LAN proxy and keep my firewall as closed as possible. It allows me to establish an OpenVPN connection from my Android device(s) and access the media content as if I was sitting at home.

Note: One thing that worked really well for me throughout this process was staging the whole thing in a virtual machine. My laptop is a MacBook Air, so using VMware Fusion I was able to create a small virtual machine running Ubuntu Server and test almost all of the stages of the build. When it came time to bring down the home server and wipe it, most of the hard work was done and I was simply following my own instructions.

Wednesday, July 18, 2012

I wrote it down so I wouldn't have to remember!

Maybe I'm getting old and can't remember things like I used to. Maybe I've been in the tech field too long and have KCS in my blood. Maybe I figure that i never find exactly the answer I'm looking for and I want to share my findings open source style with the rest of the world.

In any event I'll be converting this old blogger account into a personal knowbase of sorts for things I stumble on and don't want to have to re-google later.

HOWTO: Extract an OS X mountable ISO from Linux Hybrid Boot ISO

Problem: unable to mount Ubuntu 12.04 LTS ISO image on a Mac running OS X 10.7.x

Cause: Something in OS X does not like the way the hybrid ISO image was created.

Solution:

Source: http://ubuntuforums.org/showpost.php?p=11654292&postcount=43

1. Open the Disk Utility gui application. (Easy way to find it: Search using spotlight.)
2. Drag the original .iso from Finder into the images section of Disk Utility (on the left side underneath the mounted drive list), and then double click on it there. A faded "diskNs1" should appear underneath it, and a dialog box will say the disk is not mountable. The "diskNs1" is the embedded .iso.
3. Run "sudo dd if=/disk/rdiskNs1 of=./ubuntu-extracted.iso bs=1m" to copy out the working .iso image

This resulting ISO image can then be written to disk or USB key.