Until recently, I’ve had a dedicated PC running SUSE Linux serving as network attached storage and a backup server. I really wanted to get rid of the necessity of running another PC 24/7 with all the noise and power consumption. I decided to revisit a solution I had looked at a year or so ago, the Linksys NSLU2.
There are goals I was trying to accomplish:
- Serve as a network attached storage device
- Perform as a backup server for our two laptops
- Backup data on my web host
- Sync all the data to a secondary drive
However, just the stock NSLU2 wouldn’t do, which brought me to OpenWRT. The following is a quick step by step of how I configured it to do what I wanted. This probably isn’t for the novice, but between this and the NSLU2 wiki, you should be able to figure everything out.
My hardware configuration consists of the NSLU2 with two 500GB external hard drives. The primary drive serves as the network share along with the root and swap partitions for the NSLU2. The secondary drive’s only purpose is to backup all the data on the primary. I also have a third 500GB external drive that I periodically swap out with the secondary drive and store it off site.
Here are the steps I went through to configure it:
- Get the OpenWrt Binary
- Enter upgrade mode and flash the device with the Sercomm Update Utility.
- Telnet to 192.168.1.1 and change the root password.
- SSH in and Modify /etc/config/network. Change IP address if you want something different. Add the following:
option dns
option gateway - Reboot and SSH to the new IP Address
- Read up on how to configure to boot from a USB device.
opkg update
opkg install kmod-usb-core kmod-scsi-core kmod-usb-storage kmod-usb2 kmod-fs-ext3
insmod jbd
insmod ext3
insmod ehci-hcd
(ignore errors)
opkg install e2fsprogs fdisk - Reboot, then mount it and copy the filesystem to your USB-device
mount -t ext2 /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind /rom /tmp/root
cp /tmp/root/* /mnt -a
umount /tmp/root
umount /mnt - Add the following to /etc/init.d/pivotroot
#!/bin/sh
# change this to your boot device
boot_dev=”/dev/sda1″
/sbin/hotplug2 –override –persistent –max-children 1 –no-coldplug &
for module in usbcore ehci scsi_mod sd_mod usb-storage jbd ext3 ; do {
insmod $module
}; done# this may need to be higher if your disk is slow to initialize
sleep 30s
# mount the usb stick
mount “$boot_dev” /mnt
# if everything looks ok, do the pivot root
killall hotplug2
[ -x /mnt/sbin/init ] &} - Make it executable
chmod a+x /etc/init.d/pivotroot
- Make the symlink so it will start at boot time then reboot
ln -s /etc/init.d/pivotroot /etc/rc.d/S10pivotroot
- At this point you may have to telnet back in and set the root password again, then come back in via SSH
- Setup resolv.conf
rm /etc/resolv.conf
ln -s /tmp/resolv.conf.auto /etc/resolv.conf - Install packages needed for swapspace and set it up
opkg update
opkg install swap-utils
mkswap /dev/sda2
swapon /dev/sda2
echo “#!/bin/sh” >> /etc/init.d/swapspace
echo “swapon /dev/sda2” >> /etc/init.d/swapspace
chmod a+x /etc/init.d/swapspace
ln -s /etc/init.d/swapspace /etc/rc.d/S99swapspace -
Install a better editor (sorry, I really prefer nano over vi, and out of habit, I still call it pico)
opkg install nano
ln -s /usr/bin/nano /usr/bin/pico - Install some other useful packages
opkg install ntpclient rsync fdisk bash ntpclient
- NOTE: from this point forward you may need to mirror any changes to /etc in /mnt/etc. It’s best to keep them the same anyhow.
- You’ll probably want to move/delete the following file. It messes up the mount points for the drive.
/etc/hotplug.d/usb/10-usb-storage
It’s much better to just set up where you want the drives mounted in /etc/mtab.
- The following must be done in order for Samba to start properly
edit /etc/config/system with the hostname you want, if different than the default. I use ‘nas’add following to /etc/config/luci_hosts
config ‘host’
option ‘ipaddr’ <ip of device>
option ‘hostname’ ‘<hostname>’ - Get the samba server going (don’t use Samba 3)
opkg install samba-server samba-client
configure /etc/samba/smb.conf
smbpasswd -add <name> <password>
/etc/init.d/samba restartBe sure to rename your samba startup script in /etc/rc.d so it starts after /etc/rc.d/S??luci_hosts runs
- For Samba 2, if you’re connecting with a Visa client, you may need to make this registry change:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA\
Change the key LmCompatibilityLevel from “3” to “1”. - At this point in the game, I discovered how to over clock the slug. Apparently it really isn’t over clocking. The processor was designed to run at 266MHz, but Linksys chose to underclock it at 133MHz. I performed the hack successfully. It’s been working fine ever since.
- Setup timezone for NTP (more info here)
echo GMT+6 > /etc/TZ
(adjust for your time zone. The above is US Central (DST), even though you may think the ‘+’ should be a ‘-‘)
Make the same change in /etc/config/system - Create the startup script for rsync daemon
#!/bin/sh /etc/init.d/rsync
# Copyright (C) 2006 OpenWrt.org
START=50start () {
/usr/bin/rsync –daemon
}stop() {
killall -9 rsync
} -
Create a crontab for the daily backup to run and time sync.
/etc/crontabs/root
0 2 * * * /root/daily_backup &
0 1 * * * /root/time_sync &The time_sync file looks like this:
#!/bin/bash
# kill any existing ntpclient processes
# (they can get stuck if no route to target host)
/usr/bin/killall ntpclient# do time sync
/usr/sbin/ntpclient -l -h north-america.pool.ntp.org -c 1 -s &I’ll probably leave the daily_backup file for a future post. Basically what it does is retrieve files from my webhost, then syncs all the data from the primary drive to the secondary.
- Configure /etc/rsyncd.conf to allow remote backups. I also added another user to the system with uid=1/gid=1 and I run rsync as that user. I also have Samba configured to give all the file permissions to that user as well instead of root.
- Download, install and configure DeltaCopy client on the machines you want to back up.
Yeah, so this all seems a bit overkill perhaps. However, this little embedded device is replacing an entire PC for me and really, it’s probably no more complicated than setting up any other Linux machine to perform the same task. Plus, if there is something else I dream up later on that I want it to do, I’m not limited by a simple dedicated backup device.
This is exactly what I did with my “SLUG”. Since I had so many PC’s and Laptops both Linux and Windows, I also used it as a DHCP and DNS with preconfigured IP’s for all the machines. This works incredibly well.
I had 2 issues.
1. The hardware serial port (that I manually added) for whatever reason caused a problem during bootup.
2. The performance for large transfers over SSH was not very efficient. Samba was much better, but at times left a lot to be desired.
I’ve since stopped using it for major file transfers, but the NTP, DNS and DHCP works incredibly well.
I’ve a setup like your but I’m getting troubles with Samba, don’t know why but the same config I’ve previously used for another Debian machine doesn’t work with the Slug. I’ve OpenWRT like you but it seems I’m getting errors when I try to use “valid users” directive, everything works fine in guest mode. Obviously I’ve inserted users in /etc/passwd and even used “smbpasswd user password” command to add the user (not smbpasswd –add user passwd ?).
Can you please post your smb.conf so I can see the differences and see a working one.
Thank you in advance
Cheers
Ben
Here’s a copy of my smb.conf for the NSLU2:
http://www.yorkspace.com/wp-content/nslu2-smb.conf.txt
Thanks a lot Man 🙂
Thanks for good guide. I just have one question. Why in /etc/init.d/pivotroot you load uhci module and on the other place you use ehci. Is it intentional? If I’m not mistaken uhci is USB1 and ehci is USB2 so isn’t it better to use ehci on both places?
@egalitarian
That was an oversight. I’ve now corrected it. Thanks!
Anybody know how to install and mount a usb cdrom drive on an nslu2 running openWrt? Here’s what I get in dmesg:
scsi 0:0:0:0: CD-ROM HL-DT-ST RW/DVD GCC-4481B E106 PQ: 0 ANSI: 0
but I never get an “Attached” message. Any ideas?