Monthly Archives: January 2017

Raspberry Pi as a Mac OSX file server

Update 1/5/2017, I’ve made configuration adjustments to /etc/netatalk/afpd.conf (2nd section below) and /etc/netatalk/AppleVolumes.default (third section below). I also added a section to enable the firewall.

Update 1/4/2017, previously I was unable to make this work with Samba (Windows file sharing for Linux) but after I rebuilt the Pi and followed my own instructions I was able to make this work.

This time I want my Raspberry Pi server to behave as another Mac sharing its files. It is incredibly easy. I use the latest image of Raspberry Pi Raspbian OS Jessie with PIXEL dated 2016-11-25.

First, we install netatalk (this software provides the functionality of an AFP file server used by Macs to share files).

sudo apt-get update
sudo apt-get install netatalk
sudo service avahi-daemon restart
sudo service netatalk restart

Second, I adjust the /etc/netatalk/afpd.conf file and use the following line at the end

– -tcp -noddp -uamlist uams_dhx2.so -nosavepassword -mimicmodel RackMac

Third, now from my Mac’s Finder I can see my raid5 tinypute appear as a shared PC, I can click it, and “Connect As” my tinypute user “pi” using its password and connect to pi’s home directory.

Fourth, if I wanted to add /mnt/raid5/storage to Mac’s file share I would edit /etc/netatalk/AppleVolumes.default. At the end of the file add the following

/mnt/raid5/storage  “RAID 5 Storage”   dperm:0750 fperm:0660 umask:7007

Then update the configuration of /mnt/raid5/storage so users can access it

sudo chgrp -R users /mnt/raid5/storage  #change the group to users (pi is a member of it)
sudo chmod -R ug+r+w,o-rwx /mnt/raid5/storage # change permissions (so pi can access it)

Fifth, install ufw if not already

sudo apt-get install ufw
sudo ufw allow 548
sudo ufw allow 5353

Sixth, restart the whole stack

sudo service avahi-daemon restart
sudo service netatalk restart
sudo service smbd restart

That’s it!

 

Advertisements

Raspberry Pi 2B RAID 5 build – Part 4 – Final

Now we install Samba which is a file sharing program for Linux, it is Linux’s implementation of the SMB file protocol used by Windows. Once installed we can connect to shared folder on the tinypute from other machines.

First, install Samba:

sudo apt-get install samba
sudo apt-get install libpam-smbpass

Second, configure /etc/samba/smb.conf as follows:

# Maximum number of usershare. 0 (default) means that usershare is disabled.
usershare max shares = 100 #Uncomment this line (remove the first character “;”)

[homes]
   comment = Home Directories
   browseable = no
# By default, the home directories are exported read-only. Change the
# next parameter to ‘no’ if you want to be able to write to them.
   read only = no

Third, create a folder for users to share

sudo mkdir /mnt/raid5/storage
sudo chmod ug+rwx /mnt/raid5/storage

Fourth, configure smb to share the folder, add the following line to /etc/samba/smb.conf

[storage]
   comment = RAID 5 storage folder
   path = /mnt/raid5
   guest ok = no
   browseable = yes
   create mask = 0600
   directory mask = 0700

Restart the smbd service

sudo service smbd restart

Fifth, we install ufw (uncomplicated firewall) so we can open ports required by Samba.

sudo apt-get install ufw
sudo ufw allow 135
sudo ufw allow 137
sudo ufw allow 138
sudo ufw allow 139
sudo ufw allow 445
sudo ufw enable

Sixth, now we connect to the share we created before in /mnt/raid5 (i.e. storage folder)

Before connecting the user that will access the share must be created.

sudo smbpasswd -a pi #pi is the user that will connect to the shared folder

smbpasswd

The shared folder can be connected from another PC now.

On my Mac OSX Yosemite using Finder -> Go -> Connect To Server and enter smb://raid5/storage. A password prompt will be provided, enter as Registered User pi with the SMB password you provided before.

That’s it! New folders can be created, renamed, deleted. The same goes for files, you can edit them too.

Raspberry Pi 2B RAID 5 build – Part 3

Alright lets continue with our stock Raspberry Pi – Jessie build. It’s a long post, hang on to the handle bars!

First, install mdadm using the following commands:

sudo apt-get update #Updates our repository list
sudo apt-get install mdadm #
Accept the prompt during the installation.

Second, we’ll assume the disks are intended for a built from scratch RAID 5 array, so we’ll destroy all data on the disk (technically all we’re doing is remove previous partition table and formatting information, it could still be recovered  with data recovery software, many available on the Internet).

We’ll also assume 3 disks. More can be used, but not less than 3 for a RAID 5 array, that’s a requirement. In my case I have 3 powered external USB disks directly plugged in to the Pi.

Third, identify the disks using lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT 

lsblk

Here are my three disks, sda1, sdb1 and sdc1 (a through c denoting the sequence of the disks). My disks are partitioned already in the above picture (we’ll talk about that below) so they have numeric sequencing for their disks (the number 1 as all use the first partition). If they never partitioned then you’ll see sda, sdb, sdc and need to partition them before use.

Be very careful and verify that the disks identified are indeed disks that you intend to use! Once we proceed all previous data will be erased!

Fourth, we’ll start by partioning them using the command sudo parted. Once launched you’ll see a prompt with (parted). We’ll enter the following commands at this prompt. Start creating the partitions.

select /dev/sda
mklabel gpt
mkpart primary ext4 1049KB 3TB

select /dev/sda selects the first disk to be partitioned.
mklabel creates a partition table of type gpt (specifically needed for Linux and large multi Terabyte disks).
mkpart creates the partition. In this case I am starting at 1049KB (never mind the reasoning …) and ending at 3TB as that is the size of the disks I have (a 3TB external USB drive).

Proceed to the other disks (sdb and sdc replacing sda) the same way.
Enter quit to exit out of parted.

Fifth, we create the RAID 5 array using the following commands. This will prevent from the array created with spares (which we don’t want, we want to use all the disks for the maximum capacity we can get, we’re already losing 1/3 of the total disk space for parity information).

sudo mdadm –create –verbose –force –assume-clean /dev/md0 –level=5 \
–raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1

Check that they’re running with the following command

cat /proc/mdstat

You should see:

mdstat

Lets create the filesystem (this is what most resembles the Format command in Windows).

sudo mkfs.ext4 -F /dev/md0

You should see:

mkfs

It is now ready to mount so we can access it

sudo mkdir -p /mnt/raid5

You can now mount it using

sudo mount /dev/md0 /mnt/raid5

and see it’s content by

ls -al /mnt/raid5

mount

You can also confirm its capacity by (note /dev/md0 with 5.5T of size).

df -h -x devtmpfs -x tmpfs

mount

We’ll save the configuration in /etc/mdadm/mdadm.conf so it starts up at boot time automatically.

sudo mdadm –detail –scan | sudo tee -a /etc/mdadm/mdadm.conf

Update the initial file system (Raspberry Pi uses a RAM disk image when booting up and we want to include our array).

sudo update-initramfs -u

We’ll add the drive array to our filesystem table also so it will be mounted automatically when booting up.

echo ‘/dev/md0 /mnt/raid5 ext4 defaults,nofail,discard 0 0’ | sudo tee -a /etc/fstab

Finally confirm the array gets mounted by rebooting the Pi.

sudo reboot

You should see the following when it has booted.

ls

If “lost+found” entry isn’t listed there is more work to do (which I had to do with my Pi).

Edit /etc/rc.local file

sudo pico /etc/rc.local

Add the following line right before the line containing “exit 0”

/usr/local/bin/raid5 &

Then we create a shell script at /usr/local/bin/raid5

sudo pico /usr/local/bin/raid5

Enter the following lines in it

#!/bin/bash
# Sleep for 20 seconds after boot to make all the disks available for array assembly
sleep 20
sudo mdadm –assemble –scan # Assemble the RAID 5 array

Then set the execute permissions for the file

sudo chmod +x /usr/local/bin/raid5

Now reboot and the raid array should mount automatically. If it still doesn’t then add the following to /usr/local/bin/raid5

mount -a

Once mounted run the following command so I can start populating the /mnt/raid5 folder.

sudo chmod ug+wrx /mnt/raid5

That’s it!

Next I’ll setup samba (SMB Windows shares for Linux) and share out the folder so I can connect to it from other machines …

Next move on to part 4, the end of the journey: https://caesarsamsi.wordpress.com/2017/01/03/raspberry-pi-2b-raid-5-build-part-4/