OpenWrt OverlayFS - Part 2

After much experimenting with overlayfs in OpenWrt I've finally settled on a solution that works well. I have decided to call this project 'ovpkg' as in 'overlay package'. You can still use my old instructions if you have an ext2 partition on your card, but if you want to use a completely fat formatted card you can try out this new set of scripts.

You'll need to make sure you have the following packages installed: losetup, fdisk, e2fsprogs

There seems to be a problem with the e2fsprogs package hosted at the chainxor.org repo that prevents these scripts from working. Install my e2fsprogs package instead of using the one from the repo (opkg install /path/to/downloaded/e2fsprogs_1.41.12-2_pxa.ipk).

The first script, mkoverlay, is used to create an ext2 disk image file for use with overlayfs. It uses dd to create the image file, partitions it with fdisk, and formats it with mke2fs. The first argument to mkoverlay is the disk image size and the second is the full path and filename where the disk image will reside on your card. To create a 128Mb image file, first make sure your card is mounted (probably to /mnt/mmcblk0p1) then run: mkoverlay 128 /mnt/mmcblk0p1/myimagefilename.img

When the script is finished you will have a fresh disk image to install software to. The mkoverlay script creates /etc/ovpkg.conf with the path and filename of your image. If you use the example above it would look like this: SD_ROOTFS=/mnt/mmcblk0p1/myimagefilename.img

There also needs to be some changes to the opkg config file. This will tell opkg to install packages in our overlayfs/image file. Add the following to /etc/opkg.conf:
dest card /overlay

Now we are ready to mount the image file with the ovmount script. This script doesn't need any arguments, just type 'ovmount' and it does all the work. First it creates the image file loop device, t hen mounts the loop device to /overlay, then mounts the dirs in /overlay on top of the root dirs as overlayfs. You can also unmount the overlay with the uovmount script.

With the overlay mounted you can proceed using the ovpkg script. Use ovpkg in the same way you would use opkg except do not use the -d or —dest option. ovpkg sets the destination automatically to the card/image file. So, if you want to install supertux to the card you would run: ovpkg install supertux

This will install the software to /overlay (the image file) and remount the image so that all symbolic links show properly. If you want to install something to the jffs2 partition you can still use opkg as normal.

To have OpenWrt automatically mount the overlay at boot or when the card is inserted you can replace a hotplug script with my modified version. The file /etc/hotplug.d/block/40-mount mounts all sd cards when inserted and my modified version will mount the overlay if it exists on the card. Be aware that at boot it does take a while for the card to be mounted. Your programs may not be available immediately at boot.

I have also created an eject script that will unmount the overlays, remove the loop device and unmount the card. You should use this if you want to remove the card from the Zipit while booted. It's quicker than running uovmount and then unmounting the card manually.

Here’s a breakdown of the scripts and where they belong (all but ovpkg.conf and opkg.conf should be made executable with chmod +x):

0 comments

CAPTCHA Image

Play CAPTCHA Audio
Refresh Image

Archives By Month

Tags