Installing BackupPC on OpenWRT
I wanted to have a backup server for my church that would automatically take backups when computers came on to our new wireless network. BackupPC immediately sprang to mind, but it only runs on Linux. How could I get a Linux server into the church in a very low cost way? Answer: An Asus wireless router running OpenWRT.
Installing OpenWRT is not for beginners. What follows is not a step-by-step guide to every keystroke, but rather an overview that gets you past the particular hurdles of getting OpenWRT installed on the router, getting it to boot off the hard drive, and installing BackupPC and its dependencies. Please know what you’re doing before you get started.
I bought:
- Asus WL-500gP wireless router. It has two USB 2.0 ports in addition to easy JTAG access if I ever get in trouble.
- An external Hitachi 640G USB2.0 hard drive.
Together, the two parts set me back about $160. I decided to install OpenWRT, a distribution of Linux designed for wireless routers, and BackupPC, software that automates the backups.
- Install OpenWRT as normal. I recommend installing the latest generic
openwrt-brcm-2.4-squashfs.trxfirmware. For me, that was Kamikaze 8.09.1. It was necessary to usetftpto install the firmware. - Configure the router to pivot_root to the USB hard drive on boot. Follow the “How do I boot from the USB device (prep)” and “Boot Configuration (Kamikaze)” guides on this wiki page. You don’t need to do anything related to hotplug. The page is outdated when it comes to adding the script to
/etc/init.d/rcS, just modify your existing file to include the first three lines of the code on the wiki.- My
/etc/init.d/pivotroot:- #!/bin/sh
- # change this to your boot partition
- boot_dev="/dev/scsi/host0/bus0/target0/lun0/part1"
- # install needed modules for usb and the ext3 filesystem
- # **NOTE** for usb2.0 replace "uhci" with "ehci-hcd"
- # **NOTE** for ohci chipsets replace "uhci" with "usb-ohci"
- for module in usbcore ehci-hcd scsi_mod sd_mod usb-storage jbd ext2 ext3 ; do {
- insmod $module
- }; done
- # this may need to be higher if your disk is slow to initialize
- sleep 4s
- # mount the usb stick
- mount "$boot_dev" /mnt
- # if everything looks ok, do the pivot root
- [ -x /mnt/sbin/init ] && {
- mount -o move /proc /mnt/proc && \
- pivot_root /mnt /mnt/mnt && {
- mount -o move /mnt/dev /dev
- mount -o move /mnt/tmp /tmp
- mount -o move /mnt/jffs /jffs 2>&-
- mount -o move /mnt/sys /sys 2>&-
- }
- }
- My
/etc/init.d/rcS:- #!/bin/sh
- # Copyright (C) 2006 OpenWrt.org
- if test $2 == "boot" ; then
- /etc/init.d/pivotroot
- fi
- run_scripts() {
- for i in /etc/rc.d/$1*; do
- [ -x $i ] && $i $2 2>&1
- done | $LOGGER
- }
- LOGGER="cat"
- [ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
- if [ "$1" = "S" ]; then
- run_scripts "$1" "$2" &
- else
- run_scripts "$1" "$2"
- fi
- My
- Set up a swap file. You’re going to need the extra memory, especially when doing large batches with rsync. The basic shape of this is below for a 256M swap file. You might want to use the LuCI interface to make this permanent (or edit
/etc/config/fstab).- opkg install swap-utils
- dd if=/dev/zero of=/swap.file bs=1024 count=262144
- mkswap /swap.file
- swapon /swap.file
- Tweak
opkgto not install to flash anymore. Comment outoption overlay_root /jffsfrom/etc/opkg.conf. Otherwise you’ll have several hundred gigabytes of free space, butopkgwill still refuse to use it. - Install BackupPC dependencies from packages. You’re going to need a whole heap of samba and Perl.
- opkg update
- opkg install perl samba-client samba-server
- # Helpful symlink for perl
- ln -s /usr/bin/perl /bin/perl
- # Install all perlbase packages
- opkg list | grep -o -E perlbase-\\w+ | xargs opkg install
- Download and unzip BackupPC
- Install (yet more) BackupPC dependencies manually. Both CPAN and CPANPLUS are irretrievably broken on this platform, so run
BackupPC-3.1.0/configure.pland install what isn’t there by extracting the contents of/libof whatever CPAN module you’re installing to/usr/lib/perl5/5.10.- If it asks you repeatedly to install
Pod::Usageand you have already, type this in the shell:perl -MPod::Usageand figure out what’s still missing when it dies.
- If it asks you repeatedly to install
- Install BackupPC. Finally
configure.plwill start asking you questions and let you install. Go for it. You probably want to have it run as the root user. - Configure BackupPC to start on boot. The initializing scripts provided in
BackupPC-3.1.0/init.daren’t bad, and the one for Slackware is the best. Here’s what landed in my/etc/init.d/backuppc(Modified from the Slackware script). After copying this to your router, run/etc/init.d/backuppc enableto get the service to start automatically.- #!/bin/sh /etc/rc.common
- # Startup init script for BackupPC for OpenWrt
- START=95
- STOP=10
- start() {
- /usr/local/BackupPC/bin/BackupPC -d
- }
- stop() {
- /usr/bin/pkill -f "/usr/local/BackupPC/bin/BackupPC -d"
- }
- restart() {
- stop
- start
- }
- reload() {
- /usr/bin/pkill -f -HUP "/usr/local/BackupPC/bin/BackupPC -d"
- }
- Set up BackupPC admin interface. Here are some general steps to shoehorn it onto the router:
- Copy
BackupPC-3.1.0/cgi-bin/BackupPC_Adminto/www/cgi-bin - Edit
/etc/BackupPC/config.plto set$Conf{CgiAdminUsers}='*';This option does eliminate password requirements on BackupPC, which is appropriate for my purposes. If it’s not for yours, configure Busybox’shttpdto set$REMOTE_USER. - Copy .css and .js from
BackupPC-3.1.0/confand .png and .gif files fromBackupPC-3.1.0/imagesto/www. - Drop a link to the BackupPC admin interface in
/www/index.html, and get rid of the meta refresh in the head of that file.
- Copy
- Configure BackupPC. This is up to you. BackupPC is a complex package that needs to be customized to your particular installation. Go wild!
You might also enjoy:


