Thursday, February 2, 2012

The Pogo Plug - A Great Embedded Linux Server

I recently found the Pogo Plug on sale at my local computer store. After doing a little bit of research I discovered that this little NAS device can make a great, low power embedded Linux Server. In this tutorial I will explain how to get Arch Linux up and running on the pogo plug, how to install Apache, PHP, and Samba, as well as how to hack together Hamachi so that you can have a secure tunnel to your pogo plug from anywhere in the world.





First of all you need to understand that there are several different models of Pogo Plug and this guide is ONLY for the E-02 Model. you can check the model number of your pogo plug by looking at the sticker on the bottom.
If you have a different model, don't despair, just head on over to archlinuxarm.org to get a guide for your device.


Installing:


The first thing you need to do is enable SSH on your PogoPlug. Plug your device into the wall and into you router and head on over to pogoplug.com/activate. After you have set up an account, you need to go to the security tab for your PogoPlug and select the SSH access option. You will be prompted to enter a password. Once you have enabled SSH you can close the pogo plug webpage and look up the internal IP address of your pogo plug (you will likely need to look at the DHCP list on your router's config page). Once you have determined your pogo plug's IP address, you can connect to it using putty or your favorite ssh client. Note that your username will be root and the password will be the one you setup on the pogo plug webpage.


Now that you have connected to your PogoPlug, you will first need to disable the pogo software.


Command
killall hbwd

Next, make sure you disconnect ALL hard drives and USB flash drives except for the one you want to install linux to. All data on any connected drives could be destroyed, so it's best to remove everything. All the data on your target drive will also be destroyed so backup any data you may have on your target drive.


Now, you will need to download the bootloader which will be used to start Linux:


Commands
cd /tmp
wget http://jeff.doozan.com/debian/uboot/install_uboot_mtd0.sh
chmod +x install_uboot_mtd0.sh
./install_uboot_mtd0.sh

now that the bootloader is installed we will format the flash drive:


Commands
/sbin/fdisk /dev/sda

**this is assuming that you only have the one flash drive inserted. if you insist of leaving multiple drives attached, make sure you are using the correct drive path


now that fdisk has been launched:

  • type o to clear all partitions
  • type n to create a new partition
  • type p to create a primary partition
  • type 1 to make it the first partition
  • hit enter to accept all the default options
  • exit by typing w

now we will make an ext2 filesystem in the new partition


Commands
wget http://archlinuxarm.org/os/pogoplug/mke2fs
chmod 755 mke2fs
./mke2fs /dev/sda1
mkdir usb
mount /dev/sda1 usb

Now that we have created a compatible partiton, we will need to download and install the ArchLinux distribution we will be installing.


Commands
cd usb
wget http://archlinuxarm.org/os/ArchLinuxARM-armv5te-latest.tar.gz
tar -xzvf ArchLinuxARM-armv5te-*.tar.gz # This will take a long time
rm ArchLinuxARM-armv5te-*.tar.gz
sync # Takes a while when using a flash drive

at this point everything should be installed... unmount your flash drive and reboot


Commands
cd ..
umount usb
/sbin/reboot

After about a min or two your device should be ready to use. You can now ssh into it (the IP may have changed) using the username root and password root

At this point you should change your password:


Commands
passwd
enter new password

At this point linux has been installed and you can go ahead and use it as you see fit, or continue following this guide to install PHP, Apache, Samba, and Hamachi


Installing PHP and Apache


Install Apache using the following command:


Commands
pacman -S apache php php-apache

pacman -Sy lynx

By default a user called 'http' may not have been created so use the following command to create one:

Commands
useradd -d /srv/http -r -s /bin/false -U http

If it says the user already exists, then you're good to go and needn't worry


now test apache and make sure it starts:
Commands
/etc/rc.d/httpd start

browse to the IP address of your pogo in a web browser and you should see the default webpage.


Now it's time to get php working.
Edit the http.conf file:


Commands
nano /etc/httpd/conf/httpd.conf

Add the following line of code at the END of the "Load Modules" section

LoadModule php5_module modules/libphp5.so

Add the next line of code at the END of the "include" section

Include conf/extra/php5_module.conf

Uncomment the following lines:
TypesConfig conf/mime.types

MIMEMagicFile conf/magic

(it should be found after IfModule mime_module)

Now edit /etc/httpd/conf/mime.types:
Commands
nano /etc/httpd/conf/mime.types

and add this line:
application/x-httpd-php php

now restart apache to make sure it starts:
Commands
rc.d restart httpd

Now make a sample php file with some script it it and place it in "/srv/httpd" and then access it through your web browser


Installing Samba

Samba will allow you to share folders and files over your local network so that Linux, Windows and OSX computers can access them


Commands
pacman -S samba

cp /etc/samba/smb.conf.default /etc/samba/smb.conf


At this point Samba can be started with the command
Commands
rc.d start samba

In order to make changes to shared folders you will need to make changes to your configuration file found at "/etc/samba/smb.conf". There is plenty of information online about configuring Samba, so I won't cover it in this post


Installing Hamachi

Hamachi is a zero-configuration VPN client. It allows computers connected to physically different LAN's across the Internet appear to each other as though they were on the same LAN.


Unfortunately Hamachi is far from stable on the PogoPlug, I have managed to hack it together, but please note that the method I am about to describe is far from perfect. If you have a better method of installing andf using Hamachi on this unique platform please Contact Me


OK, with the discalmer behind us let's get started. Download the older version of hammachi for arm devices and install it:

Commands
wget http://files.hamachi.cc/linux/nokia-770/hamachi-0.9.9.9-20-lnx-n770.tar.gz

tar -xzvf hamachi-0.9.9.9-20-lnx-n770.tar.gz

cd hamachi-n770-0.9.9.9-20

./install

Now that Hamachi is installed we need to start it:


Commands
tuncfg

hamachi-init

hamachi start

hamachi login

hamachi join ''

hamachi go-online ''


At this point you should be able to access your PogoPlug through the Hamachi network, however if you have the same problem as me, then the connection becomes stale after a few min of inactivity. The solution I have come up with is to continuously ping each client in your Hamachi network using a shell script that runs at start-up. If you don't notice your Hamachi connection becoming stale, then you don't need to make this script.


the following shell script will automatically configure your VPN tunnel, launch Hamachi, and continuously ping each client in the network. You will need to edit it according the the IP addresses in your network:


Shell Script

#!/bin/bash

tuncfg

hamachi start

while [ 1 ]
do

ping - c 2

ping -c 2

....etc....

sleep 15

done

you will need to add this script to your start-up by editing rc.conf:

Command
nano /etc/rc.local

and add the path to your script

If you have followed this guide, then you should have a PogoPlug that is running Arch Linux with Apache, PHP, Samba, and Hamachi. There is a wealth of information online regarding Arch Linux, just head on over to the arch wiki for more information.