Poor man’s NAS

Gentoo November 14th, 2008

A Network Attached Storage(NAS) has been in my wanted list for quite a long time, thanks to Live Search Cashback program to make it happen: a Western Digital MyBook World Edition(500GB). More information about the hardware specification:

  • ARM926EJ-Sid(wb) [41069265] revision 5 (ARMv5TEJ) 99.73 MHz
  • Memory: 32M
  • VIA Networking Velocity Family Gigabit Ethernet
  • WD5000AAVS-0 500G HD

I believe 100MHz ARM CPU is powerful enough to drive this tiny box, but the limited capacity of memory cripples it as a lame duck. The sustainable file write(85G using lftp mirror) rate is approximately 3.8MB/s. It hardly qualifies any service beyond file server. Now, it is time to hack.

Jailbreak and SSH

The first thing to do is to create a user in the web interface of MyBook as root with null password is banned for security reason. Log on with admin and 123456, create a user JOE and setup the password for later use.

Run the script discussed in the wiki, and ssh with JOE. Now you can su to root with blank password, 0wned!

User management

MyBook takes a very intricate way to manage users:

All Samba users are granted shell access, but unix password sync = yes is not set, the /etc/shadow and /var/private/smbpasswd are updated individually by a Perl script via the web interface. The only reasonable explanation is the minimized Samba lacks PAM support.

All user names are capitalized. I assume this is a brutal force approach to address the difference between Samba and Linux native accounts: Windows user name is case insensitive, while Linux is case-sensitive.

As the password scrambled in /etc/shadow, it is easier to add/delete/update users via the web interface, then fine-tune the corresponding files. The user administration executives are hidden in /usr/www/nbin.

Share with Samba

The default exported directory is /share/internal/PUBLIC, the permission of the directory is set as rwsr-sr-x, and the owner is www-data, YMMV. So any file/directory created will be owned by www-data. If you are unhappy with the name, you may add a user, e.g joe as discussed before, then add joe to www-data group:

# /etc/group, YMMV
www-data:x:33:share

remember to change the default mask in /etc/smb.conf:

create mask = 0775
directory mask = 0775

Package management

Though I am a big fan of Gentoo, it is a little bit paranoid to build everything from scratch. A precompiled package management, like Optware makes more sense. Check out this tutorial for bootstrapping.

The essential packages for daily administration imho are screen, lftp.

Feature requests

There are some itchy miss features, if you happen to know a solution or hint, please drop me a message in the comment:

Access Anywhere No mionet, just SSH. If you are a perfectionist, consider to port this Delphi application to MyBook to host MyBook in your preferred domain.

Download Manager A web front-end to listen to download requests from Firefox/IE plugins, then delegate it to wget backend with cookie support. A more aggressive approach may support megaupload happy hour.

HOWTO extend the life of Gentoo laptop

Gentoo August 5th, 2007

*cough*, I may not qualify this discussion considering my bad record (1, 2), and I just replace the hard disk for the consequent I/O failure today. Anyway, the readers may learn some lesson from my good/bad practice and avoid the same pitfall.

Gentoo enjoys the reputation for its source-based distribution and highly-customizable package management, portage. However, we pay the price for the flexibility: synchronizing the portage, building applications from source code. Both of the two tasks are I/O extensive, and the latter is also computation-extensive. The following tips aim to offload the burden to the desktop workhorses and eliminate the unnecessary I/O operation as much as possible.

Choose the right file system

I am a big fan of JFS regarding its comparable performance with low CPU consumption. Unfortunately, JFS does not support bad block relocation. This is essential since we may still use the hard disk with some dysfunctional sectors, though not suggested. So I decide to take reiserfs as the default FS with LVM.
Pro: I could tell the difference of booting time.
Con: when emerging the package, especially boost, the whole system just lost the responsiveness due to the high I/O traffic.
It is really a tough decision. I may go back to JFS if this hard disk is dead, *touch wood*.

Using tmpfs

Check this tip in Gentoo Wiki. The temerge works as a charm. It builds the application in memory instead of hard disk, the emerge time is shortened dramatically and the hard disk access is decreased.

Share the portage over network

Another I/O extensive operation is emerge –sync. According to this HOWTO, a shared portage not only save the hard disk access, but network bandwidth of the sync servers as well. The file server used in my home network, hippo servers the multimedia files using Samba for one Dell 700m laptop tiger and one Dell Dimension E521 desktop gorilla. Follow this HOWTO to get Samba works, and we may adapt the changes mentioned in this HOWTO to the system:
Add the emerge –sync task to the cron: /etc/cron.daily/emerge.cron

#!/bin/sh
emerge –sync > /dev/null 2>&1

Export the portage to the public: /etc/samba/smb.conf

[portage]
comment = public portage
path = /usr/portage
public = no
writable = yes
browseable = yes
valid users = share admin

Auto mount the portage in tiger: /etc/fstab

//hippo/portage /usr/portage cifs user=share,password=foo,iocharset=utf8

If the laptop is roaming, local /usr/portage would be used. The distfiles and packages are left in the local disk just in case we may need them without network: /etc/make.conf

FEATURES=”sandbox ccache -distlocks autoaddcvs confcache”
PORTDIR=/usr/portage
DISTDIR=/usr/local/portage/distfiles
PKGDIR=/usr/local/portage/packages
PORTDIR_OVERLAY=”/usr/local/portage/myportage”
source /usr/local/portage/layman/make.conf

For eix users: /etc/eixrc

PORTDIR_CACHE_METHOD=’none’

and put the update-eix into cron.daily

For layman users: /etc/layman/layman.cfg

storage : /usr/local/portage/layman

Offload the build to desktop workhorse

TO BE CONTINUED…