User Tools

Site Tools


Rootfs on External Storage (extroot)

As TurrisOS is a fork of OpenWrt, most of the principles of OpenWrt are applicable to TurrisOS. Extroot is one of them.

What is extroot?

Almost every router has a small amount of persistent memory. Turris Omnia has 8 GB of storage but developers say that this storage was not designed to be heavily used for read/write. Sometimes it can be an issue, for example if it is needed to:

  1. Have permanent /var directory instead of symbolic link to /tmp
  2. Install more than 8 GB of software but don't want to alter opkg target installation pathes
  3. Use software that requires a lot of read/write operations to the root filesystem but don't want to damage the internal memory.

There are several workarounds which involve creating symbolic links from the router's internal filesystem to the one which is mounted from USB device. But there is a choice which might be more convenient and reliable in some cases: extroot.

In OpenWrt there is a possibility to replace the root filesystem which is located in the internal memory with the one from external device during the boot. Original instructions for OpenWrt to achieve that can be found here.

How to do extroot on Turris Omnia

If you fail, there is a possibility to soft-brick your device, so please do the backups! If you failed and router doesn't boot, please follow these instructions.

  1. USB device is needed, make sure it is working. If it is a hard drive, check that is has enough power from USB port to work and check its cable.
  2. At least one partition on the USB device must be empty. One of the partitions will be used for extroot and will be mounted as / (root). Others can be used for any custom mounts including swapping.
  3. Extroot only supports Ext4, so if you have a partition of other type, use mkfs.ext4 to re-format the partition.
  4. Please stop all non-core activities like torrent client, DLNA server, Samba server etc.
  5. Clone the internal filesystem to the external device. For example, if the device appeared as sda1:
    mkdir -p /tmp/introot
    mkdir -p /tmp/extroot
    mount --bind / /tmp/introot
    mount /dev/sda1 /tmp/extroot
    tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
    umount /tmp/introot
    umount /tmp/extroot
  6. In LuCI, navigate to System → Mount Points → Add.
    1. Check Enable this mount.
    2. Choose your external USB device from UUID combo box.
    3. Choose Use as root filesystem (/) from Mount point combo box.
    4. Hit SAVE & APPLY
  7. Now configuration should look similar to this:
    # cat /etc/config/fstab
    
    config global
            option anon_swap '0'
            option anon_mount '0'
            option auto_swap '1'
            option auto_mount '1'
            option delay_root '5'
            option check_fs '0'
    
    config mount
            option uuid '1f0e8e00-b854-49d2-97ee-4b57bdaccb1d'
            option target '/'
            option enabled '1'
  8. Copy /etc/config/fstab to the external filesystem:
    mount /dev/sda1 /tmp/extroot
    cp /etc/config/fstab /tmp/extroot/etc/config/fstab
    umount /tmp/extroot
  9. Cross the fingers and reboot.
  10. After reboot, mounts should look like that:
    # mount
    /dev/mmcblk0p1 on /rom type btrfs (ro,noatime,ssd,space_cache,commit=X,subvolid=ABC,subvol=/@)
    ...
    /dev/sda1 on / type ext4 (rw,relatime,data=ordered)
    ...
  11. From now all your data would be stored on the external drive. You can find the internal root filesystem mounted to /rom.

Notes

  1. I'd recommend to keep essential files like the contents of /etc/config in sync between extroot and internal memory. I cannot say for sure at which exact moment the internal memory is replaced with the external one. It has to be /etc/rc.d/S40fstab, so scripts with level less then 40 have to be loaded from internal memory while the others - from the external storage. Since /rom is obviously is read-only, to copy changed files from the extroot to internal memory, you'd have to remount it for read/write:
    mount /rom -o remount,rw
  2. Please be aware that schnapps most probably will stop to work with extroot or will work with errors. It uses Btrfs snapshot feature to work but Brtfs is not supported by extroot. If you can shed some light on that, please update this article.
  3. You can now make /var permanent (reboot required):
    cp -r /tmp /var-tmp
    rm /var
    mv /var-tmp /var