Raspberry Pi NAS for Travelers


20140422_183301

Say you have some type of home NAS or drive array which houses valuable information. And let’s say you want to go traveling for a while (as I plan to do), but leave the box in storage. What’s the best way to bring your data with you, or just a bunch of free space for projects?

For most, ditching the drive in your laptop for something which has more capacity is good enough. But what if you wanted to maintain some level of redundancy for your data?

In my case, I was coming from a 3 x 1TB drive configuration in RAID 5 with battery backed write cache (Dell PERC 5/i), running Openfiler with NFS and SMB.

The answer, of course, is Raspberry Pi.

Obviously the trade off is a drastic decrease in speed, but more than worth the effort to put this little setup together. Also, due to the CPU overhead and complexity, I didn’t want to bother with software RAID and decided instead to use lsyncd.

The kit includes:

1 x Raspberry Pi
1 x Adafruit Pi case
2 x Seagate Slim Traveler 2TB USB drive
1 x Pluggable 4 port USB hub
1 x PowerGen 2.4-Amp USB wall charger

Raspberry Pi alone doesn’t supply enough power for both drives, or even one for that matter. The powered USB hub is necessary for reliable operation of both drives.

Before we begin, we’ll need to install a few packages.

root@raspberrypi:/# apt-get install sysstat ntfs-3g lsyncd bc

Then make sure lsyncd starts on boot:

root@raspberrypi:/# update-rc.d lsyncd defaults

When working with a large directory structure as I was, upping the number of inotify watches was necessary to keep the lsyncd service from stopping unexpectedly.

root@raspberrypi:/# echo "fs.inotify.max_user_watches = 65535" >> /etc/sysctl.conf
root@raspberrypi:/# sysctl -p

Now comes the tricky part. When working with USB drives on Raspberry Pi, the first drive you plug in will always become sda, the second sdb, and so forth. We’ll need to mount each drive by ID, as opposed to sdX so that no matter the order they’re plugged in, each drive will always have the same mount point. I created a /media directory with directories usb001 & usb002. These will serve as mount points for each drive. I found the ID by plugging in one drive, then listing out /dev/disk/by-id. (It’s worth noting that I had already connected each drive to a Windows machine and formatted with NTFS.) Once you have the ID, you can assign the block device to a mount point in /etc/fstab. Then do the same for the second drive.

/etc/fstab:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/disk/by-id/scsi-SSeagate_Backup+_BK_NA763W70-part1 /media/usb001   ntfs-3g defaults 0       0
/dev/disk/by-id/scsi-SSeagate_Backup+_BK_NA763W8P-part1 /media/usb002   ntfs-3g ro 0    0

In my case, usb002 had all of my data and I didn’t want to risk accidentally syncing it with the empty drive; note the read-only (ro) flag in the options column. Once everything finishes, I’ll remove the flag and specify ‘defaults’ like usb001.

To mount both drives:

root@raspberrypi:/# mount /media/usb001 && mount /media/usb002

/etc/lsyncd.conf:

settings = {
     logfile = "/var/log/lsyncd.log",
     statusfile = "/tmp/lsyncd.status"
}

sync {
     default.rsync,
     delay = 0,
     source = "/media/usb002",
     target = "/media/usb001",
     rsync = {
          archive = true,
          compress = false
     }
}

Start lsyncd:

root@raspberrypi:/# service lsyncd start

Monitor disk utilization:

root@raspberrypi:/# watch -n 1 'iostat -d -x'

Monitor disk space:

root@raspberrypi:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.2G  2.5G  4.4G  36% /
/dev/root       7.2G  2.5G  4.4G  36% /
devtmpfs        211M     0  211M   0% /dev
tmpfs            44M  760K   44M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  34% /boot
/dev/sda1       1.9T  1.2T  663G  65% /media/usb002
/dev/sdb1       1.9T  168G  1.7T  10% /media/usb001

Here’s a little bash script that spits out a percentage. You may need to modify per your own configuration.

/root/lsyncd-monitor.sh:

#!/bin/bash
sda=`df -h | grep sda | awk '{print $5}' | sed 's/%//g'`
sdb=`df -h | grep sdb | awk '{print $5}' | sed 's/%//g'`
pct=$(echo "scale=1; $sda * 100 / $sdb" | bc)
echo "lsyncd: $pct% complete"

Make it executable and then watch the process:

root@raspberrypi:/# chmod a+x lsyncd-monitor.sh
root@raspberrypi:/# watch -n 1 './lsyncd-monitor.sh'

Once the drives sync up and everything looks good, remove the ‘ro’ attribute in /etc/fstab if you set it previously, and use the source drive as your primary Samba share.

Lsyncd will automatically sync additional files, deletes, etc. with the second drive. If you experience any difficulty with Raspberry Pi, lsyncd, or drive complications, simply disconnect and plug directly into another machine.

 

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Chiang Mai, Thailand.

Bullet-proof Apache: Nikto Security Scanner

apache

If you’ve ever been responsible for maintaining an Apache web server, you know how important security is.

Nikto provides an easy way to scan for known (and unknown) vulnerabilities within your Apache server.  Actually, it does a fairly comprehensive scan on over 200 web servers, not just Apache.  To run a security scan, download the tool, then extract the archive to the desired location.  To initiate a scan from the Nikto directory, type:

[code]

./nikto.pl -host [ip address]

[/code]

Note: when specifying an IP address, make sure you use the external IP of your webserver, not the internal IP.

Here is what my results look like:

[code]
– Nikto v2.03/2.04
—————————————————————————
+ Target IP:          10.0.0.1
+ Target Hostname:    blurred for security
+ Target Port:        80
+ Start Time:         2009-01-26 16:44:36
—————————————————————————
+ Server: Apache
+ OSVDB-3092: GET /manual/ : Web server manual found.
+ OSVDB-3268: GET /manual/images/ : Directory indexing is enabled: /manual/images
+ OSVDB-3233: GET /icons/README : Apache default file found.
+ 3577 items checked: 3 item(s) reported on remote host
+ End Time:        2009-01-26 16:45:25 (49 seconds)
—————————————————————————
+ 1 host(s) tested

Test Options: -host 10.0.0.1
—————————————————————————
[/code]

I would then look up the results and fix each issue until there have been no issues detected.  See the OSVDB-ID?  These IDs are found in the Open Source Vulnerability Database.  Each ID will contain a description, classification, and solution.

To aid in your research, I have created an OSVDB Firefox search plugin.  Install the plugin and then search for 3092, 3268, 3233, etc.

Hopefully this makes securing your web server quick & painless.

 

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Chiang Mai, Thailand.

Find Linux CPU Temperature

The easiest way to get a CPU temperature readout from Linux is by looking at an ACPI function called temperature:
[code]
cat /proc/acpi/thermal_zone/THRM/temperature
[/code]

You could also try sensors-detect and then sensors, but I had some trouble detecting the correct modules on 8 year old hardware.

 

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Chiang Mai, Thailand.

Install Microsoft TrueType Fonts in Fedora and Ubuntu

When it comes to typography, Microsoft TrueType fonts are both visually appealing and aesthetically pleasing. They’re found all over the web, usually specified in stylesheets. Unfortunately for Linux users, the most common TTFs aren’t installed (by default, that is). Instead, they are replaced by generic equivalents. With these font packages installed, you will see websites as the designer intended.

The Microsoft TrueType fonts package includes:

  • Andale Mono
  • Arial Black
  • Arial (Bold, Italic, Bold Italic)
  • Comic Sans MS (Bold)
  • Courier New (Bold, Italic, Bold Italic)
  • Georgia (Bold, Italic, Bold Italic)
  • Impact
  • Times New Roman (Bold, Italic, Bold Italic)
  • Trebuchet (Bold, Italic, Bold Italic)
  • Verdana (Bold, Italic, Bold Italic)
  • Webdings

Installing MS TrueType fonts in Ubuntu

You can install the MS core fonts by installing the msttcorefonts package. You will need to enable the “Universe” component of the repositories (done by default in Feisty & Hardy). After that, run the following from the command line:

[code]
$sudo apt-get install msttcorefonts
[/code]

While this gives you the core fonts, it also gives you the ability to install any other font by simply copying the .TTF to the ~/.fonts/ directory.

When installing new fonts, you’ll need to re-login to be able to see & use them. Optionally, this step can be bypassed by regenerating the fonts cache with:

[code]
$sudo fc-cache -fv
[/code]

Installing MS TrueType fonts in Fedora

Yep, a few extra steps in Fedora, but still a cinch. From the shell:

[code]
cd /tmp
wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec
yum install rpm-build cabextract
rpmbuild -ba msttcorefonts-2.0-1.spec
yum localinstall –nogpgcheck \
/usr/src/redhat/RPMS/noarch/msttcorefonts-2.0-1.noarch.rpm
[/code]

That should do it. Reinitialize the font cache, re-login or reboot and have another look at this site (with Georgia).

 

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Chiang Mai, Thailand.

Upgrade Fedora 8 to Fedora 9 Using PreUpgrade

Fedora 9 was released this past Tuesday. The upgrade process has changed slightly, with the Fedora Project integrating a new tool called PreUpgrade.

To upgrade, make sure your system is fully updated with:

[code]
yum -y update
[/code]

and reboot when the process has completed successfully (in case it installed a new kernel).

From here, we can install the new PreUpgrade with:

[code]
yum install preupgrade
[/code]

When that finishes, kick it off with:

[code]
preupgrade &
[/code]

As we proceed through the wizard, your screens will resemble:

F9 Upgrade 1

Click Forward.

F9 Upgrade 2

The new release will be chosen by default. Click Apply.

F9 Upgrade 3

At this point, new packages are downloaded which may take some time. Grab some coffee while the downloads transfer.

F9 Upgrade 4

Finished! Reboot and we will see a screen like this:

F9 Upgrade 5

The remaining portion of the upgrade will be completed by Anaconda, which took approximately 5 hours on my system. Proceed by clicking Next.

F9 Upgrade 6

“Upgrade an existing installation” is preselected, hit Next to continue.

F9 Upgrade 7

Here you are prompted to upgrade the GRUB boot loader. This is the best thing to do. Click Next. The following series of screens are shown as the upgrade progresses:

F9 Upgrade 8

F9 Upgrade 9

F9 Upgrade 10

F9 Upgrade 11

Ah, here we are. We find ourselves at the final screen, indicating the success of the upgrade. Word. Reboot. And that should conclude the process.

In my opinion, this upgrade was 1000x better than the upgrade from F7 to F8. I ran into all kinds of issues then, but this was better.

Having gone through the steps now, what was your upgrade experience like?

 

About Benjamin Perove

Ben has been associated with a broad spectrum of technologies starting from an early age, and he's contributed to the success of many businesses and enterprises since 2001. Most of his time is spent building cool stuff. When he's not working, he enjoys reading, playing acoustic guitar, and being with friends. He currently resides in Chiang Mai, Thailand.

Next Page »

Add this site to your Firefox Search Bar

Twitter Activity

Recent Entries

Topics

Archives