Tuesday 19 June 2007

Installing rsync to automate backups onto the NSLU2 Fileserver

Install rsync on the Fileserver -

apt-get install rsync

edit /etc/rsyncd.conf

# rsyncd.conf
uid = share
gid = share
use chroot = yes
max connections = 2
syslog facility = local3
pid file = /var/run/rsyncd.pid
[GiddyKipper]
path = /home/share/backups/GiddyKipper
comment = nslu2 rsync backup of GiddyKipper
read only = no
[SillySausage]
path = /home/share/backups/SillySausage
comment = nslu2 rsync backup of SillySausage
read only = no

Started rsync in daemon mode -

rsync --daemon

Should now be able to see the rsysnc server from another machine on the LAN -

andrew@giddykipper:~$ sudo rsync fileserver::
GiddyKipper nslu2 rsync backup of GiddyKipper
SillySausage nslu2 rsync backup of SillySausage
andrew@giddykipper:~$

Clients 'push' backups onto the server - i.e. to back-up my Linux 'home' directory on GiddyKipper -

rsync -arv --delete /home/andrew/ fileserver::GiddyKipper/andrew/

In order for this backup to run daily, the following script is added to /etc/cron.daily

#!/bin/sh
#
# backup cron daily
rsync -arv --delete /home/andrew/ fileserver::GiddyKipper/andrew/

For Windows machine, need to install cygwin, and then install rsync within cygwin. Backups are run as -

rsync -arv --delete /cygdrive/c/Documents\ and\ Settings/Rachel/ fileserver::SillySausage/Rachel/

and can include explicit exclude options to avoid lots of junk -

--exclude '*/Temporary\ Internet\ Files/*'

To run regular backups, need to add something like the following script to "Scheduled Tasks" to be run as an Administrator -

c:
cd c:\cygwin\bin
bash --login -c "rsync -avr --log-file=/cygdrive/c/backup.log --delete --exclude '*/Temporary\ Internet\ Files/*' /cygdrive/c/Documents\ and\ Settings/Rachel/ fileserver::SillySausage/Rachel/"

Setting up Samba on the NSLU2 Fileserver

Added an new user 'share' with password 'share'

adduser share

This also automatically creates a directory /home/share. Added new directories in /home/share to store the data to be shared by samba -

cd /home/share/
mkdir music
mkdir pictures

mkdir backups
mkdir videos

mkdir /home/share/backups/GiddyKipper
mkdir /home/share/backups/SillySausage

- and changed the owner of the directories to 'share'

chown share:share /home/share -R

Installed samba

apt-get install samba

edited /etc/samba/smb.conf

# Global parameters
[global]
workgroup = OURHOUSE
netbios name = fileserver

server string = Our Fileserver

security = SHARE

#turn off printing!
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes

[music]
comment = Shared Music Files
path = /home/share/music
force user = share
force group = share
read only = Yes
guest ok = Yes

[pictures]
comment = Shared Pictures
path = /home/share/pictures
force user = share
force group = share
read only = Yes
guest ok = Yes

[videos]
comment = Shared videos
path = /home/share/videos
force user = share
force group = share
read only = Yes
guest ok = Yes

[backups]
comment = Network backups
browseable = No
force user = share
force group = share
read only = Yes
guest ok = Yes

[shares-admin]
comment = Admin access to the shares
browseable = No
user = share
read only = No
guest ok = No

Added a samba user called 'share' with password 'share'

fileserver:~# smbpasswd -a share
New SMB password:
Retype new SMB password:
Added user share.

And checked he was there OK -

fileserver:~# pdbedit -L
share:1001:,,,

Restarted samba to force rereading of the config file (update: actually don't need to do this - config file is re-read every 60 seconds)

/etc/init.d/samba restart

- and then check to see if shares are exported.

The shares 'music', 'pictures' and 'videos' should be visible to everyone - but no writes or deletes allowed:

Noname 

The 'backups' share isn't shown above because it isn't browsable - but it's there readonly for everyone as well if you type the full share name in:

Noname2

Typing in the full path of the 'shares-admin' share brings up a password dialog box and you have to log in as the samba user 'share' as created above before the share is accessable (full read write access):

Noname3

Installing Debian on the NSLU2 Fileserver

My first attmpt to reflash the NSLU2 with Debian Etch using the Debian Installer repeatedly failed while downloading packages from the mirrors (Next time I try it I'll make more detailed notes of what went wrong!) - so instead I used the manual method described here. This uses a tar ball prepared by Martin Michlmayr which just needs to be unpacked into the target filesystem.

Firstly, I partitioned the usb diskdrive. I plugged the drive into my laptop running Ubuntu 7.04 and used fdisk to create the required partitions. In order to match Martin's tar ball, I created /dev/sdb1 for the root partition (size 3000M), /dev/sdb2 as an extended partition from which I created /dev/sdb5 for the swap partition (700M) and /dev/sdb6 for the home partition (the remainder of the disk ~ 36G) are created. I also used fdisk to make /dev/sdb1 bootable and to change the type of /dev/sdb5 to 82 (Linux swap).

(...I had to reboot the laptop and then unmount the automounted usb disk before the next step...)

I then formatted the drive –

mkfs.ext3 /dev/sdb1
mkfs.ext3 /dev/sdb6
mkswap /dev/sdb5

- and mounted it on the laptop -

sudo mount /dev/sdb1 /mnt/tmp

I got the tar ball from -

wget http://people.debian.org/~tbm/nslu2/etch/base.tar.bz

- and unpacked it onto the root partition of the prepared drive -

cd /mnt/tmp
bzcat ~/base.tar.bz2 tar -xvf -

I then had to manually install the proprietary firmware that is needed for the in-built Ethernet chip, following the instructions on the NSLU2-Linux wiki describing how to extract this firmware from an installer image, as follows -

Firstly I downloaded the debian-installer image from slug-firmware.net and unpacked the image using slugimage (the version of slugimage packaged for Ubuntu was too old - I got my version from the Unslung CVS.)

slugimage -u -i di-nslu2.bin

- endian swapped the initramfs (ramdisk.gz).

devio '<< ramdisk.gz; xp $ 4' > ramdisk-swap.gz

- unpacked the initramfs

mkdir initrd; cd initrd
zcat ../ramdisk-swap.gz cpio -i

(there were lots of errors here relating to file permissions - but the firmware seems to have been extracted OK)

The NPE microcode firmware was in the initrd/lib/firmware directory - called NPE-B.01000201. I copied this file to /mnt/tmp/lib/firmware, and then created a symbolic link in /mnt/tmp/lib/firmware called NPE-B which points to NPE-B.01000201.

sudo cp NPE-B.01000201 /mnt/tmp/lib/firmware/
cd /mnt/tmp/lib/firmware; sudo ln -s NPE-B.01000201 NPE-B

The filesystem was now prepared, so I put the NSLU2 in upgrade mode and flashed the etch firmware image using upslug2 (the version packaged with Ubuntu was OK).

sudo upslug2 -i sda1-2.6.18.dfsg.1-12.bin

I connected the hard drive when upslug2 had finished and the NSLU2 rebooted the new Debian system. The system obtained an IP address via DHCP on eth0. I was able connect via SSH with user root and password root.

First thing I did was changed the root password -

passwd root

- regenerated the ssh keys

ssh-keygen -f /etc/ssh/ssh_host_key -N '' -t rsa1

ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa

- edited /etc/network/interfaces to give a static IP address

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.77
netmask 255.255.255.0
gateway 192.168.1.1

- added a normal user andrew

adduser andrew

- changed the host name by changing 'foobar' to 'fileserver' in /etc/hostname and /etc/hosts

I then rebooted to make sure I could still log in (I could as user andrew and as root ...) then edited /etc/apt/sources.list to point to local mirrors as well as the contrib and non-free repositories -

deb http://ftp.uk.debian.org/debian/ etch main contrib non-free
deb-src http://ftp.uk.debian.org/debian/ etch main contrib non-free
deb http://security.debian.org/ etch/updates main contrib non-free
deb-src http://security.debian.org/ etch/updates main contrib non-free

and upgraded -

apt-get update
apt-get dist-upgrade

There was a kernel upgrade required, but no packages required updating.

Next - installing samba ...

Monday 18 June 2007

Introducing Flabbybox

This was the basic idea -

IMAGE0027

The FileServer consists of -

  • Linksys NSLU2 from ebuyer hacked to run Openslug
  • Western Digital 40GB Scorpio 2.5" drive from ebuyer
  • Dynamode USB2.0 Caddy For 2.5" Hard Drives from ebuyer

The Flabbybox itself consists of -

System has been working fine for some time, but I now need to update it -
  • Need to update my wireless network security to WPA, but this is not supported in the version of OpenSlug I'm using
  • I want to move to Debian, on the fileserver at least, in order to have a 'proper' operating system for when I connect it to the internet.
  • I want to try simpler platforms for the client, such as wireless routers running Openwrt and save the NSLU2 for harder jobs.

Aim of this blog is to document the work, so I don't forget how I did it again!

CIMG1807