# Setup and Install Docker Netclient on OpenWRT

### Prerequisite: Expand Storage

Installing large packages on OpenWRT can be challenging due to the limited storage space typically available on many routers. While there are several methods to address this limitation, this guide will focus on expanding the root filesystem using an external storage volume, such as a USB device or disk.

This demonstration uses OpenWRT hosted in a cloud infrastructure, but the instructions should also apply to physical routers running OpenWRT. The following steps assume you already have shell access to your OpenWRT device. For more detailed information, please refer to the official OpenWRT extroot documentation: <https://openwrt.org/docs/guide-user/additional-software/extroot\\_configuration>

{% stepper %}
{% step %}

### Install Required Packages

First, update the package lists and install the necessary packages:

```sh
opkg update
opkg install block-mount kmod-fs-ext4 e2fsprogs parted kmod-usb-storage
```

{% endstep %}

{% step %}

### Attach and Identify the Volume

Identify the connected storage device:

```sh
ls -l /sys/block
```

{% endstep %}

{% step %}

### Partition and Format the Disk

Partition and format the disk with ext4:

```sh
DISK="/dev/sda"
parted -s ${DISK} -- mklabel gpt mkpart extroot 2048s -2048s
DEVICE="${DISK}1"
mkfs.ext4 -L extroot ${DEVICE}
```

{% endstep %}

{% step %}

### Configure the Extroot Mount Entry

Create the extroot mount entry:

```sh
eval $(block info ${DEVICE} | grep -o -e 'UUID="\S*"')
eval $(block info | grep -o -e 'MOUNT="\S*/overlay"')
uci -q delete fstab.extroot
uci set fstab.extroot="mount"
uci set fstab.extroot.uuid="${UUID}"
uci set fstab.extroot.target="${MOUNT}"
uci commit fstab
```

{% endstep %}

{% step %}

### Configure a Mount Entry for the Original Overlay

Create a mount entry for the original overlay:

```sh
ORIG="$(block info | sed -n -e '/MOUNT="\S*\/overlay"/s/:\s.*$//p')"
uci -q delete fstab.rwm
uci set fstab.rwm="mount"
uci set fstab.rwm.device="${ORIG}"
uci set fstab.rwm.target="/rwm"
uci commit fstab
```

{% endstep %}

{% step %}

### Transfer the Current Overlay to the External Drive

Copy the contents of the current overlay to the external drive:

```sh
mount ${DEVICE} /mnt
tar -C ${MOUNT} -cvf - . | tar -C /mnt -xf -
```

{% endstep %}

{% step %}

### Reboot the Device to Apply Changes

Reboot your device:

```sh
reboot
```

{% endstep %}

{% step %}

### Modify /etc/config/fstab

Update the /etc/config/fstab configuration:

```
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 target '/overlay'
    option device '/dev/sda1'
    option fstype 'ext4'
    option options 'rw,sync'
    option enabled '1'
    option enabled_fsck '0'
```

This configuration sets up your external drive as the primary storage for installing packages.
{% endstep %}

{% step %}

### Reboot Your Router

Reboot the router to finalize the changes:

```sh
reboot
```

{% endstep %}
{% endstepper %}

### Install Docker

Refer to the OpenWRT Docker guide for more details: <https://openwrt.org/docs/guide-user/virtualization/docker\\_host>

Generally, you may need to run containers as specific users, requiring the creation of new users, groups, and setting up the appropriate folder permissions. However, for simplicity in this demo, we’ll use the root user.

Install Docker:

```sh
opkg install dockerd docker
```

### Install WireGuard

The safest way to install WireGuard on OpenWRT is via the Web GUI.

{% stepper %}
{% step %}

### Update package lists via Web GUI

Navigate to System -> Software and click the Update lists… button.
{% endstep %}

{% step %}

### Search and install WireGuard

Search for WireGuard and install wireguard-tools and luci-proto-wireguard (for Web GUI integration).
{% endstep %}

{% step %}

### Reboot

Reboot the router after installation.
{% endstep %}
{% endstepper %}

### Join Netmaker Network Via Docker

In the Netmaker UI, add a device by selecting Docker. Copy the docker run command (omitting sudo) and run it on your OpenWRT device.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.netmaker.io/help-articles/setup-and-install-docker-netclient-on-openwrt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
