Wednesday, November 6, 2013

How to Install Optware and SAMBA on the Pogoplug

In this tutorial, I'm going to show you how to install optware and samba on your Pogoplug to create a cheap and simple NAS.

Last Updated - 4/22/2015

Why do you want to do this?

I'm a big fan of the my.pogoplug.com service that comes with the Pogoplug. It allows you to easily access your files from the web or your mobile device and even allows you to share your content with friends and family. Not to mention, the great automatic iPhone/Android photostream backup feature and remote mp3 playback.

However, one thing the Pogoplug lacks is a simple and fast way to access your content on your local network; you need to install additional software on your MAC/PC and content can be slow to access and upload because the data go through the Pogoplug cloud.

This tutorial will show you how to extend the functionality of the Pogoplug (existing my.pogoplug.com service is not affected), adding SAMBA (Windows File Sharing) support which doesn't require additional software to be installed on your PC/MAC and faster access to your content.

What is optware?

Optware is a package manager that allows you to install additional software on your embedded linux device such as the Pogoplug (think of it as a free little "App Store"), while maintaining the stock my.pogoplug.com functionality.

Requirements:

1) Pogoplug - V2 such as the E02, V3 (oxnas) such as the Pogoplug P21/P22/Pogoplug Pro or the V4, also known as the Series 4 and Mobile. Pretty much any existing Pogoplug model is supported.
2) USB Hard Drive - 2TB or less recommended.

Outline of Steps:

1) SSH into Pogoplug
2) Partition and Format USB Hard Drive
3) Install Optware
4) Install SAMBA
5) Make sure everything works after a reboot

SSH into Pogoplug

In some cases, you can directly ssh into your Pogoplug. In other cases, you have to activate the Pogoplug on my.pogoplug.com and then enable SSH via their website. For the Pogoplug E02 (and potential other models), if you haven't activated your Pogoplug (new out of the box), you should be able to SSH into it using root/ceadmin as the username/password. If you have activated it, you'll need to enable SSH via my.pogoplug.com and set your own username and password. On the Pogoplug Mobile, I had to activate and then enable SSH. If you don't see the option to enable SSH, try rebooting your Pogoplug.

For the Pogoplug V4 (Mobile and Series 4) and the Pogoplug Pro, you can use the backdoor method documented in my other blog post here versus activating on the my.pogoplug.com site - http://blog.qnology.com/2014/07/hacking-pogoplug-v4-series-4-and-mobile.html.

SSH into Pogoplug using Putty or similar app

Partition and Format USB Hard Drive

Plug in your USB Hard Drive to your Pogoplug.

#stop my.pogoplug.com service
killall hbwd

#partition drive
#create two partitions, a small 4GB partition
#for optware and the rest for your data
busybox fdisk /dev/sda

# Type in the following commands to erase
# and re-partition the USB Hard Drive 
#(WARNING - USB HARD DRIVE WILL BE COMPLETELY WIPED)

# p # list current partitions
# o # to delete all partitions
#
# Create 1st Partition for Optware
#
# n # new partition
# p # primary partition
# 1 (one) # first partition
# <enter> # default start block
# +4G # to create a 4GB partition

# Create 2nd Partition for Data
#
# n       # new partition
# p       # primary partition
# <enter> # default to second partition
# <enter> # default start block
# <enter> # default end block #use the whole flash drive
# w       # write new partition to disk

#download mke2fs to format partition
cd /tmp
chmod +x mke2fs

#format and label partition
./mke2fs -L optware -j /dev/sda1
./mke2fs -L data -j /dev/sda2

#remount root to be writable
mount -o remount,rw /

#create /opt folder
mkdir /opt

#mount usb drive as /opt
mount /dev/sda1 /opt


Install Optware

###########################################
# Install optware ipkg (package manager)
# Assumes /opt is mounted at this point
###########################################

#download ipkg
cd /opt
tar -xzvf plug.tar.gz
rm plug.tar.gz

# Setup profile
cd /etc
chmod 755 profile
source /etc/profile

#update available packages
ipkg update


Install Samba

ipkg install samba36 libnsl nano

#download example smb.conf
cd /opt/etc/samba

#Edit smb.conf (optional)
#to add additional samba shares
#nano /opt/etc/samba/smb.conf

#Start SAMBA
/opt/etc/init.d/S08samba start

You should now be able to access your Pogoplug's USB Hard Drive by \\pogoplug\usb or \\IPAddress\usb


Make sure everything works after a reboot

#backup original rcS startup file
#restore the rcS.original file to revert
cp /etc/init.d/rcS /etc/init.d/rcS.original

#download mount script and make it executable
cd /etc/init.d
chmod +x mount_optext3

#add mount script to rcS file so it 
#runs automatically after a reboot
#this script will mount /opt
#the data partition is automatically mounted by the pogoplug software
echo "/etc/init.d/mount_optext3" >> /etc/init.d/rcS

#start samba on reboot
echo "/opt/etc/init.d/S08samba start" >>  /etc/init.d/rcS

reboot

Adding an Additional/Second USB Hard Drive

1) Attach additional USB Drive to Pogoplug.

2) Partition additional USB Drive. See "Partition and Format USB Hard Drive" section, but just create one partition.

  busybox fdisk /dev/sdb

3) Format and Label additional USB Drive

    ./mke2fs -L data2 -j /dev/sdb1

4) Remount root to be writable

   mount -o remount,rw /

4) Edit the smb.conf file and add an additional section that is similar to the "[usb]" section.

   nano /opt/etc/samba/smb.conf

[usb2]
  path = /tmp/.cemnt/mnt_sdb1/
  read only = no
  public = yes
  writable = yes
  guest ok = yes

5) Reboot. You should now be able to access the additional drive as \\pogoplug\usb2


Miscellaneous Notes

On the Pogoplug V2 (E02) and Pogoplug v4 (Mobile and Series), you can actually use one of the internal flash partition for /opt. Only recommended for more advanced users.

Edit 4/22/2015 - The below instructions for the Pogoplug V4 will also work on the Pogoplug Pro.

Pogoplug V4 - Optware and SAMBA on NAND (Internal Flash)

The below instructions are for the E02.

The E02 has a small partition (~90MB) that isn't used - MTD3, which is just enough for Optware and SAMBA.

####################################
# Pogoplug V2 - Use internal flash partition for /opt
####################################
#remount root to be writable
mount -o remount,rw /

#create /opt folder
mkdir /opt

#erase mtdblock3
cd /tmp
wget http://download.doozan.com/uboot/flash_eraseall
echo "/dev/mtd0 0xc0000 0x20000 0x20000">/etc/fw_env.config
/tmp/flash_eraseall /dev/mtd3


#mount internal flash partition as /opt
mount /dev/mtdblock3 /opt



Changes to above instructions if using internal flash for /opt
- only one partition needed on your USB hard drive
- "Install Optware" and "Install Samba" instructions unchanged
- modify the smb.conf file for correct partition
     path = /tmp/.cemnt/mnt_sda1/
- In the "Make sure everything works after a reboot" section, you don't need the mount_optext3 script
- Add the "mount /dev/mtdblock3 /opt" command before the "/opt/etc/init.d/S08samba start" command in the /etc/init.d/rcS file.

Troubleshooting

/opt not mounting - check the content of the /etc/init.d/rcS file and make sure /etc/init.d/mount_optext3 is called. Also double check that the /etc/init.d/mount_optext3 file exist and is executable. Minimize the number of attached USB drives

samba not working (\\pogoplug\usb not accessible) - double check that /opt is mounted correctly. Make sure that "/opt/etc/init.d/S08samba start" is the last line in the /etc/init.d/rcS file. Verify that the /opt/etc/samba/smb.conf exist.

data partition not mounted - the data partition is automatically mounted by the pogoplug software to something like /tmp/.cemnt/mnt_sda2. Run the "df -h" command to see what's mounted. Check the /etc/init.d/rcS file to make sure the pogoplug software start command ("/etc/init.d/hbmgr.sh start") isn't commented out (begins with #).


Future Updates

I'll be flushing this tutorial with additional howtos in the near future. Please leave a comment and what you would like to see added.