Raspberry Pi Private Cloud (NAS), Time Machine OSX (Yosemite)

Raspberry Pi Private Cloud (NAS), Time Machine OSX (Yosemite)

The intention is to create a private cloud at home (Within the range of your router). The cloud hosts the TIme Machine and generic storage area for photos and documents. The generic storage should be read/write compatible to Linux and OSX.

The following are required:

Raspberry Pi (Model B) ( Running Raspbian Wheezy, connected to the network, with keyboard and monitor). The procedure to get your PI running is available here.

  1. External hard disk with power supply. (I have : Verbatim 1 TB)IMG_2617

I have two laptops one is a MacBook Pro ( running OSX Yosemite ) and the other is a Toshiba (running Fedora 20).

Procedure on the Mac : Connect the external hard disk to the MacBook Pro. I have made two partitions of size 333 GB (partition name : timemachine )and 666 GB (partition name : cloud) on my external Hard Drive. The partitioning is done using the “Disk Utility” application (OSX). The file system type chosen is “Mac OS extended (journaled)” (HFS+) for both the partitions.

Run the below command on the terminal to make the OSX recognize non AFP volumes.

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Procedure on the Pi :
Now connect the External Hard Drive to the Pi.
Install the hfs+ driver.

sudo apt-get install hfsprogs

Create two directories and mount the drives. In my case sda1 was created for Time Machine and sda2 for the generic storage. To find out device names of the external hard drive run the command “lsblk”.

sudo mkdir /home/timemachine
sudo chmod 777 /home/timemachine
sudo mkdir /home/cloud
sudo chomd 777 /home/cloud
sudo mount -t hfsplus -o remount,force,rw /dev/sda1 /home/timemachine
sudo mount -t hfsplus -o remount,force,rw /dev/sda2 /home/cloud

Update the fstab so that the mount happens automatically during boot.

sudo echo "/dev/sda1       /home/timemachine hfsplus  force,rw  0  0" >> /etc/fstab
sudo echo "/dev/sda2       /home/cloud   hfsplus    force,rw 0  0" >> /etc/fstab

Create a user (For egs: cloud), a group (For egs : mycloud) and choose a password (and remember them!!!).

sudo useradd cloud
sudo groupadd mycloud
sudo useradd -gmycloud cloud
sudo passwd cloud
sudo chown cloud /home/timemachine
sudo chown cloud /home/mycloud

Install samba and netalink:

sudo apt-get install samba samba-common-bin
sudo apt-get install netatalk

Configure samba client:

sudo nano /etc/samba/smb.conf

Add the below text at the end of the file. “valid users” should have the name of the group you created:

[cloud]
  comment = Cloud
  path = /home/cloud
  valid users = @mycloud
  read only = no

Configure the netatalk.

sudo nano /etc/afp.conf

Add the below text to afp.conf:

[Global]
 mimic model = TimeCapsule6,106
 log level = default:warn
 log file = /var/log/afpd.log

[TimeMachine]
 path = /home/timemachine/
 valid users = cloud
 time machine = yes
sudo echo "/home/timemachine \"Time Machine\" options:tm" >> /etc/netatalk/AppleVolumes.default

restart samba and netatalk and make it start at boot.

sudo service netatalk restart
sudo /etc/init.d/samba restart
sudo update-rc.d netatalk defaults

Now our private cloud is ready.

To access the private cloud from MacBook Pro:
To access the “general storage” disk on our private cloud open the Finder and select “connect to server”.
Screen Shot 2014-11-05 at 21.20.10
Next type in the IP address of the Raspberry Pi (The ifconfig command on the Pi should display the IP address). Do not forget the prefix “smb://” before the IP address. Type in the user name and the password that was created previously.

Screen Shot 2014-11-05 at 21.21.21

For time machine :
To access the “Time Machine” disk on our private cloud open the Finder and select “connect to server”.
Screen Shot 2014-11-05 at 21.20.10
Next type in the IP address of the Raspberry Pi (The ifconfig command on the Pi should display the IP address). Do not forget the prefix “afp://” before the IP address. Type in the user name and the password that was created previously.

Screen Shot 2014-11-06 at 21.35.22
Open Time Machine and press “select disk”. The Time Machine created on our private cloud should be visible. Now you can backup your Mac to this Time Machine Disk on the cloud. It should start creating a sparse bundle. The first backup takes a long time (more than a day) but the next ones will be faster.

Access the private cloud from Fedora :

Open  “Files” window and click on “connect to server”.

Screenshot from 2014-11-07 08:47:44

Put in the Raspberry Pi IP address followed by “smb://”. Type in the user name and the password that was created previously.

Raspberry Pi as a wi-Fi Access point using Joy-IT

These are steps I followed to make the Raspberry Pi act as a Wi-Fi access point.

I am using a Raspberry Pi B with Joy-iT WLAN stick inserted into one of the USB ports.

I have the ethernet cable connected to the Pi for the incoming internet connection.

The OS running on the Pi is the Raspbian Wheezy.

I have connected the Pi to my TV using the HDMI and I use the Microsoft Wireless Keyboard 800 as the input device.

1) Remove existing hostapd if any.

sudo apt-get autoremove hostapd

2) Get the modified RealTek driver and extract it. Ensure that the ethernet cable is connected to the Pi.

Thanks to : http://jenssegers.be/blog/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi.

wget https://github.com/jenssegers/RTL8188-hostapd/archive/v1.1.tar.gz
tar -zxvf v1.1.tar.gz

3) Build the driver that was downloaded in the previous step. This step takes some time. initially it may seem that nothing is happening but after some time the compiler CC messages appear.

cd RTL8188-hostapd-1.1/hostapd
sudo make

4) Install the driver.

sudo make install

5) Edit the /etc/udhcpd.conf using nano.

sudo nano /etc/udhcpd.conf

Change the contents to :

start 192.168.42.2 
end 192.168.42.20
interface wlan0
remaining yes
opt dns 8.8.8.8 4.2.2.2
opt subnet 255.255.255.0
opt router 192.168.42.1
opt lease 864000

5) Edit the /etc/default/udhcpd using nano.

sudo nano /etc/default/udhcpd

comment the DHCPD_ENABLED=”no” (i.e. put the hash at the beginning of the line):

#DHCPD_ENABLED="no"

6) Run the following command. Gives a static IP to the Pi.

sudo ifconfig wlan0 192.168.42.1

7) Make the above step automatic at boot. Edit the /etc/network/interfaces.

sudo nano /etc/network/interfaces

Replace the line iface wlan0 inet dhcp to:

iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0

If the line iface wlan0 inet dhcp is not present, add the above lines to the bottom of the file.
Comment the below lines (i.e. put the hash at the beginning of the line).

#allow-hotplug wlan0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet manual

8) Edit or create the /etc/hostapd/hostapd.conf .

sudo nano /etc/hostapd/hostapd.conf

interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Choose ssid and wpa_passphrase of your liking. This will be the name and the password of the Wi-Fi access point created by the Pi.

9) Make the configuration file created in the previous step active. Edit /etc/default/hostapd

sudo nano /etc/default/hostapd

Change the

#DAEMON_CONF="" 

line to

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Do not forget to remove the # at the beginning of the line.

10) Enable IP forwarding in the kernel.

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" 

Edit the /etc/sysctl.conf file to make this step automatic at boot.

sudo nano /etc/sysctl.conf

Add the below line at the bottom of this file.

net.ipv4.ip_forward=1

11) Run the below commands to enable NAT.

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Make this step automatic at boot.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

12) Edit /etc/network/interfaces.

sudo nano /etc/default/hostapd

Add the below line at the bottom of this file.

up iptables-restore < /etc/iptables.ipv4.nat

13) Run the following commands as the last step to make the Pi an Acess point.


sudo service hostapd start
sudo service udhcpd start

Make the Pi an Access Point right from its boot.


sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable

The above steps make the Pi a decent access point. Sometimes there have been issues where the PI stops being an Access Point and I need to run the below commands to restart the hostapd and udhcpd.


sudo service hostapd restart
sudo service udhcpd restart

The steps I have followed are from the following sources:

http://elinux.org/RPI-Wireless-Hotspot

http://jenssegers.be/blog/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi