If you would like to install extra packages on OpenWrt, but you have run out of space on your router’s internal flash memory, then this tutorial is for you. The plan is to copy the OpenWrt’s root filesystem onto an external USB flash drive, and tell the router to switch to that when it boots up. All you need is a standard USB flash drive, a USB capable router running OpenWrt, and about 30 mins.
The OpenWrt wiki pages for this subject are very good. If you’re interested in reading about all the different options, then take a look (for example, it’s possible to mount the USB drive on /opt and install extras here, but some packages expect to be installed in root and won’t behave nicely). In case you’d like to look it up later, the type of extroot that I’m talking about here is external root (aka pivot root), not external overlay (aka pivot-overlay).
This assumes that you have already formatted your external USB drive with a journaling filesystem (like EXT3 or EXT4). If you haven’t, do this first (the partition managers in Ubuntu and Kubuntu do this very easily, do a google search for a tutorial if you’re unsure how to do this). To use pivot root, you must be using a version of OpenWrt that is newer than v12 (so 12.09 Attitude Adjustment is fine, but Backfire is not). First, connect to OpenWrt via ssh or telnet.
Install some packages
First, install the package that will swap your root from the router’s inbuilt flash memory to the external USB flash device:
opkg update opkg install block-mount
Copy your current root filesystem to the USB flash drive
Before you do this, make sure your router is secure (e.g. SSH login isn’t possible from WAN, wifi interfaces are password protected etc). This is important because if something goes wrong when your router boots up then OpenWrt will be unable to boot to the USB flash drive, leaving you with whatever your present setup is until you can make it boot to the USB drive properly. First, install fdisk, a tool to tell you info about attached devices:
opkg update opkg install fdisk
Now, insert your USB drive and run the following command to get some details about it:
root@OpenWrt:~# fdisk -l ... Disk /dev/sda: 4229 MB, 4229496832 bytes 255 heads, 63 sectors/track, 514 cylinders, total 8260736 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00933453 Device Boot Start End Blocks Id System /dev/sda1 63 8257409 4128673+ 83 Linux
You see your USB drive listed under “Device”. Now make a mount point for the drive. You can choose whatever you like instead of sda1, just remember what you chose later!
Mount the drive on the mount point you just created (replace /dev/sda2 with whatever you got from the fdisk command, and /mnt/sda1 with whatever you chose as your mount point):
mount /dev/sda2 /mnt/sda1
Now copy the root filesystem from the router’s inbuilt flash to the USB drive with these commands (if you chose a name other than /mnt/sda1 in the previous step, then replace /mnt/sda1 in line 3):
mkdir -p /tmp/cproot mount --bind / /tmp/cproot tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda1 -xf - umount /tmp/cproot
You now have a USB drive with a copy of your router’s filesystem on it. The next step is to make it automatically mount when you boot up, and use it as root.
Open /etc/config/fstab with your favourite text editor:
If nano is not installed, you can use vi (which is installed by default, but is horrible!) or you can just install nano with:
opkg update opkg install nano
Add the following to the file:
config mount option target / option device /dev/sda1 option fstype ext3 option options rw,sync option enabled 1 option enabled_fsck 0
Reboot and Check
When you reboot, you should now be running OpenWrt from your USB stick. Check your current mounts with this command:
Output should be something similar to the following:
root@OpenWrt:~# mount rootfs on / type rootfs (rw) /dev/root on /rom type squashfs (ro,relatime) proc on /proc type proc (rw,noatime) sysfs on /sys type sysfs (rw,noatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,size=63340k) tmpfs on /dev type tmpfs (rw,noatime,size=512k,mode=755) devpts on /dev/pts type devpts (rw,noatime,mode=600) /dev/sda1 on / type ext4 (rw,sync,relatime,user_xattr,barrier=1,data=ordered) debugfs on /sys/kernel/debug type debugfs (rw,relatime) none on /proc/bus/usb type usbfs (rw,relatime)
See how much space you’ve created for exciting packages with this command:
Which should show you something like this:
root@OpenWrt:~# df -h Filesystem Size Used Available Use% Mounted on rootfs 3.9G 157.1M 3.6G 4% / /dev/root 2.0M 2.0M 0 100% /rom tmpfs 61.9M 932.0K 60.9M 1% /tmp tmpfs 512.0K 0 512.0K 0% /dev /dev/sda1 3.9G 157.1M 3.6G 4% /
You’re all done. Have fun building your personalised OpenWrt cathedral!